(self, address, object_path, service_name=None, tags=None, *args, **kwargs)
return response_json
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, address, object_path, service_name=None, tags=None, *args, **kwargs):
        """
        Query the given URL and return the JSON response
        """
        tags = [] if tags is None else tags

        service_check_tags = ['url:{}'.format(self._get_url_base(address))] + tags

        url = address

        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._critical_service(service_name, service_check_tags, "Request timeout: {}, {}".format(url, e))
            raise

        except (HTTPError, InvalidURL, ConnectionError) as e:
            self._critical_service(service_name, service_check_tags, "Request failed: {}, {}".format(url, e))
            raise

        except JSONDecodeError as e:
            self._critical_service(service_name, service_check_tags, "JSON Parse failed: {}, {}".format(url, e))
            raise

        except ValueError as e:
            self._critical_service(service_name, service_check_tags, str(e))
            raise

        return response_json
def _rest_request_to_json ( self , address , object_path , service_name = None , tags = None , * args , * * kwargs ) : tags = [ ] if tags is None else tags service_check_tags = [ 'url:{}' . format ( self . _get_url_base ( address ) ) ] + tags url = address 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 . _critical_service ( service_name , service_check_tags , "Request timeout: {}, {}" . format ( url , e ) ) raise except ( HTTPError , InvalidURL , ConnectionError ) as e : self . _critical_service ( service_name , service_check_tags , "Request failed: {}, {}" . format ( url , e ) ) raise except JSONDecodeError as e : self . _critical_service ( service_name , service_check_tags , "JSON Parse failed: {}, {}" . format ( url , e ) ) raise except ValueError as e : self . _critical_service ( service_name , service_check_tags , str ( e ) ) raise return response_json