def health_check(): try: if not mq.is_connected(): return 'NO_MESSAGE_QUEUE', 503 if not db.conn.alive(): return 'NO_DATABASE', 503 heartbeats = db.get_heartbeats() for heartbeat in heartbeats: delta = datetime.datetime.utcnow() - heartbeat['receiveTime'] threshold = float(heartbeat['timeout']) * 4 if delta.seconds > threshold: return 'HEARTBEAT_STALE', 503 except Exception: return 'HEALTH_CHECK_FAILED', 503 return 'OK'
def get_heartbeats(): heartbeats = db.get_heartbeats() return jsonify(application="alerta", time=int(time.time() * 1000), heartbeats=heartbeats)
def get_heartbeats(): heartbeats = db.get_heartbeats() return jsonify(application="alerta", time=int(time.time() * 1000), heartbeats=heartbeats)