Beispiel #1
0
 def testFromOther(self):
     """Test creation of a storage from a sequence of storages"""
     stores = [
         self.createStorage([
             ('.1.3.6.1.2.1.1.1.0', 'Hello world!'),
             ('.1.3.6.1.2.12.1.2.0', 32),
             ('.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')),
         ]),
         self.createStorage([
             ('.1.3.6.1.2.1.1.1.0', 'Hello world!'),
             ('.1.4.6.1.2.12.1.2.0', 32),
             ('.1.4.6.1.2.2.1.3.0', v1.IpAddress('127.0.0.1')),
             ('.1.4.6.1.2.1.1.4.0', v1.OctetString('From Octet String')),
         ]),
     ]
     store = self.createStorage(stores)
     r = list(iter(store))
     assert len(r) == 7
Beispiel #2
0
 def testNextBig(self):
     store = self.createStorage([
         ('.1.3.6.1.2.1.1.1.0', 'Hello world!'),
         ('.1.3.6.1.2.12.1.2.0', 32),
         ('.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.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] == 32, result
Beispiel #3
0
 def testIter(self):
     """Test basic iteration"""
     store = self.createStorage([
         ('.1.3.6.1.2.1.1.1.0', 'Hello world!'),
         ('.1.3.6.1.2.12.1.2.0', 32),
         ('.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')),
     ])
     r = list(iter(store))
     assert len(r) == 4
Beispiel #4
0
 def testRetention(self):
     """Test that oids are stored and retrieved properly"""
     store = self.createStorage([
         ('.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')),
     ])
     store.close()
     newStore = bsdoidstore.BSDOIDStore('temp.bsd')
     result = newStore.getExactOID('.1.3.6.1.2.1.1.1.0')
     assert result[0] == '.1.3.6.1.2.1.1.1.0', result
     assert result[1] == 'Hello world!', result
Beispiel #5
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,
		)
Beispiel #6
0
class SetRetrieverV1(basetestcase.BaseTestCase):
    version = 'v1'
    oidsForTesting = [
        ('.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')),
    ]

    def test_setEndOfOIDs(self):
        """After a set, is the set value retrieved?"""
        d = self.client.set([('.1.3.6.1.2.1.1.5.0', 3)], )
        self.doUntilFinish(d)
        d = self.client.get([
            '.1.3.6.1.2.1.1.5.0',
        ], )
        self.doUntilFinish(d)
        assert self.success, self.response
        ##		import pdb
        ##		pdb.set_trace()
        assert self.response == {
            oid.OID('.1.3.6.1.2.1.1.5.0'): 3
        }, self.response

    def test_setReplaceAnOID(self):
        """After a replace-set, is the set value retrieved?"""
        d = self.client.set([('.1.3.6.1.2.1.1.4.0', 3)], )
        self.doUntilFinish(d)
        d = self.client.get([
            '.1.3.6.1.2.1.1.4.0',
        ], )
        self.doUntilFinish(d)
        assert self.success, self.response
        assert self.response == {oid.OID('.1.3.6.1.2.1.1.4.0'): 3}

    def test_socketFailure(self):
        """Test for failure due to sending-time socket failure"""
        import socket

        def mockSend(message):
            raise socket.error(65, 'No route to host')

        self.client.send = mockSend
        d = self.client.set([('.1.3.6.1.2.1.1.4.0', 3)], )
        self.doUntilFinish(d)
        assert not self.success
        assert isinstance(self.response.value, socket.error)
        assert self.response.value.args == (65, 'No route to host')
Beispiel #7
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
Beispiel #8
0
class TrapTestsV1(basetestcase.BaseTestCase):
    version = 'v1'
    oidsForTesting = [
        ('.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')),
    ]

    def test_simpleTrap(self):
        """Is a trap handled by a completely generic trap handler registration?"""
        self.client.listenTrap(callback=self.storeTrap, )
        theAgent = self.agent.protocol.agent
        handler = agent.TrapHandler(
            managerIP=('127.0.0.1', self.client.protocol.transport.port), )
        theAgent.registerTrap(handler)
        theAgent.sendTrap(pdus=[
            ('.1.3.6.1.2.1.1.3.0', None),
        ])
        self.runFor(1)
        # now, should receive it over on the client...
        assert self.trap

    def test_exactTrap(self):
        """Is a trap handled by a completely generic trap handler registration?"""
        self.client.listenTrap(
            genericType=6,
            specificType=8,
            callback=self.storeTrap,
        )
        print self.client.protocol._trapRegistry
        theAgent = self.agent.protocol.agent
        handler = agent.TrapHandler(
            managerIP=('127.0.0.1', self.client.protocol.transport.port),
            genericType=None,
            specificType=None,
        )
        theAgent.registerTrap(handler)
        ##		import pdb
        ##		pdb.set_trace()
        theAgent.sendTrap(genericType=6,
                          specificType=8,
                          pdus=[
                              ('.1.3.6.1.2.1.1.3.0', None),
                          ])
        self.runFor(1)
        # now, should receive it over on the client...
        assert self.trap
        del self.trap
        theAgent.sendTrap(
            # specificType does not match, so should not be processed
            genericType=6,
            specificType=0,
            pdus=[
                ('.1.3.6.1.2.1.1.3.0', None),
            ])
        self.runFor(1)
        assert not getattr(self, 'trap', None)

    def runFor(self, seconds=1):
        df = defer.Deferred()

        def finish():
            df.callback(None)

        reactor.callLater(seconds, finish)
        self.doUntilFinish(df)

    def storeTrap(self, trap, address):
        self.trap = trap
        self.trapAddress = address
        printTrap(trap)
        return trap
Beispiel #9
0
class GetRetrieverV1(basetestcase.BaseTestCase):
    version = 'v1'
    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')),
    ]]

    #good
    def test_simpleGet(self):
        """Can retrieve a single simple value?"""
        d = self.client.get([
            '.1.3.6.1.2.1.1.1.0',
        ])
        self.doUntilFinish(d)

        assert self.success, self.response
        assert isinstance(self.response, dict), self.response
        assert self.response.has_key(
            oid.OID('.1.3.6.1.2.1.1.1.0')), self.response
        assert self.response[oid.OID(
            '.1.3.6.1.2.1.1.1.0')] == 'Hello world!', self.response

    #good
    def test_tableGet(self):
        """Can retrieve a tabular value?"""
        d = self.client.getTable(['.1.3.6.1.2.1.1'])
        self.doUntilFinish(d)

        assert self.success, self.response
        assert isinstance(self.response, dict), self.response
        assert self.response.has_key(
            oid.OID('.1.3.6.1.2.1.1')), (self.response, self)
        tableData = self.response[oid.OID('.1.3.6.1.2.1.1')]
        assert isinstance(tableData, dict)
        assert tableData.has_key(oid.OID('.1.3.6.1.2.1.1.1.0')), tableData

    def test_tableGetWithStart(self):
        """Can retrieve a tabular value?"""
        d = self.client.getTable(
            ['.1.3.6.1.2.1.1'],
            startOIDs=['.1.3.6.1.2.1.1.3.0'],
        )
        self.doUntilFinish(d)

        assert self.success, self.response
        assert isinstance(self.response, dict), self.response
        assert self.response.has_key(
            oid.OID('.1.3.6.1.2.1.1')), (self.response, self)
        tableData = self.response[oid.OID('.1.3.6.1.2.1.1')]
        assert isinstance(tableData, dict)
        # won't have this key because started later...
        assert not tableData.has_key(oid.OID('.1.3.6.1.2.1.1.1.0')), tableData
        # should (only) have this key because started at 3...
        assert tableData.has_key(oid.OID('.1.3.6.1.2.1.1.4.0')), tableData
        assert len(tableData) == 1

    #good
    def test_tableGetMissing(self):
        """Does tabular retrieval ignore non-existent oid-sets?"""
        d = self.client.getTable(['.1.3.6.1.2.1.5'])
        self.doUntilFinish(d)
        assert self.success, self.response
        assert self.response == {}, self.response

    #good
    def test_tableGetAll(self):
        """Does tabular retrieval work specifying a distant parent (e.g. .1.3.6)?"""
        d = self.client.getTable(['.1.3.6'])
        self.doUntilFinish(d)
        assert self.success, self.response
        assert self.response == {
            oid.OID('.1.3.6'): dict(self.oidsForTesting)
        }, self.response

    #bad
    def test_multiTableGet(self):
        oids = [
            '.1.3.6.1.2.1.1',
            '.1.3.6.1.2.1.2',
            '.1.3.6.2',
        ]
        d = self.client.getTable(oids)
        self.doUntilFinish(d)
        if not self.success:
            raise self.response.value
        else:
            for oidObject in oids:
                assert self.response.has_key(oid.OID(oidObject))

    #good
    def test_multiTableGetBad(self):
        oids = [
            '.1.3.6.1.2.1.1',
            '.1.3.6.1.2.1.2',
            '.1.3.6.2',
            '.1.3.6.3',
        ]
        d = self.client.getTable(oids)
        self.doUntilFinish(d)
        for oidObject in oids[:-1]:
            assert self.response.has_key(oid.OID(oidObject))
        assert not self.response.has_key(oid.OID(oids[-1])), self.response

    #good
    def test_tableGetErrorReported(self):
        oids = [
            '.1.3.6.1.2.1.1',
            '.1.3.6.1.2.1.2',
            '.1.3.6.2',
            '.1.3.6.3',
        ]
        originalAreWeDone = tableretriever.TableRetriever.areWeDone

        def raiseError(*args, **named):
            raise TypeError("""Blah""")

        tableretriever.TableRetriever.areWeDone = raiseError
        try:
            d = self.client.getTable(oids)
            self.doUntilFinish(d)
        finally:
            tableretriever.TableRetriever.areWeDone = originalAreWeDone
        assert not self.success
        assert isinstance(self.response.value, TypeError)
        assert self.response.value.args == ('Blah', )

    #good
    def test_socketFailure(self):
        """Test whether socket failure on send is caught properly

		Previous versions have not caught failure-on-send conditions,
		which can wind up having unexpected consequences, particularly
		with things such as mass-retriever, which build on top of the
		basic AgentProxy.
		"""
        import socket

        def mockSend(message):
            raise socket.error(65, 'No route to host')

        self.client.send = mockSend
        d = self.client.get([
            '.1.3.6.1.2.1.1.1.0',
        ])
        self.doUntilFinish(d)
        assert not self.success
        assert isinstance(self.response.value, socket.error)
        assert self.response.value.args == (65, 'No route to host')

    #good
    def test_socketFailureTable(self):
        """Test whether socket failure on send is caught properly for tables

		Previous versions have not caught failure-on-send conditions,
		which can wind up having unexpected consequences, particularly
		with things such as mass-retriever, which build on top of the
		basic AgentProxy.
		"""
        self.client.send = socketErrorSend
        d = self.client.getTable([
            '.1.3.6.1.2.1.1.1.0',
        ], retryCount=2)
        self.doUntilFinish(d)
        assert not self.success
        assert isinstance(self.response.value, socket.error)
        assert self.response.value.args == (65, 'No route to host')
Beispiel #10
0
class MassRetrieverTest(basetestcase.BaseTestCase):
    """Test for mass retrieval of values"""
    version = 'v2'
    oidsForTesting = [
        ('.1.3.6.1.1.3', 'Blah!'),
        ('.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')),
    ]

    def testMassRetriever(self):
        """Can we retrieve mass value single-oid values?"""
        proxies = massretriever.proxies(
            self.client.protocol,
            [('127.0.0.1', self.agent.port, 'public', self.version)] * 250)
        retriever = massretriever.MassRetriever(proxies)
        retriever.verbose = 1
        d = retriever(oids=[
            '.1.3.6.1.1.3',
        ])
        self.doUntilFinish(d)
        assert self.success, self.response
        assert self.response == {
            ('127.0.0.1', self.agent.port): {
                oid.OID('.1.3.6.1.1.3'): 'Blah!'
            }
        }, self.response
        retriever.printStats()

    def testMassRetrieverTables(self):
        """Can we retrieve mass value tabular sets?"""
        import random
        GOOD_COUNT = 500
        BAD_COUNT = 500
        proxies = massretriever.proxies(
            self.client.protocol,
            [('127.0.0.1', self.agent.port, 'public', self.version)] *
            GOOD_COUNT +
            [('127.0.0.1', self.agent.port + 10000, 'public', self.version)] *
            BAD_COUNT)
        random.shuffle(proxies)
        random.shuffle(proxies)
        random.shuffle(proxies)
        retriever = massretriever.MassRetriever(proxies)
        retriever.verbose = 1
        d = retriever(tables=[
            '.1.3.6.1.2.1',
        ])
        self.doUntilFinish(d)
        assert self.success, self.response
        expected = {
            ('127.0.0.1', self.agent.port): {
                oid.OID('.1.3.6.1.2.1'): {
                    oid.OID('.1.3.6.1.2.1.1.1.0'): 'Hello world!',
                    oid.OID('.1.3.6.1.2.1.1.2.0'): 32,
                    oid.OID('.1.3.6.1.2.1.1.3.0'): '127.0.0.1',
                    oid.OID('.1.3.6.1.2.1.1.4.0'): 'From Octet String',
                }
            },
            ('127.0.0.1', self.agent.port + 10000): {
                oid.OID('.1.3.6.1.2.1'): None,
            },
        }
        assert self.response == expected, (expected, self.response)
        retriever.printStats()
        assert retriever.successCount == GOOD_COUNT, """Expected %s valid responses, got %s""" % (
            GOOD_COUNT, retriever.successCount)
        assert retriever.errorCount == BAD_COUNT, """Expected %s valid responses, got %s""" % (
            GOOD_COUNT, retriever.successCount)
Beispiel #11
0
 def getValue(self, oid, storage):
     oidstring = bisectoidstore.sortableToOID(oid)
     strOID = str(oidstring)
     if oidstring == self.SYSTEMDESCRIPTION_OID:
         return v1.OctetString(
             str(config.plugins.SnmpAgent.systemdescription.value))
     elif oidstring == self.SYSUPTIME_OID:
         return self.getSysUpTime()
     elif oidstring == self.CPU_USER:
         return v1.Counter(GetCPUStatForType(CPUStatTypes.user))
     elif oidstring == self.CPU_NICE:
         return v1.Counter(GetCPUStatForType(CPUStatTypes.nice))
     elif oidstring == self.CPU_SYSTEM:
         return v1.Counter(GetCPUStatForType(CPUStatTypes.system))
     elif oidstring == self.CPU_IDLE:
         return v1.Counter(GetCPUStatForType(CPUStatTypes.idle))
     elif oidstring == self.CPU_WAIT:
         return v1.Counter(GetCPUStatForType(CPUStatTypes.iowait))
     elif oidstring == self.LOAD_AVR1:
         return v1.OctetString(GetCPULoadForType(CPULoadTypes.one))
     elif oidstring == self.LOAD_AVR5:
         return v1.OctetString(GetCPULoadForType(CPULoadTypes.five))
     elif oidstring == self.LOAD_AVR15:
         return v1.OctetString(GetCPULoadForType(CPULoadTypes.fifteen))
     elif oidstring == self.MEM_TOTAL:
         return v1.Integer(GetMemoryForType(MemoryTypes.total))
     elif oidstring == self.MEM_TOTAL2:
         return v1.Integer(GetMemoryForType(MemoryTypes.total))
     elif oidstring == self.MEM_USED:
         return v1.Integer(GetMemoryForType(MemoryTypes.used))
     elif oidstring == self.MEM_FREE:
         return v1.Integer(GetMemoryForType(MemoryTypes.free))
     elif oidstring == self.MEM_BUFFER:
         return v1.Integer(GetMemoryForType(MemoryTypes.buffers))
     elif oidstring == self.MEM_CACHED:
         return v1.Integer(GetMemoryForType(MemoryTypes.cached))
     elif oidstring == self.MEM_SWAPTOTAL:
         return v1.Integer(GetMemoryForType(MemoryTypes.swaptotal))
     elif oidstring == self.MEM_SWAPFREE:
         return v1.Integer(GetMemoryForType(MemoryTypes.swapfree))
     elif strOID.startswith(str(self.DISK_INDEX)):
         return v1.Integer(int(strOID[len(str(self.DISK_INDEX)) + 1:]))
     elif strOID.startswith(str(self.DISK_PATHNAME)):
         return v1.OctetString(
             GetDiskInfo(DiskInfoTypes.mountpoint,
                         int(strOID[len(str(self.DISK_PATHNAME)) + 1:]) -
                         1))
     elif strOID.startswith(str(self.DISK_DEVICENAME)):
         return v1.OctetString(
             GetDiskInfo(
                 DiskInfoTypes.filesystem,
                 int(strOID[len(str(self.DISK_DEVICENAME)) + 1:]) - 1))
     elif strOID.startswith(str(self.DISK_AVAIL)):
         return v1.Integer(
             GetDiskInfo(DiskInfoTypes.avail,
                         int(strOID[len(str(self.DISK_AVAIL)) + 1:]) - 1))
     elif strOID.startswith(str(self.DISK_USED)):
         return v1.Integer(
             GetDiskInfo(DiskInfoTypes.used,
                         int(strOID[len(str(self.DISK_USED)) + 1:]) - 1))
     elif oidstring == self.IF_NUMBER:
         return v1.Integer(GetNetworkInfo(NetworkInfoTypes.total, 0))
     elif strOID.startswith(str(self.IP_ADENTIFINDEX)):
         return v1.Integer(self.ip_adentifindex_ref[strOID])
     elif strOID.startswith(str(self.IF_IPADENTADDR)):
         return v1.IpAddress(self.ip_adentaddr_ref[strOID])
     elif strOID.startswith(str(self.IF_INOCTANTS)):
         return v1.Counter(
             GetNetworkInfo(
                 NetworkInfoTypes.inoctants,
                 int(strOID[len(str(self.IF_INOCTANTS)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_INDISCARD)):
         return v1.Counter(
             GetNetworkInfo(
                 NetworkInfoTypes.indiscard,
                 int(strOID[len(str(self.IF_INDISCARD)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_INERRORS)):
         return v1.Counter(
             GetNetworkInfo(
                 NetworkInfoTypes.inerrors,
                 int(strOID[len(str(self.IF_INERRORS)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_OUTOCTANTS)):
         return v1.Counter(
             GetNetworkInfo(
                 NetworkInfoTypes.outoctacts,
                 int(strOID[len(str(self.IF_OUTOCTANTS)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_OUTDISCARD)):
         return v1.Counter(
             GetNetworkInfo(
                 NetworkInfoTypes.outdiscard,
                 int(strOID[len(str(self.IF_OUTDISCARD)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_OUTERRORS)):
         return v1.Counter(
             GetNetworkInfo(
                 NetworkInfoTypes.outerrors,
                 int(strOID[len(str(self.IF_OUTERRORS)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_ALIAS)):
         return v1.OctetString(
             GetNetworkInfo(NetworkInfoTypes.alias,
                            int(strOID[len(str(self.IF_ALIAS)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_HSPEED)):
         return v1.Gauge(
             GetNetworkInfo(NetworkInfoTypes.hspeed,
                            int(strOID[len(str(self.IF_HSPEED)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_INDEX)):
         return v1.Integer(int(strOID[len(str(self.IF_INDEX)) + 1:]))
     elif strOID.startswith(str(self.IF_DESC)):
         return v1.OctetString(
             GetNetworkInfo(NetworkInfoTypes.desc,
                            int(strOID[len(str(self.IF_DESC)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_NAME)):
         return v1.OctetString(
             GetNetworkInfo(NetworkInfoTypes.desc,
                            int(strOID[len(str(self.IF_NAME)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_TYPE)):
         return v1.Integer(
             GetNetworkInfo(NetworkInfoTypes.type,
                            int(strOID[len(str(self.IF_TYPE)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_MTU)):
         return v1.Integer(
             GetNetworkInfo(NetworkInfoTypes.mtu,
                            int(strOID[len(str(self.IF_MTU)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_SPEED)):
         return v1.Gauge(
             GetNetworkInfo(NetworkInfoTypes.speed,
                            int(strOID[len(str(self.IF_SPEED)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_HWADDR)):
         return v1.OctetString(
             GetNetworkInfo(NetworkInfoTypes.hwaddr,
                            int(strOID[len(str(self.IF_HWADDR)) + 1:]) - 1))
     elif strOID.startswith(str(self.IF_STATUS)):
         return v1.Integer(
             GetNetworkInfo(NetworkInfoTypes.status,
                            int(strOID[len(str(self.IF_STATUS)) + 1:]) - 1))
     elif oidstring == self.SUPPORTADDRESS_OID:
         return v1.OctetString(
             str(config.plugins.SnmpAgent.supportaddress.value))
     elif oidstring == self.SYSTEMNAME_OID:
         return v1.OctetString(
             str(config.plugins.SnmpAgent.systemname.value))
     elif oidstring == self.LOCATION_OID:
         return v1.OctetString(str(config.plugins.SnmpAgent.location.value))
     elif oidstring == self.BER_OID:
         return self.getBER()
     elif oidstring == self.AGC_OID:
         return self.getAGC()
     elif oidstring == self.SNR_OID:
         return self.getSNR()
     elif oidstring == self.SNRDB_OID:
         return self.getSNRDB()
     elif oidstring == self.LOCK_OID:
         return self.getLock()
     elif oidstring == self.HASPICTURE_OID:
         return self.haspicture
     elif oidstring == self.VIDEO_BITRATE_OID:
         if self.bitrate:
             return self.bitrate.vcur
         else:
             return 0
     elif oidstring == self.AUDIO_BITRATE_OID:
         if self.bitrate:
             return self.bitrate.acur
         else:
             return 0
     elif oidstring == self.CHANNELNAME_OID:
         return v1.OctetString(self.getChannelName())
     elif oidstring == self.SERVICESTRING_OID:
         return v1.OctetString(self.getServiceString())
     elif oidstring == self.FASTSCANSTRING_OID:
         return v1.OctetString('')
     elif oidstring == self.SERVICEPARAMS_OID:
         return v1.OctetString(self.getServiceParams())
     elif oidstring == self.TUNERTYPE_OID:
         return self.getTunerType()
     elif oidstring == self.MANAGERIP_OID:
         return v1.OctetString(str(
             config.plugins.SnmpAgent.managerip.value))
     elif oidstring == self.ENABLE_BITRATE_OID:
         return config.plugins.SnmpAgent.measurebitrate.value
     elif oidstring == self.IP_OID:
         value = "%d.%d.%d.%d" % tuple(
             iNetwork.getAdapterAttribute(self.iface, "ip"))
         return v1.IpAddress(value)
     elif oidstring == self.NETMASK_OID:
         value = "%d.%d.%d.%d" % tuple(
             iNetwork.getAdapterAttribute(self.iface, "netmask"))
         return v1.IpAddress(value)
     elif oidstring == self.GATEWAY_OID:
         value = "%d.%d.%d.%d" % tuple(
             iNetwork.getAdapterAttribute(self.iface, "gateway"))
         return v1.IpAddress(value)
     elif oidstring == self.ENABLE_EMM_OID:
         return config.plugins.SnmpAgent.checkemm.value
     elif oidstring == self.EMM_OID:
         if self.emm:
             return v1.OctetString(self.emm.pids)
         else:
             return v1.OctetString('')
Beispiel #12
0
from the command line."""
        sys.exit(1)

    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'
Beispiel #13
0
 def getValue(self, oid, storage):
     oidstring = bisectoidstore.sortableToOID(oid)
     if oidstring == self.SYSTEMDESCRIPTION_OID:
         return v1.OctetString(
             str(config.plugins.SnmpAgent.systemdescription.value))
     elif oidstring == self.SYSUPTIME_OID:
         return self.getSysUpTime()
     elif oidstring == self.SUPPORTADDRESS_OID:
         return v1.OctetString(
             str(config.plugins.SnmpAgent.supportaddress.value))
     elif oidstring == self.SYSTEMNAME_OID:
         return v1.OctetString(
             str(config.plugins.SnmpAgent.systemname.value))
     elif oidstring == self.LOCATION_OID:
         return v1.OctetString(str(config.plugins.SnmpAgent.location.value))
     elif oidstring == self.BER_OID:
         return self.getBER()
     elif oidstring == self.AGC_OID:
         return self.getACG()
     elif oidstring == self.SNR_OID:
         return self.getSNR()
     elif oidstring == self.HASPICTURE_OID:
         return self.haspicture
     elif oidstring == self.VIDEO_BITRATE_OID:
         if self.bitrate:
             return self.bitrate.vcur
         else:
             return 0
     elif oidstring == self.AUDIO_BITRATE_OID:
         if self.bitrate:
             return self.bitrate.acur
         else:
             return 0
     elif oidstring == self.CHANNELNAME_OID:
         return v1.OctetString(self.getChannelName())
     elif oidstring == self.SERVICESTRING_OID:
         return v1.OctetString(self.getServiceString())
     elif oidstring == self.FASTSCANSTRING_OID:
         return v1.OctetString('')
     elif oidstring == self.SERVICEPARAMS_OID:
         return v1.OctetString(self.getServiceParams())
     elif oidstring == self.MANAGERIP_OID:
         return v1.OctetString(str(
             config.plugins.SnmpAgent.managerip.value))
     elif oidstring == self.ENABLE_BITRATE_OID:
         return config.plugins.SnmpAgent.measurebitrate.value
     elif oidstring == self.IP_OID:
         value = "%d.%d.%d.%d" % tuple(
             iNetwork.getAdapterAttribute(self.iface, "ip"))
         return v1.IpAddress(value)
     elif oidstring == self.NETMASK_OID:
         value = "%d.%d.%d.%d" % tuple(
             iNetwork.getAdapterAttribute(self.iface, "netmask"))
         return v1.IpAddress(value)
     elif oidstring == self.GATEWAY_OID:
         value = "%d.%d.%d.%d" % tuple(
             iNetwork.getAdapterAttribute(self.iface, "gateway"))
         return v1.IpAddress(value)
     elif oidstring == self.ENABLE_EMM_OID:
         return config.plugins.SnmpAgent.checkemm.value
     elif oidstring == self.EMM_OID:
         if self.emm:
             return v1.OctetString(self.emm.pids)
         else:
             return v1.OctetString('')