Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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()
        )
Exemplo n.º 3
0
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()
        )
Exemplo n.º 4
0
 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)
     ]
Exemplo n.º 5
0
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()
        )
Exemplo n.º 6
0
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()
        )
Exemplo n.º 7
0
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())
Exemplo n.º 8
0
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())
Exemplo n.º 9
0
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()
    )
Exemplo n.º 10
0
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'
Exemplo n.º 11
0
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'
Exemplo n.º 12
0
Arquivo: views.py Projeto: skob/alerta
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"
Exemplo n.º 13
0
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'
Exemplo n.º 14
0
 def find_all(query: Query=None) -> List['Heartbeat']:
     return [Heartbeat.from_db(heartbeat) for heartbeat in db.get_heartbeats(query)]
Exemplo n.º 15
0
 def find_all(query=None):
     return [
         Heartbeat.from_db(heartbeat)
         for heartbeat in db.get_heartbeats(query)
     ]
Exemplo n.º 16
0
 def find_all(query=None):
     return [Heartbeat.from_db(heartbeat) for heartbeat in db.get_heartbeats(query)]