Exemple #1
0
def test_instance_finder_address_cannot_find_name(get_host_name):
    logger = FakeLogger()

    action = {
        'instance': {
            'finder': re.compile("^(?P<address>[a-z]+)$"),
            'oid': 'something',
        },
    }

    details = {
        'something': 'anything',
        'unimportant': 'notthis',
    }

    get_host_name.return_value = None

    with pytest.raises(snmp_trap_handler.MonitoredHostNotFoundError):
        snmp_trap_handler.find_target_instance(
            action=action,
            details=details,
            message_source='notimportant',
            logger=logger,
        )

    assert logger.string_appears_in('debug', ('look up', 'name'))
    assert logger.string_appears_in('debug', 'details finder found')
    assert logger.string_appears_in('error', 'no host found')
Exemple #2
0
def test_no_instance_finder_cannot_find_name(get_host_name):
    logger = FakeLogger()

    source_address = 'thesource'

    action = {}

    details = {
        'unimportant': 'notthis',
    }

    get_host_name.return_value = None

    with pytest.raises(snmp_trap_handler.MonitoredHostNotFoundError):
        snmp_trap_handler.find_target_instance(
            action=action,
            details=details,
            message_source=source_address,
            logger=logger,
        )

    assert logger.string_appears_in('debug', ('look up', 'name'))
    assert not logger.string_appears_in('debug', 'details finder found')
    assert logger.string_appears_in('error', 'no host found')

    get_host_name.assert_called_once_with(source_address)
Exemple #3
0
def test_instance_finder_address_can_find_name(get_host_name):
    logger = FakeLogger()

    expected_name = 'thename'

    action = {
        'instance': {
            'finder': re.compile("^(?P<address>[a-z]+)$"),
            'oid': 'something',
        },
    }

    details = {
        'something': 'anything',
        'unimportant': 'notthis',
    }

    get_host_name.return_value = expected_name

    result = snmp_trap_handler.find_target_instance(
        action=action,
        details=details,
        message_source='notimportant',
        logger=logger,
    )

    assert result == expected_name

    assert logger.string_appears_in('debug', ('look up', 'name'))
    assert logger.string_appears_in('debug', 'details finder found')
Exemple #4
0
def test_no_instance_finder_can_find_name(get_host_name):
    logger = FakeLogger()

    expected_name = 'thename'
    source_address = 'thesource'

    action = {}

    details = {
        'unimportant': 'notthis',
    }

    get_host_name.return_value = expected_name

    result = snmp_trap_handler.find_target_instance(
        action=action,
        details=details,
        message_source=source_address,
        logger=logger,
    )

    assert result == expected_name

    assert logger.string_appears_in('debug', ('look up', 'name'))
    assert not logger.string_appears_in('debug', 'details finder found')

    get_host_name.assert_called_once_with(source_address)