diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py index a5a48b7067e75117756d779c87abdd1767718c48..e7cc25a4b351b02a14546fc6971899ba08a95e39 100644 --- a/inventory_provider/snmp.py +++ b/inventory_provider/snmp.py @@ -7,6 +7,18 @@ from pysnmp.smi import builder, compiler # from pysnmp.smi import view, rfc1902 +OID_LIST = { + ## IPv4 + 'v4Address': '.1.3.6.1.2.1.4.20.1.1', + 'v4InterfaceOID': '.1.3.6.1.2.1.4.20.1.2', + 'v4InterfaceName': '.1.3.6.1.2.1.31.1.1.1.1', + 'v4Mask': '.1.3.6.1.2.1.4.20.1.3', + + ## IPv6 + 'v6AddressAndMask' '.1.3.6.1.2.1.55.1.8.1.2' + 'v6InterfaceName': '.1.3.6.1.2.1.55.1.5.1.2' +} + def _v6address_oid2str(dotted_decimal): hex_params = [] for dec in re.split(r'\.', dotted_decimal): @@ -78,6 +90,15 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover yield result +def get_router_snmp_indexes(hostname, community): + indexes = {} + RFC1213_MIB_ifDesc = '1.3.6.1.2.1.2.2.1.2' + for ifc in walk(hostname, community, RFC1213_MIB_ifDesc): + m = re.match(r'.*\.(\d+)$', ifc['oid']) + assert m, 'sanity failure parsing oid: %r' % ifc['oid'] + indexes[ifc['value']] = int(m.group(1)) + return indexes + def get_router_interfaces(hostname, community, config): oid_map = config["oids"] @@ -123,3 +144,10 @@ def get_router_interfaces(hostname, community, config): "v6InterfaceName": v6IfcNames[m.group(1)], "index": m.group(1) } + +if __name__ == "__main__": + hostname = 'mx1.ams.nl.geant.net' + community = '0pBiFbD' + interfaces = get_router_snmp_indexes(hostname, community) + for name, index in interfaces.items(): + print('%s: %s' % (name, index))