Esempio n. 1
0
def cache_oids(backend):
    # Cache OIDs to avoid actual SNMP I/O.
    snmp_cache.initialize_single_oid_cache(backend.config)
    snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_DESCR] = "sys description"
    snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_OBJ] = "sys object"
    yield
    snmp_cache._clear_other_hosts_oid_cache(backend.hostname)
Esempio n. 2
0
def test_get_single_oid_cache(backend):
    oid = ".1.3.6.1.2.1.1.1.0"
    expected_value = "Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686"

    assert snmp_modes.get_single_oid(oid, backend=backend) == expected_value
    assert oid in snmp_cache.single_oid_cache()
    cached_oid = snmp_cache.single_oid_cache()[oid]
    assert cached_oid == expected_value
    assert isinstance(cached_oid, str)
Esempio n. 3
0
def _fake_description_object() -> None:
    """Fake OID values to prevent issues with a lot of scan functions"""
    console.vverbose(
        "       Skipping system description OID "
        '(Set %s and %s to "")\n',
        OID_SYS_DESCR,
        OID_SYS_OBJ,
    )
    snmp_cache.single_oid_cache()[OID_SYS_DESCR] = ""
    snmp_cache.single_oid_cache()[OID_SYS_OBJ] = ""
Esempio n. 4
0
def test_snmp_scan_prefetch_description_object__success(backend):
    sys_desc = snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_DESCR]
    sys_obj = snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_OBJ]
    assert sys_desc
    assert sys_obj

    snmp_scan._prefetch_description_object(backend=backend)

    # Success is no-op
    assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_DESCR] == sys_desc
    assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_OBJ] == sys_obj
Esempio n. 5
0
def test_gather_available_raw_section_names_defaults(backend, mocker):
    assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_DESCR]
    assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_OBJ]

    assert snmp_scan.gather_available_raw_section_names(
        [(s.name, s.detect_spec) for s in agent_based_register.iter_all_snmp_sections()],
        on_error=OnError.RAISE,
        missing_sys_description=False,
        backend=backend,
    ) == {
        SectionName("hr_mem"),
        SectionName("snmp_info"),
        SectionName("snmp_os"),
        SectionName("snmp_uptime"),
    }
Esempio n. 6
0
def test_snmp_scan_fake_description_object__success(backend):
    snmp_scan._fake_description_object()

    assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_DESCR] == ""
    assert snmp_cache.single_oid_cache()[snmp_scan.OID_SYS_OBJ] == ""
Esempio n. 7
0
def test_snmp_scan_prefetch_description_object__oid_missing(oid, backend):
    snmp_cache.single_oid_cache()[oid] = None

    with pytest.raises(snmp_scan.MKSNMPError,
                       match=r"Cannot fetch [\w ]+ OID %s" % oid):
        snmp_scan._prefetch_description_object(backend=backend)