diff --git a/config.py b/config.py index 7c4cf4b0144305b6ce523667284128a68d0b9127..21d5ddca8c12485f5d7234f01048fa45e34d35cd 100644 --- a/config.py +++ b/config.py @@ -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()