def start(self): reactor.listenUDP( 161, agentprotocol.AgentProtocol( snmpVersion='v2c', agent=agent.Agent(dataStore=bisectoidstore.BisectOIDStore( OIDs=self.oids, ), ), ), interface=self.ip, )
def createAgent(self): from twisted.internet import reactor port = 161 try: self.agentObject = reactor.listenUDP( port, agentprotocol.AgentProtocol( snmpVersion='v2c', agent=agent.Agent(dataStore=self.oidstore), ), ) self.theAgent = self.agentObject.protocol.agent except twisted_error.CannotListenError: pass else: return port
def main( ): ports = [161]+range(20000,25000) for port in ports: try: reactor.listenUDP( port, agentprotocol.AgentProtocol( snmpVersion = 'v2c', agent = agent.Agent( dataStore = createStorage(), ), ), ) print 'listening on port', port return port except twisted_error.CannotListenError: pass
def start(): for n, (ip, oids) in enumerate(agents.iteritems()): print '%s) %s:%s' % (n, ip, port) p = udp.Port( port, agentprotocol.AgentProtocol( snmpVersion='v2c', agent=agent.Agent(dataStore=bisectoidstore.BisectOIDStore( OIDs=oids, ), ), community=None, # accept all communities ), ip, 8192, # maxPacketSize reactor) p.startListening() print 'are simulated.'
def createAgent( oids ): ports = [161]+range(20000,25000) for port in ports: try: agentObject = reactor.listenUDP( port, agentprotocol.AgentProtocol( snmpVersion = 'v2c', agent = agent.Agent( dataStore = bisectoidstore.BisectOIDStore( OIDs = oids, ), ), ), ) except twisted_error.CannotListenError: pass else: return agentObject, port
if sys.argv[1] == 'server': # just setup something to serve a response from twistedsnmp import agent, agentprotocol, bisectoidstore from twistedsnmp.pysnmpproto import v2c, v1, error agentObject = reactor.listenUDP( 20161, agentprotocol.AgentProtocol( snmpVersion='v1', agent=agent.Agent( dataStore=bisectoidstore.BisectOIDStore(OIDs=[ ('.1.3.6.1.2.1.1.1.0', 'Hello world!'), ('.1.3.6.1.2.1.1.2.0', 32), ('.1.3.6.1.2.1.1.3.0', v1.IpAddress('127.0.0.1')), ('.1.3.6.1.2.1.1.4.0', v1.OctetString('From Octet String')), ('.1.3.6.1.2.1.2.1.0', 'Hello world!'), ('.1.3.6.1.2.1.2.2.0', 32), ('.1.3.6.1.2.1.2.3.0', v1.IpAddress('127.0.0.1')), ('.1.3.6.1.2.1.2.4.0', v1.OctetString('From Octet String')), ('.1.3.6.2.1.0', 'Hello world!'), ('.1.3.6.2.2.0', 32), ('.1.3.6.2.3.0', v1.IpAddress('127.0.0.1')), ('.1.3.6.2.4.0', v1.OctetString('From Octet String')), ]), ), ), ) print 'Starting listening agent' reactor.run() else: from twistedsnmp import agentproxy, snmpprotocol port = snmpprotocol.port()
self.clients[cli_num]['traffic'] = (bytesin, bytesout) if 'common_name' in self.clients[cli_num]: self.updateoctets(self.clients[cli_num]['common_name'], bytesin, bytesout) class MgmtDataFactory(ReconnectingClientFactory): protocol = MgmtDataCollection def __init__(self, datastore): self.datastore = datastore log.msg( self.datastore ) log.startLogging(sys.stdout) baseoids = { '.1.3.6.1.2.1.1.1.0': 'Openvpn Bandwidth Monitor', '.1.3.6.1.2.1.1.2.0': v2c.ObjectIdentifier('.1.3.6.1.4.1.88.3.1'), '.1.3.6.1.2.1.1.3.0': 0, '.1.3.6.1.2.1.1.4.0': "*****@*****.**", '.1.3.6.1.2.1.1.5.0': "host openvpn", '.1.3.6.1.2.1.1.6.0': "location", OB['IF-MIB::ifNumber']: 0, } datastore = bisectoidstore.BisectOIDStore(OIDs = baseoids,) agentprotocol = agentprotocol.AgentProtocol(snmpVersion = 'v2c', agent = agent.Agent(datastore), ) agentObject = reactor.listenUDP(1161, agentprotocol) reactor.connectTCP(sys.argv[1],int(sys.argv[2]), MgmtDataFactory(datastore)) reactor.run()