summaryrefslogtreecommitdiff
path: root/examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py
diff options
context:
space:
mode:
authorelie <elie>2013-03-16 17:05:46 +0000
committerelie <elie>2013-03-16 17:05:46 +0000
commitc4ada8eada8b4ea59a4bbb7d9c6123199d51917a (patch)
tree536f717c2f9a628c06684bb713b556705ff4671e /examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py
parent19698bc00888b4cc59e0cec603a752c2e95fe849 (diff)
downloadpysnmp-c4ada8eada8b4ea59a4bbb7d9c6123199d51917a.tar.gz
a dozen of lightweight Twisted-based example scripts replaced more
complex example implementations used previously.
Diffstat (limited to 'examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py')
-rw-r--r--examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py b/examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py
new file mode 100644
index 0000000..38f058f
--- /dev/null
+++ b/examples/v3arch/twisted/agent/cmdrsp/v3-multiple-users.py
@@ -0,0 +1,77 @@
+#
+# Command Responder
+#
+# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with
+# the following options:
+#
+# * SNMPv3
+# * with USM user 'usr-md5-des', auth: MD5, priv DES or
+# with USM user 'usr-sha-none', auth: SHA, no privacy
+# with USM user 'usr-sha-aes128', auth: SHA, priv AES
+# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1)
+# * over IPv4/UDP, listening at 127.0.0.1:161
+#
+# Either of the following Net-SNMP's commands will walk this Agent:
+#
+# $ snmpwalk -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 localhost .1.3.6
+# $ snmpwalk -v3 -u usr-sha-none -l authNoPriv -a SHA -A authkey1 localhost .1.3.6
+# $ snmpwalk -v3 -u usr-sha-aes128 -l authPriv -a SHA -A authkey1 -x AES -X privkey1 localhost .1.3.6
+#
+from twisted.internet import reactor
+from pysnmp.entity import engine, config
+from pysnmp.entity.rfc3413 import cmdrsp, context
+from pysnmp.carrier.twisted.dgram import udp
+from pysnmp.carrier.twisted import dispatch
+
+# Create SNMP engine with autogenernated engineID and pre-bound
+# to socket transport dispatcher
+snmpEngine = engine.SnmpEngine()
+
+# Transport setup
+
+# Instantiate and register Twisted dispatcher at SNMP engine
+snmpEngine.registerTransportDispatcher(dispatch.TwistedDispatcher())
+
+# UDP over IPv4
+config.addSocketTransport(
+ snmpEngine,
+ udp.domainName,
+ udp.UdpTwistedTransport().openServerMode(('127.0.0.1', 161))
+)
+
+# SNMPv3/USM setup
+
+# user: usr-md5-des, auth: MD5, priv DES
+config.addV3User(
+ snmpEngine, 'usr-md5-des',
+ config.usmHMACMD5AuthProtocol, 'authkey1',
+ config.usmDESPrivProtocol, 'privkey1'
+)
+# user: usr-sha-none, auth: SHA, priv NONE
+config.addV3User(
+ snmpEngine, 'usr-sha-none',
+ config.usmHMACSHAAuthProtocol, 'authkey1'
+)
+# user: usr-sha-none, auth: SHA, priv AES
+config.addV3User(
+ snmpEngine, 'usr-sha-aes128',
+ config.usmHMACSHAAuthProtocol, 'authkey1',
+ config.usmAesCfb128Protocol, 'privkey1'
+)
+
+# Allow full MIB access for each user at VACM
+config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
+config.addVacmUser(snmpEngine, 3, 'usr-sha-none', 'authNoPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
+config.addVacmUser(snmpEngine, 3, 'usr-sha-aes128', 'authPriv', (1,3,6,1,2,1), (1,3,6,1,2,1))
+
+# Get default SNMP context this SNMP engine serves
+snmpContext = context.SnmpContext(snmpEngine)
+
+# Register SNMP Applications at the SNMP engine for particular SNMP context
+cmdrsp.GetCommandResponder(snmpEngine, snmpContext)
+cmdrsp.SetCommandResponder(snmpEngine, snmpContext)
+cmdrsp.NextCommandResponder(snmpEngine, snmpContext)
+cmdrsp.BulkCommandResponder(snmpEngine, snmpContext)
+
+# Run Twisted main loop
+reactor.run()