Пример #1
0
def get_incident(key):
    try:
        incident = redis.hgetall(key)
        incident['host'] = redis.hgetall(KEY_DEVICE+get_device_id_hash(incident['node_id']))
        return jsonify_incident(key, incident)
    except:
        return None
def get_incident(key):
    try:
        incident = redis.hgetall(key)
        incident['host'] = redis.hgetall(
            KEY_DEVICE + get_device_id_hash(incident['node_id']))
        return jsonify_incident(key, incident)
    except:
        return None
Пример #3
0
def get_device(node_id):
    try:
        host = redis.hgetall(KEY_DEVICE+get_device_id_hash(node_id))
        host['unacknowleged_incidents'] = get_unacknowledged_incidents(include_hosts=False, node_id=node_id)
        return host
    except:
        return None
def get_device(node_id):
    try:
        host = redis.hgetall(KEY_DEVICE + get_device_id_hash(node_id))
        host['unacknowleged_incidents'] = get_unacknowledged_incidents(
            include_hosts=False, node_id=node_id)
        return host
    except:
        return None
Пример #5
0
def _filter_incidents(filter_=None, include_hosts=True):
    host_cache = {}
    keys = redis.zrangebyscore(KEY_INCIDENTS, '-inf', '+inf')
    incidents = []
    for key in keys:
        incident = redis.hgetall(key)
        try:
            if not filter_(incident):
                continue

            if include_hosts:
                if not host_cache.has_key(incident['node_id']):
                    host_cache[incident['node_id']] = \
                        redis.hgetall(KEY_DEVICE+get_device_id_hash(incident['node_id']))
                incident['host'] = host_cache[incident['node_id']]
            incidents.append(jsonify_incident(key, incident))
        except Exception as e:
            logger.critical(e)

    return incidents
def _filter_incidents(filter_=None, include_hosts=True):
    host_cache = {}
    keys = redis.zrangebyscore(KEY_INCIDENTS, '-inf', '+inf')
    incidents = []
    for key in keys:
        incident = redis.hgetall(key)
        try:
            if not filter_(incident):
                continue

            if include_hosts:
                if not host_cache.has_key(incident['node_id']):
                    host_cache[incident['node_id']] = \
                        redis.hgetall(KEY_DEVICE+get_device_id_hash(incident['node_id']))
                incident['host'] = host_cache[incident['node_id']]
            incidents.append(jsonify_incident(key, incident))
        except Exception as e:
            logger.critical(e)

    return incidents