1 """Simple example of an Agent for testing""" 2 from twisted.internet import reactor 3 from twisted.internet import error as twisted_error 4 from twistedsnmp import agent, agentprotocol, bisectoidstore 5 try: 6 from twistedsnmp import bsdoidstore 7 except ImportError: 8 import warnings 9 warnings.warn( """No BSDDB OID Storage available for testing""" ) 10 bsdoidstore = None 11 12 def createAgent( oids ): 13 ports = [161]+range(20000,25000) 14 for port in ports: 15 try: 16 agentObject = reactor.listenUDP( 17 port, agentprotocol.AgentProtocol( 18 snmpVersion = 'v2c', 19 agent = agent.Agent( 20 dataStore = bisectoidstore.BisectOIDStore( 21 OIDs = oids, 22 ), 23 ), 24 ), 25 ) 26 except twisted_error.CannotListenError: 27 pass 28 else: 29 return agentObject, port 30 31 testingOIDs = { 32 '.1.3.6.1.2.1.1.1.0': 'Some tool out in the field', 33 '.1.3.6.1.2.1.1.2.0': '.1.3.6.1.4.1.88.3.1', 34 '.1.3.6.1.2.1.1.3.0': 558566090, 35 '.1.3.6.1.2.1.1.4.0': "support@somewhere.ca", 36 '.1.3.6.1.2.1.1.5.0': "NameOfSystem", 37 '.1.3.6.1.2.1.1.6.0': "SomeHeadEnd, West Hinterlands, Canada", 38 } 39 40 def main(oids=testingOIDs): 41 agent, port = createAgent( oids ) 42 43 if __name__ == "__main__": 44 reactor.callWhenRunning( main ) 45 reactor.run() 46