def cache_oids(backend): # Cache OIDs to avoid actual SNMP I/O. snmp_cache.initialize_single_oid_cache(backend.config) snmp_cache.set_single_oid_cache(snmp_scan.OID_SYS_DESCR, "sys description") snmp_cache.set_single_oid_cache(snmp_scan.OID_SYS_OBJ, "sys object") yield snmp_cache._clear_other_hosts_oid_cache(backend.hostname)
def _snmp_scan_cache_description( binary_host: bool, *, backend: ABCSNMPBackend, ) -> None: if not binary_host: for oid, name in [ (OID_SYS_DESCR, "system description"), (OID_SYS_OBJ, "system object"), ]: value = snmp_modes.get_single_oid( oid, backend=backend, ) if value is None: raise MKSNMPError( "Cannot fetch %s OID %s. Please check your SNMP " "configuration. Possible reason might be: Wrong credentials, " "wrong SNMP version, Firewall rules, etc." % (name, oid),) else: # 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.set_single_oid_cache(OID_SYS_DESCR, "") snmp_cache.set_single_oid_cache(OID_SYS_OBJ, "")
def test_snmp_scan_cache_description__oid_missing(oid, backend): snmp_cache.set_single_oid_cache(oid, None) with pytest.raises(snmp_scan.MKSNMPError, match=r"Cannot fetch [\w ]+ OID %s" % oid): snmp_scan._snmp_scan_cache_description( False, do_snmp_scan=False, backend=backend, )
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.set_single_oid_cache(OID_SYS_DESCR, "") snmp_cache.set_single_oid_cache(OID_SYS_OBJ, "")
def test_snmp_scan_prefetch_description_object__oid_missing(oid, backend): snmp_cache.set_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)