Example #1
0
 def testNext(self):
     """Test that getNext properly chains into/out-of sub-storages"""
     store = bisectoidstore.BisectOIDStore([])
     self.failUnlessRaises(
         errors.OIDNameError,
         store.nextOID,
         '.1.3.6.1',
     )
     store.setValue('.1.3.6.1.2.1.1.3', bisectoidstore.BisectOIDStore([]))
     subStorage = store.getExactOID('.1.3.6.1.2.1.1.3')[1]
     self.failUnlessRaises(
         errors.OIDNameError,
         store.nextOID,
         '.1.3.6.1',
     )
     store.setValue(
         '.1.3.6.1.2.1.1.3.4',
         32,
     )
     result = store.nextOID('.1.3.6.1')
     assert result == ('.1.3.6.1.2.1.1.3.4', 32), result
     store.setValue(
         '.1.3.6.1.2.1.1.3.3',
         44,
     )
     result = store.nextOID('.1.3.6.1')
     assert result == ('.1.3.6.1.2.1.1.3.3', 44), result
Example #2
0
 def testFirst(self):
     """Test that firstOID properly chains in/out of sub-storages"""
     store = bisectoidstore.BisectOIDStore([])
     store.setValue('.1.3.6.1.2.1.1.3', bisectoidstore.BisectOIDStore([]))
     self.failUnlessRaises(
         errors.OIDNameError,
         store.firstOID,
     )
     store.setValue(
         '.1.3.6.1.2.1.1.4.0',
         32,
     )
     result = store.firstOID()
     assert result == (
         '.1.3.6.1.2.1.1.4.0',
         32,
     ), result
     store.getExactOID('.1.3.6.1.2.1.1.3')[1].setValue(
         '.1.3.6.1.2.1.1.3.0',
         32,
     )
     result = store.firstOID()
     assert result == (
         '.1.3.6.1.2.1.1.3.0',
         32,
     ), result
Example #3
0
 def testSet(self):
     """Test that setting a value chains into sub-storages"""
     store = bisectoidstore.BisectOIDStore([])
     store.setValue('.1.3.6.1.2.1.1.3', bisectoidstore.BisectOIDStore([]))
     store.setValue(
         '.1.3.6.1.2.1.1.3.4',
         32,
     )
     subStorage = store.getExactOID('.1.3.6.1.2.1.1.3')[1]
     assert len(subStorage.OIDs) == 1, (subStorage.OIDs, store.OIDs)
     store.setValue(
         '.1.3.6.1.2.1.1.4.0',
         32,
     )
     assert len(subStorage.OIDs) == 1, (subStorage.OIDs, store.OIDs)
     assert len(store.OIDs) == 2, store.OIDs
     store.setValue(
         '.1.3.6.1.2.1.1.0.0',
         32,
     )
     assert len(subStorage.OIDs) == 1, (subStorage.OIDs, store.OIDs)
     assert len(store.OIDs) == 3, store.OIDs
     store.setValue('.1.3.6.1.2.1.1.3.5', bisectoidstore.BisectOIDStore([]))
     assert len(subStorage.OIDs) == 2, (subStorage.OIDs, store.OIDs)
     store.setValue(
         '.1.3.6.1.2.1.1.3.5.3',
         32,
     )
     assert len(subStorage.OIDs) == 2, (subStorage.OIDs, store.OIDs)
     subStorage2 = store.getExactOID('.1.3.6.1.2.1.1.3.5')[1]
     assert len(subStorage2.OIDs) == 1, (subStorage2.OIDs, subStorage.OIDs)
Example #4
0
 def testExact(self):
     """Do we get child OIDstore's exact values?"""
     store = bisectoidstore.BisectOIDStore([
         ('.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.4.0', v1.OctetString('From Octet String')),
     ])
     store.setValue(
         '.1.3.6.1.2.1.1.3',
         bisectoidstore.BisectOIDStore([('.1.3.6.1.2.1.1.3.%d' % i, i)
                                        for i in range(32)]))
     result = store.getExactOID('.1.3.6.1.2.1.1.3.5')
     assert result[0] == '.1.3.6.1.2.1.1.3.5', result
     assert result[1] == 5, result
Example #5
0
 def start(self):
     reactor.listenUDP(
         161,
         agentprotocol.AgentProtocol(
             snmpVersion='v2c',
             agent=agent.Agent(dataStore=bisectoidstore.BisectOIDStore(
                 OIDs=self.oids, ), ),
         ),
         interface=self.ip,
     )
Example #6
0
 def testCalculated(self):
     store = bisectoidstore.BisectOIDStore([
         ('.1.3.6.1.2.1.1.1.0', lambda oid, store: 550),
         ('.1.3.6.1.2.12.1.2.0', lambda oid, store: 555),
         ('.1.3.6.1.2.2.1.3.0', v1.IpAddress('127.0.0.1')),
         ('.1.3.6.1.2.1.1.4.0', v1.OctetString('From Octet String')),
     ])
     result = store.getExactOID('.1.3.6.1.2.12.1.2.0')
     assert result[0] == '.1.3.6.1.2.12.1.2.0', result
     assert result[1] == 555, result
     result = store.nextOID('.1.3.6.1.2.2.1.3.0')
     assert result[0] == '.1.3.6.1.2.12.1.2.0', result
     assert result[1] == 555, result
     result = store.firstOID()
     assert result[0] == '.1.3.6.1.2.1.1.1.0', result
     assert result[1] == 550, result
 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.'
Example #8
0
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
Example #9
0
def createStorage( oidsForTesting = [
	(oid.OID(key),value)
	for key,value in [
		('.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.1.2.1.3.%s.0'%i, 32)
		for i in xrange( 512 )
	] + [
		('.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')),
	]
]):
		return bisectoidstore.BisectOIDStore(
			OIDs = oidsForTesting,
		)
Example #10
0
 def createStorage(self, oids):
     return bisectoidstore.BisectOIDStore(OIDs=oids, )
Example #11
0
     # 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()
     proxy = agentproxy.AgentProxy(
Example #12
0
        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()