def _get_room(self, room): """Get Room object, creating it if necessary.""" from hipnotify import Room if room not in self._rooms: self._rooms[room] = Room( token=self._token, room_id=room, endpoint_url=self._host) return self._rooms[room]
class Alert(object): def __init__(self, config): self.HIPCHAT_TOKEN = config['hipchat_token'] self.HIPCHAT_ROOM_ID = config['hipchat_room'] self.room = Room(self.HIPCHAT_TOKEN, self.HIPCHAT_ROOM_ID) def run(self, data): try: for d in data: if d['status'] == 1: continue elif d['status'] == 2: self.room.notify( "--------------------------------------------------------------------------------\n" "RabbitMQ Message Queue Filled\n" "--------------------------------------------------------------------------------\n" "Queue: {0}\n" "Environment: {1}\n" "Messages in Queue: {2}\n" "Message Processing Rate: {3}".format(d['queue'], d['env'], d['messages_remaining'], d['process_rate']) ) continue elif d['status'] == 3: self.room.notify( "--------------------------------------------------------------------------------\n" "RabbitMQ Messages processing slowly\n" "--------------------------------------------------------------------------------\n" "Queue: {0}\n" "Environment: {1}\n" "Messages in Queue: {2}\n" "Message Processing Rate: {3}".format(d['queue'], d['env'], d['messages_remaining'], d['process_rate']) ) continue elif d['status'] == 4: self.room.notify( "--------------------------------------------------------------------------------\n" "RabbitMQ Health Rule Violation\n" "--------------------------------------------------------------------------------\n" "Reason: Unknown\n" "Queue: {0}\n" "Environment: {1}\n" "Messages in Queue: {2}\n" "Message Processing Rate: {3}".format(d['queue'], d['env'], d['messages_remaining'], d['process_rate']) ) continue except Exception as ex: raise Exception('Error: {}'.format(ex))
def __init__(self, config): self.HIPCHAT_TOKEN = config['hipchat_token'] self.HIPCHAT_ROOM_ID = config['hipchat_room'] self.room = Room(self.HIPCHAT_TOKEN, self.HIPCHAT_ROOM_ID)
def test_debug_room_notification(mock_hipchat): """Test for debug mode""" hip = Room('test_token', '1234', debug=True) res = hip.notify('test') assert res == []
def test_room_notification(mock_hipchat): """Test with HipChat API mock""" hip = Room('test_token', '1234') res = hip.notify('test') assert res.status_code == 200
def send_message_hipchat(self): room = Room(settings.HIPCHAT_TOKEN, settings.HIPCHAT_ROOM_ID) message = '%s %s %s %s' % (self.username, self.title, self.text, ' '.join(self.tags)) room.notify(message)