def get_heartbeats(): customer = g.get('customer', None) if customer: query = {'customer': customer} else: query = {} try: heartbeats = db.get_heartbeats(query) except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() body['href'] = absolute_url('/heartbeat/' + hb.id) hb_list.append(body) if hb_list: return jsonify(status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow()) else: return jsonify(status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow())
def get_heartbeats(): customer = g.get('customer', None) if customer: query = {'customer': customer} else: query = {} try: heartbeats = db.get_heartbeats(query) except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() body['href'] = absolute_url('/heartbeat/' + hb.id) hb_list.append(body) if hb_list: return jsonify( status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow() ) else: return jsonify( status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow() )
def get_heartbeats(): try: heartbeats = db.get_heartbeats() except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() body['href'] = "%s/%s" % (request.base_url.replace('heartbeats', 'heartbeat'), hb.id) hb_list.append(body) if hb_list: return jsonify( status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow() ) else: return jsonify( status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow() )
def find_all(query: Query = None, page: int = 1, page_size: int = 1000) -> List['Heartbeat']: return [ Heartbeat.from_db(heartbeat) for heartbeat in db.get_heartbeats(query, page, page_size) ]
def get_heartbeats(tenant): tenant = generateDBName(tenant) try: heartbeats = db.get_heartbeats(tenant) except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() if g.get('role', None) != 'admin' and not body['customer'] == g.get('customer', None): continue body['href'] = "%s/%s" % (request.base_url.replace('heartbeats', 'heartbeat'), hb.id) hb_list.append(body) if hb_list: return jsonify( status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow() ) else: return jsonify( status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow() )
def get_heartbeats(): try: heartbeats = db.get_heartbeats() except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() if g.get('role', None) != 'admin' and not body['customer'] == g.get('customer', None): continue body['href'] = absolute_url('/heartbeat/' + hb.id) hb_list.append(body) if hb_list: return jsonify( status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow() ) else: return jsonify( status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow() )
def get_heartbeats(): try: heartbeats = db.get_heartbeats() except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() body['href'] = "%s/%s" % (request.base_url.replace( 'heartbeats', 'heartbeat'), hb.id) hb_list.append(body) if hb_list: return jsonify(status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow()) else: return jsonify(status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow())
def get_heartbeats(): try: heartbeats = db.get_heartbeats() except Exception as e: return jsonify(status="error", message=str(e)), 500 hb_list = list() for hb in heartbeats: body = hb.get_body() if g.get('role', None) != 'admin' and not body['customer'] == g.get( 'customer', None): continue body['href'] = absolute_url('/heartbeat/' + hb.id) hb_list.append(body) if hb_list: return jsonify(status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow()) else: return jsonify(status="ok", message="not found", total=0, heartbeats=hb_list, time=datetime.datetime.utcnow())
def get_heartbeats(): heartbeats = db.get_heartbeats() hb_list = list() for hb in heartbeats: hb_list.append(hb.get_body()) return jsonify( status="ok", total=len(heartbeats), heartbeats=hb_list, time=datetime.datetime.utcnow() )
def health_check(): try: heartbeats = db.get_heartbeats() for heartbeat in heartbeats: delta = datetime.datetime.utcnow() - heartbeat.receive_time threshold = float(heartbeat.timeout) * 4 if delta.seconds > threshold: return 'HEARTBEAT_STALE: %s' % heartbeat.origin, 503 except Exception as e: return 'HEALTH_CHECK_FAILED: %s' % e, 503 return 'OK'
def health_check(): try: heartbeats = db.get_heartbeats() for heartbeat in heartbeats: delta = datetime.datetime.utcnow() - heartbeat.receive_time threshold = float(heartbeat.timeout) * 4 if delta.seconds > threshold: return 'HEARTBEAT_STALE: %s' % heartbeat.origin , 503 except Exception as e: return 'HEALTH_CHECK_FAILED: %s' % e, 503 return 'OK'
def health_check(): try: if not db.conn.alive(): return "NO_DATABASE", 503 heartbeats = db.get_heartbeats() for heartbeat in heartbeats: delta = datetime.datetime.utcnow() - heartbeat.receive_time threshold = float(heartbeat.timeout) * 4 if delta.seconds > threshold: return "HEARTBEAT_STALE: %s" % heartbeat.origin, 503 except Exception as e: return "HEALTH_CHECK_FAILED: %s" % e, 503 return "OK"
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.receive_time threshold = float(heartbeat.timeout) * 4 if delta.seconds > threshold: return 'HEARTBEAT_STALE', 503 except Exception as e: return 'HEALTH_CHECK_FAILED: %s' % e, 503 return 'OK'
def find_all(query: Query=None) -> List['Heartbeat']: return [Heartbeat.from_db(heartbeat) for heartbeat in db.get_heartbeats(query)]
def find_all(query=None): return [ Heartbeat.from_db(heartbeat) for heartbeat in db.get_heartbeats(query) ]
def find_all(query=None): return [Heartbeat.from_db(heartbeat) for heartbeat in db.get_heartbeats(query)]