예제 #1
0
def _perform_snmpwalk(snmp_config, check_plugin_name, base_oid, fetchoid):
    # type: (SNMPHostConfig, CheckPluginName, OID, OID) -> SNMPRowInfo
    added_oids = set([])  # type: Set[OID]
    rowinfo = []  # type: SNMPRowInfo

    for context_name in snmp_config.snmpv3_contexts_of(check_plugin_name):
        rows = SNMPBackendFactory.walk(snmp_config,
                                       oid=fetchoid,
                                       check_plugin_name=check_plugin_name,
                                       table_base_oid=base_oid,
                                       context_name=context_name)

        # I've seen a broken device (Mikrotik Router), that broke after an
        # update to RouterOS v6.22. It would return 9 time the same OID when
        # .1.3.6.1.2.1.1.1.0 was being walked. We try to detect these situations
        # by removing any duplicate OID information
        if len(rows) > 1 and rows[0][0] == rows[1][0]:
            console.vverbose(
                "Detected broken SNMP agent. Ignoring duplicate OID %s.\n" %
                rows[0][0])
            rows = rows[:1]

        for row_oid, val in rows:
            if row_oid in added_oids:
                console.vverbose("Duplicate OID found: %s (%r)\n" %
                                 (row_oid, val))
            else:
                rowinfo.append((row_oid, val))
                added_oids.add(row_oid)

    return rowinfo
예제 #2
0
def walk_for_export(snmp_config, oid):
    # type: (SNMPHostConfig, OID) -> SNMPRowInfoForStoredWalk
    rows = SNMPBackendFactory.walk(snmp_config, use_cache=False, oid=oid)
    return _convert_rows_for_stored_walk(rows)