Skip to content
Snippets Groups Projects
Commit 3aa6d81a authored by Erik Reid's avatar Erik Reid
Browse files

simpler method for retreiving snmp indexes

parent 0aa91cd7
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,18 @@ from pysnmp.smi import builder, compiler ...@@ -7,6 +7,18 @@ from pysnmp.smi import builder, compiler
# from pysnmp.smi import view, rfc1902 # 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): def _v6address_oid2str(dotted_decimal):
hex_params = [] hex_params = []
for dec in re.split(r'\.', dotted_decimal): for dec in re.split(r'\.', dotted_decimal):
...@@ -78,6 +90,15 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover ...@@ -78,6 +90,15 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
yield result 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): def get_router_interfaces(hostname, community, config):
oid_map = config["oids"] oid_map = config["oids"]
...@@ -123,3 +144,10 @@ def get_router_interfaces(hostname, community, config): ...@@ -123,3 +144,10 @@ def get_router_interfaces(hostname, community, config):
"v6InterfaceName": v6IfcNames[m.group(1)], "v6InterfaceName": v6IfcNames[m.group(1)],
"index": 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))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment