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

added basic snmp walk function

parent 88205d25
No related branches found
No related tags found
No related merge requests found
......@@ -4,9 +4,41 @@ import re
import click
import mysql.connector
from pysnmp.hlapi import nextCmd, SnmpEngine, CommunityData, \
UdpTransportTarget, ContextData, ObjectType, ObjectIdentity
def walk(agent_hostname, community, base_oid):
"""
https://stackoverflow.com/a/45001921
http://snmplabs.com/pysnmp/docs/hlapi/asyncore/sync/manager/cmdgen/nextcmd.html
http://snmplabs.com/pysnmp/faq/pass-custom-mib-to-manager.html
:param agent_hostname:
:param community:
:param base_oid:
:return:
"""
print("walking %s: %s" % (agent_hostname, base_oid))
for (engineErrorIndication,
pduErrorIndication,
errorIndex,
varBinds) in nextCmd(
SnmpEngine(),
CommunityData(community),
UdpTransportTarget((agent_hostname, 161)),
ContextData(),
ObjectType(ObjectIdentity(base_oid)),
lexicographicMode=False):
assert not engineErrorIndication
assert not pduErrorIndication
assert errorIndex == 0
for oid, val in varBinds:
print("\toid: '%s', val: '%s'" % (
oid.prettyPrint(), val.prettyPrint()))
def _validate_config(ctx, param, value):
"""
......@@ -98,7 +130,7 @@ def cli(config):
with open("routers_community.conf") as f:
for r in load_routers(f):
_db_test(c, r)
walk(r["hostname"], r["community"], ".1.3.6.1.2.1.4.20.1.1")
if __name__ == "__main__":
cli()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment