0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-03-16 14:23:28 +00:00

add api health check response

This commit is contained in:
Nick Satterly 2013-04-01 21:05:39 +01:00
parent 8a31cde23a
commit a460b81e66
2 changed files with 18 additions and 3 deletions
alerta
api/v2
common

View file

@ -16,7 +16,7 @@ from alerta.common import log as logging
from alerta.alert import Alert, Heartbeat, severity, status, ATTRIBUTES
from alerta.common.utils import DateEncoder
Version = '2.0.3'
Version = '2.0.4'
LOG = logging.getLogger(__name__)
CONF = config.CONF
@ -238,7 +238,7 @@ def create_alert():
graph_urls=data.get('graphUrls', None),
)
LOG.debug('New alert %s', newAlert)
create_mq.send(newAlert)
mq.send(newAlert)
if newAlert:
return jsonify(response={"status": "ok", "id": newAlert.get_id()})
@ -408,6 +408,18 @@ def create_heartbeat():
return jsonify(response={"status": "error", "message": "something went wrong"})
@app.route('/management/healthcheck')
def health_check():
if not create_mq.is_connected():
return 'NO_MESSAGE_QUEUE', 503
if not db.conn.alive():
return 'NO_DATABASE', 503
return 'OK'
# Only use when running API in stand-alone mode during testing
@app.route('/alerta/dashboard/<path:filename>')
def console(filename):

View file

@ -84,11 +84,14 @@ class Messaging(object):
LOG.info('Message sent to broker %s:%s', CONF.stomp_host, CONF.stomp_port)
def disconnect(self):
if self.conn.is_connected():
if self.is_connected():
LOG.info('Disconnecting from broker %s:%s', CONF.stomp_host, CONF.stomp_port)
self.conn.disconnect()
LOG.info('Disconnected!')
def is_connected(self):
return self.conn.is_connected()
class MessageHandler(ConnectionListener):
"""