Example #1
0
def _dict_to_db(msg):
    db_event = Event()

    event_msg = {}
    event_msg.update(msg)

    if event_msg.get('source', None):
        db_event.source_servicename = event_msg['source'].get('servicename', None)
        db_event.source_hostid = event_msg['source'].get('hostid', None)
        db_event.source_base_url = event_msg['source'].get('base_url', None)
        db_event.source_request_id = event_msg['source'].get('request_id', None)

    if event_msg.get('resource', None):
        db_event.resource_user_id = event_msg['resource'].get('user_id', None)
        db_event.resource_id = event_msg['resource'].get('id', None)
        db_event.resource_type = event_msg['resource'].get('type', None)

    db_event.type = event_msg['type']
    db_event.level = event_msg['level']
    db_event.message = event_msg['message']
    db_event.details = event_msg.get('details', {})
    db_event.timestamp = dateparser.parse(event_msg['timestamp'])

    return db_event
Example #2
0
def _dict_to_db(msg):
    db_event = Event()

    event_msg = {}
    event_msg.update(msg)

    if event_msg.get("source", None):
        db_event.source_servicename = event_msg["source"].get(
            "servicename", None)
        db_event.source_hostid = event_msg["source"].get("hostid", None)
        db_event.source_base_url = event_msg["source"].get("base_url", None)
        db_event.source_request_id = event_msg["source"].get(
            "request_id", None)

    if event_msg.get("resource", None):
        db_event.resource_user_id = event_msg["resource"].get("user_id", None)
        db_event.resource_id = event_msg["resource"].get("id", None)
        db_event.resource_type = event_msg["resource"].get("type", None)

    db_event.type = event_msg["type"]
    db_event.level = event_msg["level"]
    db_event.message = event_msg["message"]
    db_event.details = event_msg.get("details", {})
    db_event.timestamp = dateparser.parse(event_msg["timestamp"])

    return db_event