(self, url, object_path, query_params, tags=None)
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, query_params, tags=None):
        """
        Query the given URL and return the JSON response
        """
        if object_path:
            url = self._join_url_dir(url, object_path)

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

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

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

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

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

        except JSONDecodeError as e:
            self.service_check(
                self.JMX_SERVICE_CHECK,
                AgentCheck.CRITICAL,
                tags=tags,
                message='JSON Parse failed: {}, {}'.format(url, e),
            )
            raise

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

        else:
            return response_json
def _rest_request_to_json ( self , url , object_path , query_params , tags = None ) : if object_path : url = self . _join_url_dir ( url , object_path ) # Add query_params as arguments if query_params : query = '&' . join ( [ '{}={}' . format ( key , value ) for key , value in iteritems ( query_params ) ] ) url = urljoin ( url , '?' + query ) self . log . debug ( 'Attempting to connect to "%s"' , url ) try : response = self . http . get ( url ) response . raise_for_status ( ) response_json = response . json ( ) except Timeout as e : self . service_check ( self . JMX_SERVICE_CHECK , AgentCheck . CRITICAL , tags = tags , message = "Request timeout: {}, {}" . format ( url , e ) ) raise except ( HTTPError , InvalidURL , ConnectionError ) as e : self . service_check ( self . JMX_SERVICE_CHECK , AgentCheck . CRITICAL , tags = tags , message = "Request failed: {}, {}" . format ( url , e ) ) raise except JSONDecodeError as e : self . service_check ( self . JMX_SERVICE_CHECK , AgentCheck . CRITICAL , tags = tags , message = 'JSON Parse failed: {}, {}' . format ( url , e ) , ) raise except ValueError as e : self . service_check ( self . JMX_SERVICE_CHECK , AgentCheck . CRITICAL , tags = tags , message = str ( e ) ) raise else : return response_json