Ejemplo n.º 1
0
def test_base_logging_handler_emit_system_tracking():
    handler = BaseHandler(host='127.0.0.1', enabled_flag=True,
                          message_type='logstash', indv_facts=True, lvl='INFO',
                          enabled_loggers=['awx', 'activity_stream', 'job_events', 'system_tracking'])
    handler.setFormatter(LogstashFormatter())
    record = logging.LogRecord(
        'awx.analytics.system_tracking', # logger name
        20, # loglevel INFO
        './awx/some/module.py', # pathname
        100, # lineno
        None, # msg
        tuple(), # args,
        None # exc_info
    )
    record.inventory_id = 11
    record.host_name = 'my_lucky_host'
    record.ansible_facts = {
        "ansible_kernel": "4.4.66-boot2docker",
        "ansible_machine": "x86_64",
        "ansible_swapfree_mb": 4663,
    }
    record.ansible_facts_modified = datetime.datetime.now(tzutc()).isoformat()
    sent_payloads = handler.emit(record)

    assert len(sent_payloads) == 1
    assert sent_payloads[0]['ansible_facts'] == record.ansible_facts
    assert sent_payloads[0]['level'] == 'INFO'
    assert sent_payloads[0]['logger_name'] == 'awx.analytics.system_tracking'
Ejemplo n.º 2
0
def test_base_logging_handler_ignore_low_severity_msg(dummy_log_record):
    handler = BaseHandler(host='127.0.0.1', enabled_flag=True,
                          message_type='logstash', lvl='WARNING',
                          enabled_loggers=['awx', 'activity_stream', 'job_events', 'system_tracking'])
    handler.setFormatter(LogstashFormatter())
    sent_payloads = handler.emit(dummy_log_record)
    assert len(sent_payloads) == 0
Ejemplo n.º 3
0
def test_base_logging_handler_emit_system_tracking(dummy_log_record):
    handler = BaseHandler(host='127.0.0.1', indv_facts=True)
    handler.setFormatter(LogstashFormatter())
    dummy_log_record.name = 'awx.analytics.system_tracking'
    dummy_log_record.msg = None
    dummy_log_record.inventory_id = 11
    dummy_log_record.host_name = 'my_lucky_host'
    dummy_log_record.job_id = 777
    dummy_log_record.ansible_facts = {
        "ansible_kernel": "4.4.66-boot2docker",
        "ansible_machine": "x86_64",
        "ansible_swapfree_mb": 4663,
    }
    dummy_log_record.ansible_facts_modified = datetime.datetime.now(
        tzutc()).isoformat()
    sent_payloads = handler.emit(dummy_log_record)

    assert len(sent_payloads) == 1
    assert sent_payloads[0]['ansible_facts'] == dummy_log_record.ansible_facts
    assert sent_payloads[0][
        'ansible_facts_modified'] == dummy_log_record.ansible_facts_modified
    assert sent_payloads[0]['level'] == 'INFO'
    assert sent_payloads[0]['logger_name'] == 'awx.analytics.system_tracking'
    assert sent_payloads[0]['job_id'] == dummy_log_record.job_id
    assert sent_payloads[0]['inventory_id'] == dummy_log_record.inventory_id
    assert sent_payloads[0]['host_name'] == dummy_log_record.host_name
Ejemplo n.º 4
0
def test_base_logging_handler_emit(dummy_log_record):
    handler = BaseHandler(host='127.0.0.1', enabled_flag=True,
                          message_type='logstash', lvl='INFO',
                          enabled_loggers=['awx', 'activity_stream', 'job_events', 'system_tracking'])
    handler.setFormatter(LogstashFormatter())
    sent_payloads = handler.emit(dummy_log_record)

    assert len(sent_payloads) == 1
    body = json.loads(sent_payloads[0])

    assert body['level'] == 'INFO'
    assert body['logger_name'] == 'awx'
    assert body['message'] == 'User joe logged in'