Example #1
0
 def on_receive(self, client):
     try:
         message_type, message = client.receive_message()
         deserialized_message = deserialize_json(message)
         updated_checks = self._client_manager.process_message(client, message_type, deserialized_message)
         [self._write_queue(client, message_type, uc) for uc in updated_checks]
     except MessageNotReady:
         pass
Example #2
0
 def _deserialize_output(self, output):
     try:
         valid_fields = ['status', 'details', 'data']
         d = {k.lower(): v for k, v in deserialize_json(output).iteritems() if k.lower() in valid_fields}
         d.update({
             'status': self.STATUS[d['status'].upper()],
             'id': self.id,
         })
     except ValueError, e:
         raise CheckError('Error - Couldn\'t parse JSON from check output. Details : {:}'.format(e))
Example #3
0
    def get_request(self, path):
        ''' Perform an http GET request on a resource

        :param path: The path up from the root to operate on
        :returns: The result of the operation
        '''
        _logger.debug('Getting resource %s' % path)
        resource = self.base + path
        response, content = self.client.request(resource, "GET",
            headers=self.headers)
        if response.status != 200:
            raise Exception('error getting with the api', response.content)
        return deserialize_json(content)
Example #4
0
    def post_request(self, path, data):
        ''' Perform an http POST request on a resource

        :param path: The path up from the root to operate on
        :param data: The data to send to the resource
        :returns: The result of the operation
        '''
        _logger.debug('Creating resource %s' % path)
        resource = self.base + path
        response, content = self.client.request(resource, "POST",
            body=data, headers=self.headers)
        if response.status != 200:
            raise Exception('error creating with the api', response.content)
        return deserialize_json(content)
Example #5
0
 def on_receive(self):
     message_type, message = self.receive_message()
     self._output_queue.put_nowait({
         'message_type': message_type,
         'message': deserialize_json(message),
     })