SNMP Agent in Python -
i required snmp agent in python, listen on particular port , and responds basic snmp command (like gte, set, getnext ...etc)
if 1 have code please reply on post.
there's collection of snmp command responder scripts @ pysnmp web-site.
here's simple pysnmp-based command responder uses text files in /tmp mib data store.
from pysnmp.entity import engine, config pysnmp.entity.rfc3413 import cmdrsp, context pysnmp.carrier.asynsock.dgram import udp pysnmp.smi import instrum, error pysnmp.proto.api import v2c snmpengine = engine.snmpengine() config.addsockettransport( snmpengine, udp.domainname, udp.udptransport().openservermode(('127.0.0.1', 1161)) ) config.addv1system(snmpengine, 'my-area', 'public', contextname='my-context') config.addvacmuser(snmpengine, 2, 'my-area', 'noauthnopriv', (1,3,6), (1,3,6)) snmpcontext = context.snmpcontext(snmpengine) class fileinstrumcontroller(instrum.abstractmibinstrumcontroller): def readvars(self, vars, acinfo=(none, none)): try: return [ (o,v2c.octetstring(open('/tmp/%s.txt' % o, 'r').read())) o,v in vars ] except ioerror: raise error.smierror def writevars(self, vars, acinfo=(none, none)): try: o,v in vars: open('/tmp/%s.txt' % o, 'w').write(str(v)) return vars except ioerror: raise error.smierror snmpcontext.registercontextname( v2c.octetstring('my-context'), # context name fileinstrumcontroller() # management instrumentation ) cmdrsp.getcommandresponder(snmpengine, snmpcontext) cmdrsp.setcommandresponder(snmpengine, snmpcontext) snmpengine.transportdispatcher.jobstarted(1) try: snmpengine.transportdispatcher.rundispatcher() except: snmpengine.transportdispatcher.closedispatcher() raise
keep in mind script starter you, not handle corner cases.