(self, url, object_path, tags, *args, **kwargs)
Query the given URL and return the JSON response
Query the given URL and return the JSON response
Query the given URL and return the JSON response
def _rest_request_to_json(self, url, object_path, tags, *args, **kwargs):
        """
        Query the given URL and return the JSON response
        """
        service_check_tags = ['url:{}'.format(self._get_url_base(url))] + tags
        service_check_tags = list(set(service_check_tags))

        if object_path:
            url = self._join_url_dir(url, object_path)

        # Add args to the url
        if args:
            for directory in args:
                url = self._join_url_dir(url, directory)

        self.log.debug('Attempting to connect to "%s"', url)

        # Add kwargs as arguments
        if kwargs:
            query = '&'.join(['{}={}'.format(key, value) for key, value in iteritems(kwargs)])
            url = urljoin(url, '?' + query)

        try:
            response = self.http.get(url)
            response.raise_for_status()
            response_json = response.json()

        except Timeout as e:
            self.service_check(
                SERVICE_CHECK_NAME,
                AgentCheck.CRITICAL,
                tags=service_check_tags,
                message="Request timeout: {}, {}".format(url, e),
            )
            raise

        except (HTTPError, InvalidURL, ConnectionError, SSLError) as e:
            self.service_check(
                SERVICE_CHECK_NAME,
                AgentCheck.CRITICAL,
                tags=service_check_tags,
                message="Request failed: {}, {}".format(url, e),
            )
            raise

        except ValueError as e:
            self.service_check(SERVICE_CHECK_NAME, AgentCheck.CRITICAL, tags=service_check_tags, message=str(e))
            raise

        else:
            self.service_check(
                SERVICE_CHECK_NAME,
                AgentCheck.OK,
                tags=service_check_tags,
            )

            return response_json
def _rest_request_to_json ( self , url , object_path , tags , * args , * * kwargs ) : service_check_tags = [ 'url:{}' . format ( self . _get_url_base ( url ) ) ] + tags service_check_tags = list ( set ( service_check_tags ) ) if object_path : url = self . _join_url_dir ( url , object_path ) # Add args to the url if args : for directory in args : url = self . _join_url_dir ( url , directory ) self . log . debug ( 'Attempting to connect to "%s"' , url ) # Add kwargs as arguments if kwargs : query = '&' . join ( [ '{}={}' . format ( key , value ) for key , value in iteritems ( kwargs ) ] ) url = urljoin ( url , '?' + query ) try : response = self . http . get ( url ) response . raise_for_status ( ) response_json = response . json ( ) except Timeout as e : self . service_check ( SERVICE_CHECK_NAME , AgentCheck . CRITICAL , tags = service_check_tags , message = "Request timeout: {}, {}" . format ( url , e ) , ) raise except ( HTTPError , InvalidURL , ConnectionError , SSLError ) as e : self . service_check ( SERVICE_CHECK_NAME , AgentCheck . CRITICAL , tags = service_check_tags , message = "Request failed: {}, {}" . format ( url , e ) , ) raise except ValueError as e : self . service_check ( SERVICE_CHECK_NAME , AgentCheck . CRITICAL , tags = service_check_tags , message = str ( e ) ) raise else : self . service_check ( SERVICE_CHECK_NAME , AgentCheck . OK , tags = service_check_tags , ) return response_json