コード例 #1
0
def test():
	port = reactor.listenUDP(20000, SNMPProtocol() )
	proxy = agentproxy.AgentProxy(
		"205.207.149.252", 161, protocol = port.protocol,
	)
	def onSuccess( value ):
		print 'Success:'
		if isinstance( value, dict ):
			value = value.items()
		for key,item in value:
			print key, len(item)
	def onFailure( reason ):
		print 'Failure:', reason
	d = proxy.get( ['.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0', '.1.3.6.1.2.1.1.6.0'] )
	d.addCallbacks( onSuccess, onFailure )

	d = proxy.getTable( [ '.1.3.6.1.4.1.1456.2.2.6.1.3' ] )
	d.addCallbacks( onSuccess, onFailure )

	proxy2 = agentproxy.AgentProxy(
		"205.207.149.252",
		community = 'public',
		snmpVersion = 'v2',
		protocol = port.protocol,
	)
	d = proxy2.getTable( [
		'.1.3.6.1.4.1.1456.2.2.6.1.2',
		'.1.3.6.1.4.1.1456.2.3.2.1.18',
	] )
	d.addCallbacks( onSuccess, onFailure )
コード例 #2
0
def proxies(protocol, addresses, proxyClass=agentproxy.AgentProxy):
    """Given protocol and set of addresses, construct AgentProxies

	protocol -- SNMPProtocol instance
	addresses -- tuples of (ip,port,[community,[version]]) to be
		passed to the AgentProxy constructor.
	proxyClass -- the proxy class to use for the retrieval
	"""
    return [
        agentproxy.AgentProxy(protocol=protocol, *args) for args in addresses
    ]
コード例 #3
0
ファイル: bgpflow.py プロジェクト: Cloudxtreme/bgpflow
    def update_ifs(self):
        proxy = agentproxy.AgentProxy(
            self.host,
            161,
            community='secret',
            snmpVersion='v2',
            protocol=self.snmp_protocol.protocol,
        )
        df = proxy.getTable(['.1.3.6.1.2.1.31.1.1.1.18'],
                            timeout=5,
                            retryCount=3)
        df.addCallback(self.snmp_ok)
        df.addErrback(self.snmp_fail)

        reactor.callLater(300, self.update_ifs)

        return df
コード例 #4
0
ipAddress -- dotted IP address of the agent
port -- numeric port number of the agent
community -- community string for the agent
baseoid -- dotted set of OIDs to retrieve from agent
"""
    if len(sys.argv) < 4:
        print usage
        sys.exit(1)
    ipAddress = sys.argv[1]
    # choose random port in range 25000 to 30000
    port = snmpprotocol.port()
    targetPort = int(sys.argv[2])
    proxy = agentproxy.AgentProxy(
        ipAddress,
        targetPort,
        community=sys.argv[3],
        snmpVersion='v2',
        protocol=port.protocol,
    )
    if not sys.argv[4:]:
        oids = [
            '.1.3.6.1.2.1.1.1.0',
            'New Description',
            '.1.3.6.1.2.1.1.4.0',
            '*****@*****.**',
        ]
    else:
        oids = sys.argv[4:]
    reactor.callWhenRunning(main, proxy, oids)
    reactor.run()
コード例 #5
0
                        ('.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(
            ip='127.0.0.1',
            community='public',
            protocol=port.protocol,
            port=20161,
        )
        proxy.verbose = 1
        print synchronous(0, proxy.getTable, ('.1.3.6.1.2.1.1', ))
コード例 #6
0
##	oidStore.btree.sync()

if __name__ == "__main__":
    # need to get the ip address
    usage = """Usage:
	mirroragent ipAddress community filename baseoid...

ipAddress -- dotted IP address of the agent
community -- community string for the agent
filename -- filename to use for storing the results
baseoid -- dotted set of OIDs to retrieve from agent
"""
    import sys
    if len(sys.argv) < 4:
        print usage
        sys.exit(1)
    ipAddress = sys.argv[1]
    port = reactor.listenUDP(
        20000,
        snmpprotocol.SNMPProtocol(),
    )
    client = agentproxy.AgentProxy(
        ipAddress,
        161,
        community=sys.argv[2],
        snmpVersion='v2',
        protocol=port.protocol,
    )
    reactor.callLater(1, main, client, sys.argv[3], sys.argv[4:])
    reactor.run()