diff options
author | elie <elie> | 2015-09-14 05:20:24 +0000 |
---|---|---|
committer | elie <elie> | 2015-09-14 05:20:24 +0000 |
commit | ddc989155d58641cf32e6a1ef8a400f22f5d167c (patch) | |
tree | 9df696918f07781d60cca7a8cc3ff8a6378b638f /examples | |
parent | 6596cb464810233b3b16973665f2a4fe27ddd1db (diff) | |
download | pysnmp-git-ddc989155d58641cf32e6a1ef8a400f22f5d167c.tar.gz |
* synchronous oneliner apps redesigned to offer Python generator-based
API along with a more comprehensive set of accepted parameters.
* massively documented (in Sphinx, NumPy style)
Diffstat (limited to 'examples')
110 files changed, 3161 insertions, 2358 deletions
diff --git a/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py b/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py index fc4a3582..cfa2acdc 100644 --- a/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py +++ b/examples/hlapi/asyncore/agent/ntforg/multiple-informs-at-once.py @@ -1,30 +1,31 @@ -# -# Notification Originator -# -# Send multiple SNMP notifications using the following options: -# -# * SNMPv2c and SNMPv3 -# * with community name 'public' or USM username usr-md5-des -# * over IPv4/UDP -# * send INFORM notification -# * to multiple Managers -# * with TRAP ID 'coldStart' specified as a MIB symbol -# * include managed object information specified as var-bind objects pair -# -from pysnmp.entity.rfc3413.oneliner import ntforg -from pysnmp.entity import engine +""" +Multiple concurrent notifications ++++++++++++++++++++++++++++++++++ + +Send multiple SNMP notifications at once using the following options: + +* SNMPv2c and SNMPv3 +* with community name 'public' or USM username usr-md5-des +* over IPv4/UDP +* send INFORM notification +* to multiple Managers +* with TRAP ID 'coldStart' specified as a MIB symbol +* include managed object information specified as var-bind objects pair + +"""# +from pysnmp.entity.rfc3413.oneliner.ntforg import * # List of targets in the followin format: # ( ( authData, transportTarget ), ... ) targets = ( # 1-st target (SNMPv2c over IPv4/UDP) - ( ntforg.CommunityData('public'), - ntforg.UdpTransportTarget(('localhost', 162)), - ntforg.ContextData() ), + ( CommunityData('public'), + UdpTransportTarget(('localhost', 162)), + ContextData() ), # 2-nd target (SNMPv3 over IPv4/UDP) - ( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - ntforg.UdpTransportTarget(('localhost', 162)), - ntforg.ContextData() ), + ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('localhost', 162)), + ContextData() ), ) def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -41,7 +42,7 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, snmpEngine = engine.SnmpEngine() -ntfOrg = ntforg.AsyncNotificationOriginator() +ntfOrg = AsyncNotificationOriginator() for authData, transportTarget, contextData in targets: sendPduHandle = ntfOrg.sendNotification( @@ -50,8 +51,8 @@ for authData, transportTarget, contextData in targets: transportTarget, contextData, 'inform', # NotifyType - ntforg.NotificationType( - ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'coldStart') ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ), cbInfo=(cbFun, None) ) diff --git a/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py b/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py index c9e955e9..60c557a4 100644 --- a/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py +++ b/examples/hlapi/asyncore/agent/ntforg/multiple-traps-at-once.py @@ -1,36 +1,37 @@ -# -# Notification Originator -# -# Send multiple SNMP notifications using the following options: -# -# * SNMPv1 and SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * to multiple Managers -# * with TRAP ID 'coldStart' specified as a MIB symbol -# * include managed object information specified as var-bind objects pair -# -from pysnmp.entity.rfc3413.oneliner import ntforg -from pysnmp.entity import engine -from pysnmp.proto import rfc1902 +""" +Multiple concurrent queries ++++++++++++++++++++++++++++ + +Send a bunch of different SNMP Notifications to different peers all at once, +wait for responses asynchronously: + +* SNMPv1 and SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* to multiple Managers +* with TRAP ID 'coldStart' specified as a MIB symbol +* include managed object information specified as var-bind objects pair + +"""# +from pysnmp.entity.rfc3413.oneliner.ntforg import * # List of targets in the followin format: # ( ( authData, transportTarget ), ... ) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) - ( ntforg.CommunityData('public', mpModel=0), - ntforg.UdpTransportTarget(('localhost', 162)), - ntforg.ContextData() ), + ( CommunityData('public', mpModel=0), + UdpTransportTarget(('localhost', 162)), + ContextData() ), # 2-nd target (SNMPv2c over IPv4/UDP) - ( ntforg.CommunityData('public'), - ntforg.UdpTransportTarget(('localhost', 162)), - ntforg.ContextData() ), + ( CommunityData('public'), + UdpTransportTarget(('localhost', 162)), + ContextData() ), ) -snmpEngine = engine.SnmpEngine() +snmpEngine = SnmpEngine() -ntfOrg = ntforg.AsyncNotificationOriginator() +ntfOrg = AsyncNotificationOriginator() for authData, transportTarget, contextData in targets: ntfOrg.sendNotification( @@ -39,11 +40,11 @@ for authData, transportTarget, contextData in targets: transportTarget, contextData, 'trap', # NotifyType - ntforg.NotificationType( - ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'coldStart') ).addVarBinds( - ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'), - rfc1902.OctetString('my name') ) + ( ObjectName('1.3.6.1.2.1.1.1.0'), + OctetString('my name') ) ) ) diff --git a/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py b/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py index fcceaf0d..aa96c1e8 100644 --- a/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py +++ b/examples/hlapi/asyncore/agent/ntforg/running-multiple-snmp-engines-at-once.py @@ -1,44 +1,45 @@ -# -# Notification Originator -# -# Send SNMP notifications in behalf of multiple independend SNMP engines -# using the following options: -# -# * with a single transport dispatcher and two independent SNMP engines -# * SNMPv2c and SNMPv3 -# * with community name 'public' or USM username usr-md5-des -# * over IPv4/UDP -# * send IMFORM notification -# * to multiple Managers -# * with TRAP ID 'coldStart' specified as a MIB symbol -# * include managed object information specified as var-bind objects pair -# -# Within this script we have a single asynchronous TransportDispatcher -# and a single UDP-based transport serving two independent SNMP engines. -# We use a single instance of AsyncNotificationOriginator with each of -# SNMP Engines to communicate INFORM notification to remote systems. -# -# When we receive a [response] message from remote system we use -# a custom message router to choose what of the two SNMP engines -# data packet should be handed over. The selection criteria we -# employ here is based on peer's UDP port number. Other selection -# criterias are also possible. -# -from pysnmp.entity.rfc3413.oneliner import ntforg -from pysnmp.entity import engine +""" +Multiple SNMP Engines ++++++++++++++++++++++ + +Send SNMP notifications in behalf of multiple independend SNMP engines +using the following options: + +* with a single transport dispatcher and two independent SNMP engines +* SNMPv2c and SNMPv3 +* with community name 'public' or USM username usr-md5-des +* over IPv4/UDP +* send IMFORM notification +* to multiple Managers +* with TRAP ID 'coldStart' specified as a MIB symbol +* include managed object information specified as var-bind objects pair + +Within this script we have a single asynchronous TransportDispatcher +and a single UDP-based transport serving two independent SNMP engines. +We use a single instance of AsyncNotificationOriginator with each of +SNMP Engines to communicate INFORM notification to remote systems. + +When we receive a [response] message from remote system we use +a custom message router to choose what of the two SNMP engines +data packet should be handed over. The selection criteria we +employ here is based on peer's UDP port number. Other selection +criterias are also possible. + +"""# +from pysnmp.entity.rfc3413.oneliner.ntforg import * from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher # List of targets in the following format: # ( ( authData, transportTarget ), ... ) targets = ( # 1-st target (SNMPv2c over IPv4/UDP) - ( ntforg.CommunityData('public'), - ntforg.UdpTransportTarget(('localhost', 1162)), - ntforg.ContextData() ), + ( CommunityData('public'), + UdpTransportTarget(('localhost', 1162)), + ContextData() ), # 2-nd target (SNMPv3 over IPv4/UDP) - ( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - ntforg.UdpTransportTarget(('localhost', 162)), - ntforg.ContextData() ), + ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('localhost', 162)), + ContextData() ), ) def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -67,7 +68,7 @@ snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A') snmpEngineB = engine.SnmpEngine() snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B') -ntfOrg = ntforg.AsyncNotificationOriginator() +ntfOrg = AsyncNotificationOriginator() for authData, transportTarget, contextData in targets: snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \ @@ -78,8 +79,8 @@ for authData, transportTarget, contextData in targets: transportTarget, contextData, 'inform', # NotifyType - ntforg.NotificationType( - ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'coldStart') ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ), cbInfo=(cbFun, snmpEngine) ) diff --git a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py index e50a54b4..f5c05690 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py +++ b/examples/hlapi/asyncore/manager/cmdgen/multiple-concurrent-queries.py @@ -1,50 +1,52 @@ -# -# Asynchronous Command Generator -# -# Send a bunch of SNMP GET requests all at once using the following options: -# -# * with SNMPv1, community 'public' and -# with SNMPv2c, community 'public' and -# with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy -# * over IPv4/UDP and -# over IPv6/UDP -# * to an Agent at demo.snmplabs.com:161 and -# to an Agent at [::1]:161 -# * for instances of SNMPv2-MIB::sysDescr.0 and -# SNMPv2-MIB::sysLocation.0 MIB objects -# -from pysnmp.entity import engine -from pysnmp.entity.rfc3413.oneliner import cmdgen +""" +Multiple concurrent queries ++++++++++++++++++++++++++++ + +Send a bunch of different SNMP GET requests to different peers all at once, +wait for responses asynchronously: + +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and + with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at [::1]:161 +* for instances of SNMPv2-MIB::sysDescr.0 and + SNMPv2-MIB::sysLocation.0 MIB objects + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * # List of targets in the followin format: # ( ( authData, transportTarget, varNames ), ... ) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) - ( cmdgen.CommunityData('public', mpModel=0), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), + ( CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), # 2-nd target (SNMPv2c over IPv4/UDP) - ( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), + ( CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), # 3-nd target (SNMPv2c over IPv4/UDP) - same community and # different transport address. - ( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('localhost', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysName', 0))) ), + ( CommunityData('public'), + UdpTransportTarget(('localhost', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0))) ), # 4-nd target (SNMPv3 over IPv4/UDP) - ( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), + ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), # 5-th target (SNMPv3 over IPv6/UDP) - ( cmdgen.UsmUserData('usr-md5-none', 'authkey1'), - cmdgen.Udp6TransportTarget(('::1', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), + ( UsmUserData('usr-md5-none', 'authkey1'), + Udp6TransportTarget(('::1', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), # N-th target # ... ) @@ -52,36 +54,32 @@ targets = ( # Wait for responses or errors def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): - (authData, transportTarget) = cbCtx + authData, transportTarget = cbCtx print('%s via %s' % (authData, transportTarget)) if errorIndication: print(errorIndication) - return 1 - if errorStatus: + return True + elif errorStatus: print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) ) - return 1 - - for oid, val in varBinds: - if val is None: - print(oid.prettyPrint()) - else: - print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + return True + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) -snmpEngine = engine.SnmpEngine() +snmpEngine = SnmpEngine() -cmdGen = cmdgen.AsyncCommandGenerator() +cmdGen = AsyncCommandGenerator() # Submit GET requests for authData, transportTarget, varNames in targets: cmdGen.getCmd( - snmpEngine, authData, transportTarget, cmdgen.ContextData(), varNames, + snmpEngine, authData, transportTarget, ContextData(), varNames, # User-space callback function and its context - (cbFun, (authData, transportTarget)), - lookupNames=True, lookupValues=True + (cbFun, (authData, transportTarget)) ) snmpEngine.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py index b1304aec..a77dc49e 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py +++ b/examples/hlapi/asyncore/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py @@ -1,40 +1,42 @@ -## -# Asynchronous Command Generator -# -# Send a bunch of SNMP GETNEXT requests all at once using the following options: -# -# * with SNMPv1, community 'public' and -# with SNMPv2c, community 'public' and -# with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy -# * over IPv4/UDP and -# over IPv6/UDP -# * to an Agent at demo.snmplabs.com:161 and -# to an Agent at [::1]:161 -# * for multiple MIB subtrees and tables -# -from pysnmp.entity import engine -from pysnmp.entity.rfc3413.oneliner import cmdgen +""" +Walk multiple Agents at once +++++++++++++++++++++++++++++ + +Iterate over MIBs of multiple SNMP Agents asynchronously using the +following options: + +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and + with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at [::1]:161 +* for multiple MIB subtrees and tables + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * # List of targets in the followin format: # ( ( authData, transportTarget, varNames ), ... ) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) - ( cmdgen.CommunityData('public', mpModel=0), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('1.3.6.1.2.1')), - cmdgen.ObjectType(cmdgen.ObjectIdentity('1.3.6.1.3.1')) ) ), + ( CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('1.3.6.1.2.1')), + ObjectType(ObjectIdentity('1.3.6.1.3.1')) ) ), # 2-nd target (SNMPv2c over IPv4/UDP) - ( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('1.3.6.1.4.1')), ) ), + ( CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('1.3.6.1.4.1')), ) ), # 3-nd target (SNMPv3 over IPv4/UDP) - ( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'system')), ) ), + ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')), ) ), # 4-th target (SNMPv3 over IPv6/UDP) - ( cmdgen.UsmUserData('usr-md5-none', 'authkey1'), - cmdgen.Udp6TransportTarget(('::1', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('IF-MIB', 'ifTable')), ) ) + ( UsmUserData('usr-md5-none', 'authkey1'), + Udp6TransportTarget(('::1', 161)), + ( ObjectType(ObjectIdentity('IF-MIB', 'ifTable')), ) ) # N-th target # ... ) @@ -47,44 +49,38 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, if errorIndication: print(errorIndication) return - if errorStatus: + elif errorStatus: print('%s at %s' % ( errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex)-1][0] or '?' ) ) return - varBindTableRow = varBindTable[-1] - for idx in range(len(varBindTableRow)): - name, val = varBindTableRow[idx] - if val is not None and varBindHead[idx] <= name: - # still in table - break else: - print('went out of table at %s' % (name, )) - return + for idx, varBind in enumerate(varBindTable[-1]): + if varBind[1] is not None and varBindHead[idx] <= varBind[0]: + break # still in table + else: + print('went out of table at %s' % (name, )) + return - for varBindRow in varBindTable: - for oid, val in varBindRow: - if val is None: - print(oid.prettyPrint()) - else: - print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + for varBindRow in varBindTable: + for varBind in varBindRow: + print(' = '.join([ x.prettyPrint() for x in varBind ])) - return True # continue table retrieval + return True # continue table retrieval -snmpEngine = engine.SnmpEngine() +snmpEngine = SnmpEngine() -cmdGen = cmdgen.AsyncCommandGenerator() +cmdGen = AsyncCommandGenerator() # Submit initial GETNEXT requests and wait for responses for authData, transportTarget, varBinds in targets: varBindHead = [ x[0] for x in cmdGen.makeVarBinds(snmpEngine, varBinds ) ] cmdGen.nextCmd( - snmpEngine, authData, transportTarget, cmdgen.ContextData(), varBinds, + snmpEngine, authData, transportTarget, ContextData(), varBinds, # User-space callback function and its context - (cbFun, (varBindHead, authData, transportTarget)), - lookupNames=True, lookupValues=True + (cbFun, (varBindHead, authData, transportTarget)) ) snmpEngine.transportDispatcher.runDispatcher() diff --git a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py b/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py index 85586ed5..96ce80f3 100644 --- a/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py +++ b/examples/hlapi/asyncore/manager/cmdgen/query-multiple-snmp-engines.py @@ -1,52 +1,54 @@ -# -# Asynchronous Command Generator -# -# Send SNMP GET requests using multiple independend SNMP engines -# with the following options: -# -# * with SNMPv1, community 'public' and -# with SNMPv2c, community 'public' and -# with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy -# * over IPv4/UDP and -# over IPv6/UDP -# * to an Agent at demo.snmplabs.com:161 and -# to an Agent at [::1]:161 -# * for instances of SNMPv2-MIB::sysDescr.0 and -# SNMPv2-MIB::sysLocation.0 MIB objects -# -# Within this script we have a single asynchronous TransportDispatcher -# and a single UDP-based transport serving two independent SNMP engines. -# We use a single instance of AsyncCommandGenerator with each of -# SNMP Engines to comunicate GET command request to remote systems. -# -# When we receive a [response] message from remote system we use -# a custom message router to choose what of the two SNMP engines -# data packet should be handed over. The selection criteria we -# employ here is based on peer's UDP port number. Other selection -# criterias are also possible. -# -from pysnmp.entity.rfc3413.oneliner import cmdgen -from pysnmp.entity import engine +""" +Multiple SNMP engines ++++++++++++++++++++++ + +Send multiple SNMP GET requests to multiple peers using multiple +independend SNMP engines. Deal with peers asynchronously. SNMP options +are: + +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and + with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at [::1]:161 +* for instances of SNMPv2-MIB::sysDescr.0 and + SNMPv2-MIB::sysLocation.0 MIB objects + +Within this script we have a single asynchronous TransportDispatcher +and a single UDP-based transport serving two independent SNMP engines. +We use a single instance of AsyncCommandGenerator with each of +SNMP Engines to comunicate GET command request to remote systems. + +When we receive a [response] message from remote system we use +a custom message router to choose what of the two SNMP engines +data packet should be handed over. The selection criteria we +employ here is based on peer's UDP port number. Other selection +criterias are also possible. + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher -# List of targets in the followin format: +# List of targets in the following format: # ( ( authData, transportTarget, varNames ), ... ) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) - ( cmdgen.CommunityData('public', mpModel=0), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), + ( CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), # 2-nd target (SNMPv2c over IPv4/UDP) - ( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 1161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), + ( CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 1161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ), # 3-nd target (SNMPv3 over IPv4/UDP) - ( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 2161)), - ( cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - cmdgen.ObjectType(cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ) + ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 2161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) )) ) # N-th target # ... ) @@ -61,20 +63,16 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, if errorIndication: print(errorIndication) return 1 - if errorStatus: + elif errorStatus: print('%s at %s' % ( errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) ) return 1 - - for oid, val in varBinds: - if val is None: - print(oid.prettyPrint()) - else: - print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) - + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) # Instantiate the single transport dispatcher object transportDispatcher = AsyncoreDispatcher() @@ -84,19 +82,19 @@ transportDispatcher.registerRoutingCbFun( lambda td,ta,d: ta[1] % 3 and 'A' or 'B' ) -snmpEngineA = engine.SnmpEngine() +snmpEngineA = SnmpEngine() snmpEngineA.registerTransportDispatcher(transportDispatcher, 'A') -snmpEngineB = engine.SnmpEngine() +snmpEngineB = SnmpEngine() snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B') -cmdGen = cmdgen.AsyncCommandGenerator() +cmdGen = AsyncCommandGenerator() for authData, transportTarget, varBinds in targets: snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \ snmpEngineA or snmpEngineB cmdGen.getCmd( - snmpEngine, authData, transportTarget, cmdgen.ContextData(), varBinds, + snmpEngine, authData, transportTarget, ContextData(), varBinds, (cbFun, (snmpEngine, authData, transportTarget)) ) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py index 071c3362..0c75c212 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextengineid.py @@ -1,46 +1,50 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv3 -# * with user 'usr-md5-none', MD5 auth, no priv -# * send INFORM notification -# * in behalf of contextEngineId 0x8000000004030201, contextName '' -# * over IPv4/UDP -# * with TRAP ID 'warmStart' specified as a string OID -# -# Sending SNMPv3 Notification in behalf of non-default ContextEngineId -# requires having a collection of Managed Objects registered under -# the ContextEngineId being used. -# +""" +INFORM with custom ContextEngineId +++++++++++++++++++++++++++++++++++ + +Send SNMP notification using the following options: + +* SNMPv3 +* with user 'usr-md5-none', MD5 auth, no priv +* send INFORM notification +* in behalf of contextEngineId 0x8000000004030201, contextName '' +* over IPv4/UDP +* with TRAP ID 'warmStart' specified as a string OID + +Sending SNMPv3 Notification in behalf of non-default ContextEngineId +requires having a collection of Managed Objects registered under +the ContextEngineId being used. + +Functionally similar to: + +| $ snmpinform -v3 -l authNoPriv -u usr-md5-none -A authkey1 \ +| -E 0x8000000004030201 +| demo.snmplabs.com \ +| 12345 \ +| 1.3.6.1.6.3.1.1.5.2 + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -from pysnmp.proto import rfc1902 - -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('localhost', 162)), - ContextData( - rfc1902.OctetString(hexValue='8000000004030201') - ), - 'inform', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('localhost', 162)), + ContextData( + rfc1902.OctetString(hexValue='8000000004030201') + ), + 'inform', + NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py index ed87fdc8..1b3e1f8e 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-contextname.py @@ -1,43 +1,48 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv3 -# * with user 'usr-md5-none', MD5 auth, no priv -# * send INFORM notification -# * in behalf of contextEngineId = SnmpEngineId, contextName 'my-context' -# * over IPv4/UDP -# * with TRAP ID 'warmStart' specified as a string OID -# -# Sending SNMPv3 Notification in behalf of non-default ContextName -# requires having a collection of Managed Objects registered under -# the ContextName being used. -# +""" +INFORM with custom ContextName +++++++++++++++++++++++++++++++ + +Send SNMP notification using the following options: + +* SNMPv3 +* with user 'usr-md5-none', MD5 auth, no priv +* send INFORM notification +* in behalf of contextEngineId = SnmpEngineId, contextName 'my-context' +* over IPv4/UDP +* with TRAP ID 'warmStart' specified as a string OID + +Sending SNMPv3 Notification in behalf of non-default ContextName +requires having a collection of Managed Objects registered under +the ContextName being used. + +Functionally similar to: + +| $ snmpinform -v3 -l authNoPriv -u usr-md5-none -A authkey1 \ +| -n my-context \ +| demo.snmplabs.com \ +| 12345 \ +| 1.3.6.1.6.3.1.1.5.2 + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('localhost', 162)), - ContextData(contextName='my-context'), - 'inform', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('localhost', 162)), + ContextData(contextName='my-context'), + 'inform', + NotificationType(ObjectIdentity('1.3.6.1.6.3.1.1.5.2'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py index 1d2b825e..85e130b9 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/custom-v1-trap.py @@ -1,36 +1,50 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv1 -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * with Generic Trap #6 (enterpriseSpecific) and Specific Trap 432 -# * overriding Uptime value with 12345 -# * overriding Agent Address with '127.0.0.1' -# * overriding Enterprise OID with 1.3.6.1.4.1.20408.4.1.1.2 -# * include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' -# +""" +Custom SNMPv1 TRAP +++++++++++++++++++ + +Send SNMPv1 TRAP through unified SNMPv3 message processing framework. + +Original v1 TRAP fields are mapped into dedicated variable-bindings, +(see `RFC2576 <https://www.ietf.org/rfc/rfc2576.txt>`_) for details. + +* SNMPv1 +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Generic Trap #6 (enterpriseSpecific) and Specific Trap 432 +* overriding Uptime value with 12345 +* overriding Agent Address with '127.0.0.1' +* overriding Enterprise OID with 1.3.6.1.4.1.20408.4.1.1.2 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v1 -c public demo.snmplabs.com \ +| 1.3.6.1.4.1.20408.4.1.1.2 \ +| 127.0.0.1 \ +| 6 \ +| 432 \ +| 12345 \ +| '1.3.6.1.2.1.1.1.0' s 'my system' + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -from pysnmp.proto import rfc1902 -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('localhost', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'), - ).addVarBinds( - ('1.3.6.1.2.1.1.3.0', 12345), - ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'), - ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), - ('1.3.6.1.2.1.1.1.0', rfc1902.OctetString('my system')) - )): - if errorIndication: - print(errorIndication) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('localhost', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('1.3.6.1.4.1.20408.4.1.1.2.0.432'), + ).addVarBinds( + ('1.3.6.1.2.1.1.3.0', 12345), + ('1.3.6.1.6.3.18.1.3.0', '127.0.0.1'), + ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), + ('1.3.6.1.2.1.1.1.0', rfc1902.OctetString('my system')) + ) + ) +) +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py index a7041462..5ad5ef7b 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/default-v1-trap.py @@ -1,34 +1,46 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv1 -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * with Generic Trap #1 (warmStart) and Specific Trap 0 -# * with default Uptime -# * with default Agent Address -# * with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2 -# * include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' -# +""" +SNMPv1 TRAP with defaults ++++++++++++++++++++++++++ + +Send SNMPv1 TRAP through unified SNMPv3 message processing framework +using the following options: + +* SNMPv1 +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with Generic Trap #1 (warmStart) and Specific Trap 0 +* with default Uptime +* with default Agent Address +* with Enterprise OID 1.3.6.1.4.1.20408.4.1.1.2 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v1 -c public demo.snmplabs.com \ +| 1.3.6.1.4.1.20408.4.1.1.2 \ +| 0.0.0.0 \ +| 1 \ +| 0 \ +| 0 +| '1.3.6.1.2.1.1.1.0' s 'my system' + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -from pysnmp.proto import rfc1902 -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('localhost', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ).addVarBinds( - ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), - ('1.3.6.1.2.1.1.1.0', rfc1902.OctetString('my system')) - )): - if errorIndication: - print(errorIndication) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('localhost', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).addVarBinds( + ('1.3.6.1.6.3.1.1.4.3.0', '1.3.6.1.4.1.20408.4.1.1.2'), + ('1.3.6.1.2.1.1.1.0', rfc1902.OctetString('my system')) + ) + ) +) +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py index 6eebaa93..4d99a126 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/send-notification-with-additional-varbinds.py @@ -1,42 +1,49 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send INFORM notification -# * with TRAP ID 'coldStart' specified as a MIB symbol -# * include managed object information specified as a MIB symbol -# * perform response OIDs and values resolution at MIB -# +""" +Sending additional var-binds +++++++++++++++++++++++++++++ + +Send SNMP notification using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send INFORM notification +* with TRAP ID 'coldStart' specified as a MIB symbol +* include managed object information specified as a MIB symbol + +Functionally similar to: + +| $ snmpinform -v2c -c public +| demo.snmplabs.com \ +| 12345 \ +| 1.3.6.1.6.3.1.1.5.1 \ +| 1.3.6.1.2.1.1.1.0 s 'my system' + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('localhost', 162)), - ContextData(), - 'inform', - NotificationType( - ObjectIdentity('SNMPv2-MIB', 'coldStart') - ).addVarBinds( - ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system') ) - ), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('localhost', 162)), + ContextData(), + 'inform', + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'coldStart') + ).addVarBinds( + ObjectType(ObjectIdentity('SNMPv2-MIB','sysName',0), + 'my system') + )) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py index b243f438..a328a2ce 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/v2c-trap-via-notification-type.py @@ -1,27 +1,37 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * with TRAP ID 'coldStart' specified as a MIB symbol -# * include managed object information specified as a MIB symbol -# +""" +SNMPv2c TRAP via NOTIFICATION-TYPE +++++++++++++++++++++++++++++++++++ + +Initialize TRAP message contents from variables specified +in *NOTIFICATION-TYPE* SMI macro. + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* with TRAP ID 'coldStart' specified as a MIB symbol +* include managed object information specified as a MIB symbol + +Functionally similar to: + +| $ snmptrap -v2c -c public demo.snmplabs.com \ +| 12345 +| 1.3.6.1.4.1.20408.4.1.1.2 \ + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('localhost', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('SNMPv2-MIB', 'coldStart') - )): - if errorIndication: - print(errorIndication) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('localhost', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'coldStart') + ) + ) +) + +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py index 2996eb51..161427a3 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-inform.py @@ -1,44 +1,49 @@ -## -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv3 -# * with user 'usr-md5-des', auth: MD5, priv DES -# * over IPv4/UDP -# * send INFORM notification -# * with TRAP ID 'warmStart' specified as a string OID -# * include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' -# +""" +INFORM, auth: MD5 privacy: DES +++++++++++++++++++++++++++++++ + +Send SNMP INFORM notification using the following options: + +* SNMPv3 +* with user 'usr-md5-des', auth: MD5, priv DES +* over IPv4/UDP +* send INFORM notification +* with TRAP ID 'warmStart' specified as a string OID +* include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' + +Functionally similar to: + +| $ snmpinform -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 \ +| demo.snmplabs.com \ +| 12345 \ +| 1.3.6.1.4.1.20408.4.1.1.2 \ +| '1.3.6.1.2.1.1.1.0' s 'my system' + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -from pysnmp.proto import rfc1902 -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - UdpTransportTarget(('localhost', 162)), - ContextData(), - 'inform', - NotificationType( - ObjectIdentity('1.3.6.1.6.3.1.1.5.2') - ).addVarBinds( - ( ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), - rfc1902.OctetString('system name')) ) - ), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('localhost', 162)), + ContextData(), + 'inform', + NotificationType( + ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).addVarBinds( + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.5.0'), + 'system name') + )) +) +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py index bbc91940..f03948f2 100644 --- a/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py +++ b/examples/hlapi/asyncore/sync/agent/ntforg/v3-trap.py @@ -1,37 +1,45 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv3 -# * with local snmpEngineId = 0x8000000001020304 (must configure at Receiver) -# * with user 'usr-sha-aes128', auth: SHA, priv: AES128 -# * over IPv4/UDP -# * send TRAP notification -# * with TRAP ID 'authenticationFailure' specified as a MIB symbol -# * do not include any additional managed object information -# -# SNMPv3 TRAPs requires pre-sharing the Notification Originator's -# value of SnmpEngineId with Notification Receiver. To facilitate that -# we will use static (e.g. not autogenerated) version of snmpEngineId. -# +""" +SNMPv3 TRAP: auth SHA, privacy: AES128 +++++++++++++++++++++++++++++++++++++++ + +Send SNMP notification using the following options: + +* SNMPv3 +* with local snmpEngineId = 0x8000000001020304 (must configure at Receiver) +* with user 'usr-sha-aes128', auth: SHA, priv: AES128 +* over IPv4/UDP +* send TRAP notification +* with TRAP ID 'authenticationFailure' specified as a MIB symbol +* do not include any additional managed object information + +SNMPv3 TRAPs requires pre-sharing the Notification Originator's +value of SnmpEngineId with Notification Receiver. To facilitate that +we will use static (e.g. not autogenerated) version of snmpEngineId. + +Functionally similar to: + +| $ snmptrap -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 \ +| -a SHA -x AES \ +| demo.snmplabs.com \ +| 12345 \ +| 1.3.6.1.4.1.20408.4.1.1.2 \ +| '1.3.6.1.2.1.1.1.0' s 'my system' + +"""# from pysnmp.entity.rfc3413.oneliner.ntforg import * -from pysnmp.proto.rfc1902 import OctetString -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in \ - sendNotification(SnmpEngine( - OctetString(hexValue='8000000001020304') - ), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol), - UdpTransportTarget(('localhost', 162)), - ContextData(), - 'trap', - NotificationType( - ObjectIdentity('SNMPv2-MIB', 'authenticationFailure') - )): - if errorIndication: - print(errorIndication) +errorIndication, errorStatus, errorIndex, varBinds = next( + sendNotification(SnmpEngine(OctetString(hexValue='8000000001020304')), + UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol), + UdpTransportTarget(('localhost', 162)), + ContextData(), + 'trap', + NotificationType( + ObjectIdentity('SNMPv2-MIB', 'authenticationFailure') + ) + ) +) +if errorIndication: + print(errorIndication) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py index 46d4c5ec..62f7595c 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/coerce-set-value-to-mib-spec.py @@ -1,36 +1,39 @@ -# -# Command Generator -# -# Send SNMP SET request using the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) -# +""" +Coerce value to SET to MIB spec ++++++++++++++++++++++++++++++++ + +Send SNMP SET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) + +Functionally similar to: + +| $ snmpset -v2c -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 \ +| = "new system name" + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in setCmd(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType( - ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), - 'new system name' - )): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + setCmd(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), + 'new system name')) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py index fba316f5..e994dbac 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-asn1-mib-search-path.py @@ -1,37 +1,39 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for IF-MIB::ifInOctets.1 MIB object -# * Pass attached MIB compiler non-default ASN.1 MIB source -# +""" +Custom ASN.1 MIB path ++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 MIB object +* pass non-default ASN.1 MIB source to MIB compiler + +Functionally similar to: + +| $ snmpget -v2c -c public -M /usr/share/snmp demo.snmplabs.com \ +| IF-MIB::ifInOctets.1 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType( - ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/@mib@') - ), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1).addAsn1MibSource('file:///usr/share/snmp', 'http://mibs.snmplabs.com/asn1/@mib@'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py index 9c5b20f1..f0178823 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid-and-contextname.py @@ -1,43 +1,45 @@ -# -# Command Generator -# -# Send SNMP SET request using the following options: -# -# * with SNMPv3 with user 'usr-md5-none', MD5 auth and no privacy protocols -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * addressing particular set of Managed Objects at remote SNMP Engine by: -# * contextEngineId 0x80004fb805636c6f75644dab22cc and -# * contextName 'a172334d7d97871b72241397f713fa12' -# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) -# +""" +Custom ContextEngineId and ContextName +++++++++++++++++++++++++++++++++++++++ + +Send SNMP SET request using the following options: + +* with SNMPv3 with user 'usr-md5-none', MD5 auth and no privacy protocols +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* addressing particular set of Managed Objects at remote SNMP Engine by: + * contextEngineId 0x80004fb805636c6f75644dab22cc and + * contextName 'a172334d7d97871b72241397f713fa12' +* setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) + +Functionally similar to: + +| $ snmpset -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 \ +| -E 80004fb805636c6f75644dab22cc -n a172334d7d97871b72241397f713fa12 \ +| demo.snmplabs.com \ +| SNMPv2-MIB::sysORDescr.1 = "new system name" + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -from pysnmp.proto import rfc1902 -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in setCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData( - contextEngineId=rfc1902.OctetString(hexValue='80004fb805636c6f75644dab22cc'), - contextName='da761cfc8c94d3aceef4f60f049105ba' - ), - ObjectType( - ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), - 'new system name' - )): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + setCmd(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(contextEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc'), + contextName='da761cfc8c94d3aceef4f60f049105ba'), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), + 'new system name')) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py index 22d165df..46ef2759 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py @@ -1,44 +1,43 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols -# * use remote SNMP Engine ID 0x80004fb805636c6f75644dab22cc (USM -# autodiscovery will run) -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB) -# +""" +Custom ContextEngineId +++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols +* use remote SNMP Engine ID 0x80004fb805636c6f75644dab22cc (USM + autodiscovery will run) +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* setting SNMPv2-MIB::sysName.0 to new value (type coerced from MIB) + +Functionally similar to: + +| $ snmpset -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 \ +| -E 80004fb805636c6f75644dab22cc demo.snmplabs.com \ +| SNMPv2-MIB::sysORDescr.1 = "new system name" + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -from pysnmp.proto import rfc1902 -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in setCmd(SnmpEngine(), - UsmUserData( - 'usr-md5-des', 'authkey1', 'privkey1', - securityEngineId=rfc1902.OctetString( - hexValue='80004fb805636c6f75644dab22cc' - ) - ), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType( - ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1), - 'new system name' - )): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + setCmd(SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1', + securityEngineId=OctetString(hexValue='80004fb805636c6f75644dab22cc')), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0), + 'new system name')) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py index 5d1eb815..9c974656 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-pysnmp-mibs-search-path.py @@ -1,17 +1,23 @@ -# -# Command Generator -# -# Send SNMP GETBULK request using the following options: -# -# * with SNMPv3, user 'usr-none-none', no authentication, no privacy -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for all OIDs past TCP-MIB::tcpConnTable -# * TCP-MIB will be searched by a user-specified path -# * run till end-of-mib condition is reported by Agent OR maxRows == 100 OR -# maxCalls == 10 request-response interactions occur -# * ignoring non-increasing OIDs whenever reported by Agent -# +""" +Custom PySNMP MIBs location ++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv3, user 'usr-none-none', no authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs within TCP-MIB::tcpConnTable column +* TCP-MIB Python module will be searched by a user-specified filesystem + path (/opt/mib/pysnmp) and in Python package (python_packaged_mibs) + which should be in sys.path + +Functionally similar to: + +| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \ +| demo.snmplabs.com TCP-MIB::tcpConnTable + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -21,22 +27,19 @@ for errorIndication, \ UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), 0, 50, - ObjectType(ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/tmp/mibs')), - maxRows=100, maxCalls=10, - lexicographicMode=True, - ignoreNonIncreasingOid=True): - # Check for errors and print out results + ObjectType(ObjectIdentity('TCP-MIB', 'tcpConnTable').addMibSource('/opt/mibs/pysnmp').addMibSource('python_packaged_mibs')), + lexicographicMode=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py index d9fc4919..1439aeb3 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-timeout-and-retries.py @@ -1,49 +1,53 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for an OID in string form -# * use custom timeout and request retries values -# -# Transport timing settings (maximum number of request retries and -# individual request timeout in seconds) can be set on a per-target basis -# as explained by the code that follows. -# -# Keep in mind that while timeout value can be specified in fractions of a -# second, default pysnmp timer resolution is quite low (about 0.5 sec) -# so there's no much point in using timeouts which is not a multiple of 0.5 -# Internal timer can be programmatically adjusted to finer resolution if needed. -# -# If retries value is set to 0, pysnmp will issue a single request. Even -# if no response arrives, there will be no retry. Likewise, retries=1 -# means one initial request plus one retry. -# +""" +Custom request timeout +++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for an OID in string form +* use custom timeout and request retries values + +Transport timing settings (maximum number of request retries and +individual request timeout in seconds) can be set on a per-target basis +as explained by the code that follows. + +Keep in mind that while timeout value can be specified in fractions of a +second, default pysnmp timer resolution is quite low (about 0.5 sec) +so there's no much point in using timeouts which is not a multiple of 0.5 +Internal timer can be programmatically adjusted to finer resolution if needed. + +If retries value is set to 0, pysnmp will issue a single request. Even +if no response arrives, there will be no retry. Likewise, retries=1 +means one initial request plus one retry. + +Functionally similar to: + +| $ snmpget -v1 -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget( - ('demo.snmplabs.com', 161), timeout=1.5, retries=0 - ), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget( + ('demo.snmplabs.com', 161), timeout=1.5, retries=0 + ), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py index 4770c5d3..ae5e6569 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-v3-security-name.py @@ -1,40 +1,38 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv3, user 'usr-md5-none', securityName 'myuser' -# MD5 authentication, no privacy -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for an OID in text form -# -# The securityName parameter can be thought as an alias to userName and -# allows you to address a USM Table row just as userName does. However -# securityName can be made human-readable, also it is not an index in -# usmUserTable, thus duplicate securityName parameters are possible. -# +""" +Custom SecurityName ++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-md5-none', securityName 'myuser' + MD5 authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for an OID in text form + +The securityName parameter can be thought as an alias to userName and +allows you to address a USM Table row just as userName does. However +securityName can be made human-readable, also it is not an index in +usmUserTable, thus duplicate securityName parameters are possible. +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1', - securityName='myuser'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1', securityName='myuser'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py index 716d1e9b..9499a385 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/fetch-variables-over-ipv6.py @@ -1,36 +1,42 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols -# * over IPv6/UDP -# * to an Agent at [::1]:161 -# * for three OIDs: one passed as a ObjectIdentity object while others are -# * in string form -# +""" +GET over IPv6 ++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols +* over IPv6/UDP +* to an Agent at [::1]:161 +* for three OIDs in string form + +Functionally similar to: + +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ +| udp6:[::1]:161 \ +| 1.3.6.1.2.1.1.1.0 \ +| 1.3.6.1.2.1.1.2.0 \ +| 1.3.6.1.2.1.1.3.0 +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - Udp6TransportTarget(('::1', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0'))): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + Udp6TransportTarget(('::1', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.2.0')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py index e83e0d2a..84b91056 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-index.py @@ -1,35 +1,41 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv3, user 'usr-none-none', no authentication, no privacy -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for IF-MIB::ifInOctets.1 MIB object -# * perform response OIDs and values resolution at MIB -# +""" +GET table row ++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-none-none', no authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 and IF-MIB::ifOutOctets.1 MIB object +* perform response OIDs and values resolution at MIB + +Functionally similar to: + +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ +| demo.snmplabs.com \ +| IF-MIB::ifInOctets.1 IF-MIB::ifOutOctets.1 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - UsmUserData('usr-none-none'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)), + ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py index 7b78a356..ebc2b0cb 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/get-table-object-by-multiple-indices.py @@ -1,40 +1,46 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 MIB object -# +""" +Fetch table row by composite index +++++++++++++++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 MIB object + +Functionally similar to: + +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ +| -a SHA -x AES \ +| demo.snmplabs.com \ +| TCP-MIB::tcpConnLocalAddress."0.0.0.0".22."0.0.0.0".0 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', - authProtocol=usmHMACSHAAuthProtocol, - privProtocol=usmAesCfb128Protocol ), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType( - ObjectIdentity('TCP-MIB', - 'tcpConnLocalAddress', - '0.0.0.0', 22, - '0.0.0.0', 0) - )): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol ), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('TCP-MIB', + 'tcpConnLocalAddress', + '0.0.0.0', 22, + '0.0.0.0', 0)) + ) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py index 9b255f35..6a09a13e 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py @@ -1,16 +1,25 @@ -# -# Command Generator -# -# Send SNMP GETBULK request using the following options: -# -# * with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols -# * over IPv6/UDP -# * to an Agent at [::1]:161 -# * with values non-repeaters = 1, max-repetitions = 25 -# * for IP-MIB::ipAdEntAddr and all columns of the IF-MIB::ifEntry table -# * stop when response OIDs leave the scopes of the table OR maxRows == 20 -# * perform response OIDs and values resolution at MIB -# +""" +Fetch scalar and table variables +++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols +* over IPv6/UDP +* to an Agent at [::1]:161 +* with values non-repeaters = 1, max-repetitions = 25 +* for IP-MIB::ipAdEntAddr and all columns of the IF-MIB::ifEntry table +* stop when response OIDs leave the scopes of the table + +Functionally similar to: + +| $ snmpbulkwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 \ +| -Cn1, -Cr25 \ +| demo.snmplabs.com \ +| IP-MIB::ipAdEntAddr \ +| IP-MIB::ipAddrEntry + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -22,19 +31,18 @@ for errorIndication, \ 1, 25, ObjectType(ObjectIdentity('IP-MIB', 'ipAdEntAddr')), ObjectType(ObjectIdentity('IP-MIB', 'ipAddrEntry')), - lookupNames=True, lookupValues=True, maxRows=20): - # Check for errors and print out results + lexicographicMode=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py new file mode 100644 index 00000000..4cb303e9 --- /dev/null +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-packets.py @@ -0,0 +1,44 @@ +""" +Walk Agent, limit number of packets ++++++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv3, user 'usr-none-none', no authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs past SNMPv2-MIB::system +* run till end-of-mib condition is reported by Agent OR + maxCalls == 10 request-response interactions occur + +Functionally similar to: + +| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \ +| demo.snmplabs.com SNMPv2-MIB::system + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * + +for errorIndication, \ + errorStatus, errorIndex, \ + varBinds in bulkCmd(SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + 0, 50, + ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')), + maxCalls=10): + + if errorIndication: + print(errorIndication) + break + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py new file mode 100644 index 00000000..ac4887a0 --- /dev/null +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getbulk-limit-number-of-variables.py @@ -0,0 +1,47 @@ +""" +Walk MIB, limit number of response rows ++++++++++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* with values non-repeaters = 0, max-repetitions = 25 +* for two OIDs in string form +* stop when response OIDs leave the scopes of initial OIDs OR + number of response rows reach fixed value (20) + +Functionally similar to: + +| $ snmpbulkwalk -v2c -c public demo.snmplabs.com \ +| -Cn0 -Cr25 \ +| 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.3 + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * + +for errorIndication, \ + errorStatus, errorIndex, \ + varBinds in bulkCmd(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + 0, 25, + ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3')), + lexicographicMode=False, maxRows=20): + + if errorIndication: + print(errorIndication) + break + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py index 99eba513..19d79500 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-limit-number-of-variables.py @@ -1,17 +1,23 @@ -# -# Command Generator -# -# Send SNMP GETNEXT requests using the following options: -# -# * with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy -# * over Local Domain Sockets -# * to an Agent at demo.snmplabs.com:161 -# * for all OIDs past IF-MIB (load up all MIBs in search path) -# * run till end-of-mib condition is reported by Agent OR maxRows == 100 -# * ignoring non-increasing OIDs whenever reported by Agent -# -# make sure IF-MIB.py is search path -# +""" +Fetch fixed amount of MIB variables ++++++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy +* over UDP/IPv4 +* to an Agent at demo.snmplabs.com:161 +* for all OIDs past SNMPv2-MIB +* run till end-of-mib condition is reported by Agent OR maxRows == 100 +* ignoring non-increasing OIDs whenever reported by Agent + +Functionally similar to: + +| $ snmpwalk -v3 -lauthPriv -u usr-sha-aes128 -A authkey1 -X privkey1 \ +| -a MD5 -x AES demo.snmplabs.com \ +| SNMPv2-MIB::system + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -22,21 +28,19 @@ for errorIndication, \ privProtocol=usmAesCfb128Protocol), UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), - ObjectType(ObjectIdentity('IF-MIB', '').loadMibs()), - lexicographicMode=True, maxRows=100, - ignoreNonIncreasingOid=True): - # Check for errors and print out results + ObjectType(ObjectIdentity('SNMPv2-MIB')), + maxRows=100, ignoreNonIncreasingOid=True): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py index 178cd09e..514a6ce7 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/getnext-multiple-oids-to-eom.py @@ -1,14 +1,21 @@ -# -# Command Generator -# -# Send SNMP GETNEXT requests using the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for two OIDs in string form -# * stop when response OIDs leave the scopes of initial OIDs -# +""" +Fetch two OID branches +++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for two OIDs in string form +* stop when response OIDs leave the scopes of initial OIDs + +Functionally similar to: + +| $ snmpwalk -v2c -c public demo.snmplabs.com \ +| 1.3.6.1.2.1.2.2.1.2 1.3.6.1.2.1.2.2.1.3 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -18,19 +25,19 @@ for errorIndication, \ UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.2')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.3'))): - # Check for errors and print out results + ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.3')), + lexicographicMode=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py b/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py new file mode 100644 index 00000000..116d99ff --- /dev/null +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/multiple-get-calls.py @@ -0,0 +1,47 @@ +""" +Sequence Of GET's ++++++++++++++++++ + +Send two SNMP GET requests in a row using the following options: + +* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 and IF-MIB::ifOutOctets.1 MIB objects + +Use a queue of MIB objects to query. + +The next() call is used to forward Python iterator to the position where it +could consume input + +Functionally similar to: + +| $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 demo.snmplabs.com \ +| IF-MIB::ifInOctets.1 + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * + +queue = [ [ ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1)) ], + [ ObjectType(ObjectIdentity('IF-MIB', 'ifOutOctets', 1)) ] ] + +iter = getCmd(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData()) + +next(iter) + +while queue: + errorIndication, errorStatus, errorIndex, varBinds = iter.send(queue.pop()) + if errorIndication: + print(errorIndication) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py index 01c74be0..4a0877d0 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/preload-pysnmp-mibs.py @@ -1,17 +1,23 @@ -# -# Command Generator -# -# Send SNMP GETNEXT requests using the following options: -# -# * with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols -# * over IPv6/UDP -# * to an Agent at [::1]:161 -# * for all columns of the IF-MIB::ifEntry table -# * stop when response OIDs leave the scopes of the table -# * perform response OIDs and values resolution at MIB -# -# make sure IF-MIB.py is in search path -# +""" +Preload PySNMP MIBs ++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols +* over IPv6/UDP +* to an Agent at [::1]:161 +* for all OIDs starting from 1.3.6 +* preload all Python MIB modules found in search path + +Functionally similar to: + +| $ snmpwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ +| -m ALL +| udp6:[::1]:161 \ +| 1.3.6 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -20,20 +26,18 @@ for errorIndication, \ UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), Udp6TransportTarget(('::1', 161)), ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifEntry')), - lookupNames=True, lookupValues=True): - # Check for errors and print out results + ObjectType(ObjectIdentity('1.3.6').loadMibs())): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py index 658f6fc5..4c0568a0 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-mib.py @@ -1,15 +1,21 @@ -# -# Command Generator -# -# Send SNMP GETNEXT requests using the following options: -# -# * with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for all OIDs in IF-MIB -# * stop when response OIDs leave the scopes of the table -# * perform response values resolution at MIB -# +""" +Walk whole MIB +++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for all OIDs in IF-MIB +* stop when response OIDs leave the scopes of the table + +Functionally similar to: + +| $ snmpwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 \ +| demo.snmplabs.com IF-MIB:: + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -18,20 +24,19 @@ for errorIndication, \ UsmUserData('usr-md5-none', 'authkey1'), UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), - ObjectType(ObjectIdentity('IF-MIB', '')), - lookupValues=True): - # Check for errors and print out results + ObjectType(ObjectIdentity('IF-MIB')), + lexicographicMode=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py index 1c3a998e..7530a391 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/pull-whole-snmp-table.py @@ -1,18 +1,31 @@ -# -# Command Generator -# -# Send SNMP GETNEXT request using the following options: -# -# * with SNMPv1, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for some columns of the IF-MIB::ifEntry table -# * stop when response OIDs leave the scopes of initial OIDs -# +""" +Fetch whole SNMP table +++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests using the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for some columns of the IF-MIB::ifEntry table +* stop when response OIDs leave the scopes of initial OIDs + +Functionally similar to: + +| $ snmpwalk -v1 -c public demo.snmplabs.com \ +| IF-MIB::ifDescr \ +| IF-MIB::ifType \ +| IF-MIB::ifMtu \ +| IF-MIB::ifSpeed \ +| IF-MIB::ifPhysAddress \ +| IF-MIB::ifType \ + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ - errorStatus, errorIndex, \ + errorStatus, \ + errorIndex, \ varBinds in nextCmd(SnmpEngine(), CommunityData('public', mpModel=0), UdpTransportTarget(('demo.snmplabs.com', 161)), @@ -22,19 +35,19 @@ for errorIndication, \ ObjectType(ObjectIdentity('IF-MIB', 'ifMtu')), ObjectType(ObjectIdentity('IF-MIB', 'ifSpeed')), ObjectType(ObjectIdentity('IF-MIB', 'ifPhysAddress')), - ObjectType(ObjectIdentity('IF-MIB', 'ifType'))): - # Check for errors and print out results + ObjectType(ObjectIdentity('IF-MIB', 'ifType')), + lexicographicMode=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py b/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py index 5d589f93..47630ea5 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/query-agents-from-multuple-threads.py @@ -1,56 +1,58 @@ -# -# Multithreaded, synchronous Command Generator -# -# Send a bunch of SNMP GET requests simultaneously using the following options: -# -# * process 5 GET requests in 3 parallel threads -# * with SNMPv1, community 'public' and -# with SNMPv2c, community 'public' and -# with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy -# * over IPv4/UDP and -# over IPv6/UDP -# * to an Agent at demo.snmplabs.com:161 and -# to an Agent at [::1]:161 -# * for instances of SNMPv2-MIB::sysDescr.0 and -# SNMPv2-MIB::sysLocation.0 MIB objects -# +""" +Query Agents from multiple threads +++++++++++++++++++++++++++++++++++ + +Send a bunch of SNMP GET requests simultaneously using the following options: + +* process 5 GET requests in 3 parallel threads +* with SNMPv1, community 'public' and + with SNMPv2c, community 'public' and + with SNMPv3, user 'usr-md5-des', MD5 auth and DES privacy +* over IPv4/UDP and + over IPv6/UDP +* to an Agent at demo.snmplabs.com:161 and + to an Agent at [::1]:161 +* for instances of SNMPv2-MIB::sysDescr.0 and + SNMPv2-MIB::sysLocation.0 MIB objects + +"""# from sys import version_info if version_info[0] == 2: from Queue import Queue else: from queue import Queue from threading import Thread -from pysnmp.entity.rfc3413.oneliner import cmdgen +from pysnmp.entity.rfc3413.oneliner.cmdgen import * # List of targets in the followin format: # ( ( authData, transportTarget, varNames ), ... ) targets = ( # 1-st target (SNMPv1 over IPv4/UDP) - ( cmdgen.CommunityData('public', mpModel=0), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), - cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ), + ( CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # 2-nd target (SNMPv2c over IPv4/UDP) - ( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), - cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ), + ( CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # 3-nd target (SNMPv2c over IPv4/UDP) - same community and # different transport address. - ( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('localhost', 161)), - ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysContact', 0), - cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysName', 0) ) ), + ( CommunityData('public'), + UdpTransportTarget(('localhost', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)))), # 4-nd target (SNMPv3 over IPv4/UDP) - ( cmdgen.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)), - ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), - cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ), + ( UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ))), # 5-th target (SNMPv3 over IPv6/UDP) - ( cmdgen.UsmUserData('usr-md5-none', 'authkey1'), - cmdgen.Udp6TransportTarget(('::1', 161)), - ( cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), - cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0) ) ), + ( UsmUserData('usr-md5-none', 'authkey1'), + Udp6TransportTarget(('::1', 161)), + ( ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))), # N-th target # ... ) @@ -58,19 +60,21 @@ targets = ( class Worker(Thread): def __init__(self, requests, responses): Thread.__init__(self) + self.snmpEngine = SnmpEngine() self.requests = requests self.responses = responses - self.cmdGen = cmdgen.CommandGenerator() self.setDaemon(True) self.start() def run(self): while True: - authData, transportTarget, varNames = self.requests.get() + authData, transportTarget, varBinds = self.requests.get() self.responses.append( - self.cmdGen.getCmd( - authData, transportTarget, *varNames, - **{ 'lookupNames': True, 'lookupValues': True } + next( + getCmd( + self.snmpEngine, + authData, transportTarget, ContextData(), *varBinds + ) ) ) if hasattr(self.requests, 'task_done'): # 2.5+ @@ -101,8 +105,8 @@ class ThreadPool: pool = ThreadPool(3) # Submit GET requests -for authData, transportTarget, varNames in targets: - pool.addRequest(authData, transportTarget, varNames) +for authData, transportTarget, varBinds in targets: + pool.addRequest(authData, transportTarget, varBinds) # Wait for responses or errors pool.waitCompletion() @@ -112,15 +116,12 @@ for errorIndication, errorStatus, errorIndex, varBinds in pool.getResponses(): print('Response for %s from %s:' % (authData, transportTarget)) if errorIndication: print(errorIndication) - if errorStatus: + elif errorStatus: print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) ) - - for oid, val in varBinds: - if val is None: - print(oid.prettyPrint()) - else: - print('%s = %s' % (oid.prettyPrint(), val.prettyPrint())) + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py b/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py index bba4a84d..9b9fae71 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/set-multiple-scalar-values.py @@ -1,36 +1,49 @@ -# -# Command Generator -# -# Send SNMP SET request using the following options: -# -# * with SNMPv1, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * setting two OIDs to new values (types explicitly specified) -# +""" +SET scalars values +++++++++++++++++++ + +Send SNMP SET request using the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* setting three var-bindings to new values + +Please note, that in this example MIB lookup is only used +for the second var-bindins. For the rest, value types are +inferred from passed objects. + +Functionally similar to: + +| $ snmpset -v1 -c public demo.snmplabs.com \ +| 1.3.6.1.2.1.1.9.1.2.1 o 1.3.6.1.4.1.20408.1.1 \ +| 1.3.6.1.2.1.1.9.1.2.1 = 1.3.6.1.4.1.20408.1.1 \ +| 1.3.6.1.2.1.1.9.1.3.1 s "new system name" + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -from pysnmp.proto import rfc1902 - -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in setCmd(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ('1.3.6.1.2.1.1.9.1.2.1', rfc1902.ObjectName('1.3.6.1.4.1.20408.1.1')), - ('1.3.6.1.2.1.1.9.1.2.1', '1.3.6.1.4.1.20408.1.1'), - ('1.3.6.1.2.1.1.9.1.3.1', rfc1902.OctetString('new system name'))): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break + +errorIndication, errorStatus, errorIndex, varBinds = next( + setCmd(SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), + ObjectIdentifier('1.3.6.1.4.1.20408.1.1')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.2.1'), + '1.3.6.1.4.1.20408.1.1'), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.9.1.3.1'), + OctetString('new system name'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py b/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py index ca1d1fef..18b3a47a 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/specific-v3-engine-id.py @@ -1,18 +1,23 @@ -# -# Command Generator -# -# Send SNMP GET request using the following scenario and options: -# -# * try to communicate with a SNMPv3 Engine using: -# ** a non-existing user -# ** over IPv4/UDP -# ** to an Agent at demo.snmplabs.com:161 -# * if remote SNMP Engine ID is discovered, send SNMP GET request: -# ** with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy -# at discovered securityEngineId -# ** to the same SNMP Engine ID -# ** for an OID in text form -# +""" +Discover SNMPv3 SecurityEngineId +++++++++++++++++++++++++++++++++ + +Send SNMP GET request using the following scenario and options: + +* try to communicate with a SNMPv3 Engine using: + +* a non-existing user +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 + +* if remote SNMP Engine ID is discovered, send SNMP GET request: + +* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy + at discovered securityEngineId +* to the same SNMP Engine ID +* for an OID in text form + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * snmpEngine = SnmpEngine() @@ -38,10 +43,10 @@ snmpEngine.observer.registerObserver( authData = UsmUserData('non-existing-user') -for errorIndication, errorStatus, errorIndex, \ - varBinds in getCmd(snmpEngine, authData, - transportTarget, ContextData()): - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(snmpEngine, authData, transportTarget, ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) +) # See if our SNMP engine received REPORT PDU containing securityEngineId @@ -60,22 +65,22 @@ print('Remote securityEngineId = %s' % securityEngineId.prettyPrint()) authData = UsmUserData('usr-md5-none', 'authkey1', securityEngineId=securityEngineId) -for errorIndication, errorStatus, errorIndex, \ - varBinds in getCmd(snmpEngine, authData, \ - transportTarget, ContextData(), \ - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))): - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(snmpEngine, + authData, + transportTarget, + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) +) -# Check for errors and print out results if errorIndication: print(errorIndication) -else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - else: - for name, val in varBinds: - print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + ) +else: + for name, val in varBinds: + print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py new file mode 100644 index 00000000..2c53b290 --- /dev/null +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-des.py @@ -0,0 +1,39 @@ +""" +SNMPv3: auth MD5, privacy DES ++++++++++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-md5-des', MD5 authentication, DES encryption +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 MIB object + +Functionally similar to: + +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 \ +| demo.snmplabs.com \ +| IF-MIB::ifInOctets.1 + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py index c01a61d0..6e0d1c51 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-md5-none.py @@ -1,33 +1,38 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for IF-MIB::ifInOctets.1 MIB object -# +""" +SNMPv3: auth MD5, no privacy +++++++++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-md5-none', MD5 authentication, no privacy +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 MIB object + +Functionally similar to: + +| $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 demo.snmplabs.com \ +| IF-MIB::ifInOctets.1 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - UsmUserData('usr-md5-none', 'authkey1'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-md5-none', 'authkey1'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py new file mode 100644 index 00000000..976e0f4d --- /dev/null +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-none-none.py @@ -0,0 +1,39 @@ +""" +SNMPv3: no auth, no privacy ++++++++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-none-none', no authentication, no encryption +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for IF-MIB::ifInOctets.1 MIB object + +Functionally similar to: + +| $ snmpget -v3 -l noAuthNoPriv -u usr-none-none +| demo.snmplabs.com \ +| IF-MIB::ifInOctets.1 + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-none-none'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets', 1))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py new file mode 100644 index 00000000..85a0399e --- /dev/null +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py @@ -0,0 +1,57 @@ +""" +SNMPv3: auth SHA, privacy AES128 +++++++++++++++++++++++++++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv3, user 'usr-sha-aes', SHA authentication, AES128 encryption +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for SNMPv2-MIB::sysDescr.0 MIB object + +Available authentication protocols: + +#. usmHMACMD5AuthProtocol +#. usmHMACSHAAuthProtocol +#. usmNoAuthProtocol + +Available privacy protocols: + +#. usmDESPrivProtocol +#. usm3DESEDEPrivProtocol +#. usmAesCfb128Protocol +#. usmAesCfb192Protocol +#. usmAesCfb256Protocol +#. usmNoPrivProtocol + +Functionally similar to: + +| $ snmpget -v3 -l authPriv -u usr-sha-aes -A authkey1 -X privkey1 \ +| -a SHA -x AES \ +| demo.snmplabs.com \ +| SNMPv2-MIB::sysDescr.0 + +"""# +from pysnmp.entity.rfc3413.oneliner.cmdgen import * + +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + UsmUserData('usr-sha-aes', 'authkey1', 'privkey1', + authProtocol=usmHMACSHAAuthProtocol, + privProtocol=usmAesCfb128Protocol), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py index aca41293..2e9c298c 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v1-get.py @@ -1,35 +1,37 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv1, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for two instances of SNMPv2-MIB::sysDescr.0 MIB object, -# * one in label and another in MIB symbol form -# +""" +SNMPv1 +++++++ + +Send SNMP GET request using the following options: + + * with SNMPv1, community 'public' + * over IPv4/UDP + * to an Agent at demo.snmplabs.com:161 + * for two instances of SNMPv2-MIB::sysDescr.0 MIB object, + +Functionally similar to: + +| $ snmpget -v1 -c public demo.snmplabs.com SNMPv2-MIB::sysDescr.0 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), - lookupNames=True, lookupValues=True): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + CommunityData('public', mpModel=0), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py index 5fe5bfe9..dcc4ccf8 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-get.py @@ -1,34 +1,39 @@ -# -# Command Generator -# -# Send SNMP GET request using the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for two OIDs in string form -# +""" +SNMPv2c ++++++++ + +Send SNMP GET request using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for two OIDs in string form + +Functionally similar to: + +| $ snmpget -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1.1.0 \ +| 1.3.6.1.2.1.1.6.0 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * -for errorIndication, \ - errorStatus, errorIndex, \ - varBinds in getCmd(SnmpEngine(), - CommunityData('public'), - UdpTransportTarget(('demo.snmplabs.com', 161)), - ContextData(), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0'))): - # Check for errors and print out results - if errorIndication: - print(errorIndication) - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) - ) - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) - break +errorIndication, errorStatus, errorIndex, varBinds = next( + getCmd(SnmpEngine(), + CommunityData('public'), + UdpTransportTarget(('demo.snmplabs.com', 161)), + ContextData(), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')), + ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0'))) +) + +if errorIndication: + print(errorIndication) +elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' + ) + ) +else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py index 0bed0f08..bf167e45 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/v2c-getbulk.py @@ -1,15 +1,23 @@ -# -# Command Generator -# -# Send SNMP GETBULK request using the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * with values non-repeaters = 0, max-repetitions = 25 -# * for two OIDs in string form -# * stop when response OIDs leave the scopes of initial OIDs -# +""" +Bulk walk MIB ++++++++++++++ + +Send a series of SNMP GETBULK requests using the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* with values non-repeaters = 0, max-repetitions = 25 +* for two OIDs in string form +* stop when response OIDs leave the scopes of initial OIDs + +Functionally similar to: + +| $ snmpbulkwalk -v2c -c public demo.snmplabs.com \ +| -Cn0 -Cr25 \ +| 1.3.6.1.2.1.2.2 1.3.6.1.2.1.2.3 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -20,19 +28,19 @@ for errorIndication, \ ContextData(), 0, 25, ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2')), - ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3'))): - # Check for errors and print out results + ObjectType(ObjectIdentity('1.3.6.1.2.1.2.3')), + lexicographicMode=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py b/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py index e59b07bd..427c964e 100644 --- a/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py +++ b/examples/hlapi/asyncore/sync/manager/cmdgen/waive-mib-lookup.py @@ -1,25 +1,24 @@ -# -# GETNEXT Command Generator Application -# -# Perform SNMP GETNEXT operation with the following options: -# -# * with SNMPv2c, community 'public' -# * over IPv4/UDP -# * to an Agent at demo.snmplabs.com:161 -# * for an OID in string form -# * resolve response OIDs and values into human-freidly form -# * stop when response OIDs leave the scopes of initial OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpwalk -v2c -c public demo.snmplabs.com 1.3.6.1.2.1.1 -# -# The lookupNames and lookupValues keyword arguments will make pysnmp -# trying to resolve OIDs and values, in response variable-bindings, -# into human-friendly form. If response OIDs do not belong to any of -# currently loaded MIBs, unresolved OIDs and values will still be -# returned. -# +""" +Waive MIB lookup +++++++++++++++++ + +Perform SNMP GETNEXT operation with the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at demo.snmplabs.com:161 +* for an OID in string form +* do not resolve response OIDs and values into human-freidly form + +False lookupMib keyword arguments could make pysnmp waiving +OIDs and values resolution in response variable-bindings, into human +friendly form. + +Functionally similar to: + +| $ snmpwalk -v2c -c public -ObentU demo.snmplabs.com 1.3.6.1.2.1 + +"""# from pysnmp.entity.rfc3413.oneliner.cmdgen import * for errorIndication, \ @@ -29,19 +28,18 @@ for errorIndication, \ UdpTransportTarget(('demo.snmplabs.com', 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6.1.2.1.1')), - lookupNames=True, lookupValues=True): - # Check for errors and print out results + lookupMib=False): + if errorIndication: print(errorIndication) break - else: - if errorStatus: - print('%s at %s' % ( - errorStatus.prettyPrint(), - errorIndex and varBinds[int(errorIndex)-1][0] or '?' - ) + elif errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBinds[int(errorIndex)-1][0] or '?' ) - break - else: - for varBind in varBinds: - print(' = '.join([ x.prettyPrint() for x in varBind ])) + ) + break + else: + for varBind in varBinds: + print(' = '.join([ x.prettyPrint() for x in varBind ])) diff --git a/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py b/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py index 1007a475..5119a159 100644 --- a/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py +++ b/examples/v1arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py @@ -1,4 +1,24 @@ -# Command Responder Application (GET/GETNEXT) +""" +Implementing scalar MIB objects ++++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/GETNEXT queries with the following options: + +* SNMPv1 or SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:161 +* over IPv6/UDP, listening at [::1]:161 +* serving two Managed Objects Instances (sysDescr.0 and sysUptime.0) + +Either of the following Net-SNMP commands will walk this Agent: + +| $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 +| $ snmpwalk -v2c -c public udp6:[::1] .1.3.6 + +The Command Receiver below uses two distinct transports for communication +with Command Generators - UDP over IPv4 and UDP over IPv6. + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp, udp6, unix from pyasn1.codec.ber import encoder, decoder diff --git a/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py b/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py index 66c8a53f..e0be25a8 100644 --- a/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py +++ b/examples/v1arch/asyncore/agent/ntforg/send-trap-over-ipv4-and-ipv6.py @@ -1,4 +1,27 @@ -# Notification Originator Application (TRAP) +""" +TRAP over multiple transports ++++++++++++++++++++++++++++++ + +The following script sends two SNMP TRAP notification using the +following options: + +* with SNMPv1 +* with community name 'public' +* over IPv4/UDP and IPv6/UDP +* send TRAP notification +* to a Manager at 127.0.0.1:162 and [::1] +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: +* with default Uptime value +* with default Agent Address with '127.0.0.1' +* overriding Enterprise OID with 1.3.6.1.4.1.20408.4.1.1.2 + +The following Net-SNMP commands will produce similar SNMP notification: + +| $ snmptrap -v1 -c public udp:127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 0 12345 +| $ snmptrap -v1 -c public udp6:[::1] 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 0 12345 + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp, udp6, unix from pyasn1.codec.ber import encoder diff --git a/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py b/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py index 2ac0f181..cd8c3c99 100644 --- a/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py +++ b/examples/v1arch/asyncore/manager/cmdgen/broadcast-agent-discovery.py @@ -1,3 +1,25 @@ +""" +Broadcast SNMP message (IPv4) ++++++++++++++++++++++++++++++ + +Send SNMP GET request to broadcast address and wait for respons(es): + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to all Agents via broadcast address 255.255.255.255:161 +* for OIDs in tuple form + +Here we send out a single SNMP request and wait for potentially many SNMP +responses from multiple SNMP Agents listening in local broadcast domain. +Since we can't predict the exact number of Agents responding, this script +just waits for arbitrary time for collecting all responses. This technology +is also known as SNMP-based discovery. + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v2c -c public -ObentU 255.255.255.255 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.3.0 + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp from pyasn1.codec.ber import encoder, decoder diff --git a/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py b/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py index a44707ea..e7fa029b 100644 --- a/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py +++ b/examples/v1arch/asyncore/manager/cmdgen/fetch-scalar-value.py @@ -1,4 +1,19 @@ -# GET Command Generator +""" +Fetch scalar MIB variables (SNMPv1) ++++++++++++++++++++++++++++++++++++ + +Perform SNMP GET operation with the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for OIDs in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.3.0 + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp, udp6, unix from pyasn1.codec.ber import encoder, decoder diff --git a/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py b/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py index d4c7ca75..8ba9af62 100644 --- a/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py +++ b/examples/v1arch/asyncore/manager/cmdgen/getbulk-pull-whole-mib.py @@ -1,4 +1,20 @@ -# GETBULK Command Generator (SNMPv2c only) +""" +Bulk walk Agent MIB (SNMPv2c) ++++++++++++++++++++++++++++++ + +Perform SNMP GETBULK operation with the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for OID in tuple form +* with non-repeaters=0 and max-repeaters=25 + +This script performs similar to the following Net-SNMP command: + +| $ snmpbulkwalk -v2c -c public -ObentU -Cn0 -Cr25 195.218.195.228 1.3.6 + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp from pyasn1.codec.ber import encoder, decoder diff --git a/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py b/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py index d0cefc37..b3e16f19 100644 --- a/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py +++ b/examples/v1arch/asyncore/manager/cmdgen/getnext-pull-whole-mib.py @@ -1,4 +1,19 @@ -# GETNEXT Command Generator +""" +Walk Agent MIB (SNMPv1) ++++++++++++++++++++++++ + +Perform SNMP GETNEXT operation with the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for OID in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6 + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp from pyasn1.codec.ber import encoder, decoder diff --git a/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py b/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py index acaefacb..16009ab8 100644 --- a/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py +++ b/examples/v1arch/asyncore/manager/cmdgen/spoof-source-address.py @@ -1,3 +1,33 @@ +""" +Spoof IPv4 source address ++++++++++++++++++++++++++ + +Send SNMP GET request from a non-local IP address: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* from a non-local, spoofed IP 1.2.3.4 (root and Python 3.3+ required) +* for OIDs in string form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0 1.3.6.1.2.1.1.3.0 + +But unlike the above command, this script issues SNMP request from a +non-default, non-local IP address. + +It is indeed possible to originate SNMP traffic from any valid local IP +addresses. It could be a secondary IP interface, for instance. Superuser +privileges are only required to send spoofed packets. Alternatively, +sending from local interface could also be achieved by binding to +it (via openClientMode() parameter). + +Agent would respond to the IP address you used as a source. So this script +could only get a response if that source address is somehow routed to the +host this script is running on. Otherwise it just times out. + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp from pysnmp.proto import api diff --git a/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py b/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py index f7c22bbd..a30bebb6 100644 --- a/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py +++ b/examples/v1arch/asyncore/manager/cmdgen/v2c-set.py @@ -1,4 +1,19 @@ -# SET Command Generator +""" +SET string and integer scalars (SNMPv2c) +++++++++++++++++++++++++++++++++++++++++ + +Perform SNMP SET operation with the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for OIDs in string form and values in form of pyasn1 objects + +This script performs similar to the following Net-SNMP command: + +| $ snmpset -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.9.1.3.1 s 'New description' 1.3.6.1.2.1.1.9.1.4.1 t 12 + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp from pyasn1.codec.ber import encoder, decoder diff --git a/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py b/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py index 3a1b0266..b9073cf2 100644 --- a/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py +++ b/examples/v1arch/asyncore/manager/ntfrcv/listen-on-ipv4-and-ipv6-interfaces.py @@ -1,4 +1,25 @@ -# Notification Receiver (TRAP PDU) +""" +Listen for notifications at IPv4 & IPv6 interfaces +++++++++++++++++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:162 +* over IPv6/UDP, listening at [::1]:162 +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test +| $ snmptrap -v2c -c public udp6:[::1] 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test + +Notification Receiver below uses two different transports for communication +with Notification Originators - UDP over IPv4 and UDP over IPv6. + +"""# from pysnmp.carrier.asyncore.dispatch import AsyncoreDispatcher from pysnmp.carrier.asyncore.dgram import udp, udp6, unix from pyasn1.codec.ber import decoder diff --git a/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py b/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py index cdc264b5..b0b7e5bd 100644 --- a/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py +++ b/examples/v3arch/asyncio/agent/cmdrsp/multiple-usm-users.py @@ -1,25 +1,28 @@ -# -# 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 -# * using asyncio network transport (available since Python 3.4) -# -# 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 -# -# Requires Python 3.4 and later! -# +""" +Multiple SNMP USM users ++++++++++++++++++++++++ + +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 + - 'usr-sha-none', auth: SHA, no privacy + - '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 +* using asyncio network transport (available since Python 3.4) + +Either of the following Net-SNMP 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 + +Requires Python 3.4 and later! + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncio.dgram import udp diff --git a/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py b/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py index a5fa2417..30dc5111 100644 --- a/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py +++ b/examples/v3arch/asyncio/manager/ntfrcv/multiple-interfaces.py @@ -1,23 +1,25 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with SNMP community "public" -# * over IPv4/UDP, listening at 127.0.0.1:162 -# over IPv4/UDP, listening at 127.0.0.1:2162 -# * using Asyncio framework for network transport -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test -# $ snmpinform -v2c -c public 127.0.0.1:2162 123 1.3.6.1.6.3.1.1.5.1 -# -# Requires Python 3.4 and later! -# +""" +Serving multiple network interfaces ++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:162 + over IPv4/UDP, listening at 127.0.0.1:2162 +* using Asyncio framework for network transport +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test +| $ snmpinform -v2c -c public 127.0.0.1:2162 123 1.3.6.1.6.3.1.1.5.1 + +Requires Python 3.4 and later! + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncio.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py b/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py index eabb989a..fa3bc6b5 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/alternative-mib-tree.py @@ -1,21 +1,23 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv3 -# * with USM username usr-md5-none -# * using alternative set of Managed Objects addressed by -# contextEngineId: 8000000001020304, contextName: my-context -# * 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-none -l authNoPriv -A authkey1 -E 8000000001020304 -n my-context 127.0.0.1 .1.3.6 -# $ snmpwalk -v3 -u usr-md5-none -l authNoPriv -A authkey1 -E 8000000001020304 127.0.0.1 .1.3.6 -# +""" +Serve non-default MIB tree +++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv3 +* with USM username usr-md5-none +* using alternative set of Managed Objects addressed by + contextEngineId: 8000000001020304, contextName: my-context +* 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 commands will walk this Agent: + +| $ snmpwalk -v3 -u usr-md5-none -l authNoPriv -A authkey1 -E 8000000001020304 -n my-context 127.0.0.1 .1.3.6 +| $ snmpwalk -v3 -u usr-md5-none -l authNoPriv -A authkey1 -E 8000000001020304 127.0.0.1 .1.3.6 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py index 5fe26a7b..1711133d 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py @@ -1,20 +1,22 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv3 -# * with USM username usr-none-none -# * using alternative set of Managed Objects addressed by -# contextName: my-context -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 -# -# The following Net-SNMP's command will send GET request to this Agent: -# -# $ snmpget -v3 -u usr-none-none -l noAuthNoPriv -n my-context -Ir 127.0.0.1 sysDescr.0 -# +""" +Custom MIB Controller ++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv3 +* with USM username usr-none-none +* using alternative set of Managed Objects addressed by + contextName: my-context +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 + +The following Net-SNMP command will send GET request to this Agent: + +| $ snmpget -v3 -u usr-none-none -l noAuthNoPriv -n my-context -Ir 127.0.0.1 sysDescr.0 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py b/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py index 4a58de34..e2452ca3 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/custom-snmp-engine-id.py @@ -1,19 +1,21 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv3 -# * with SNMP EngineID: 8000000004030201 -# * with USM user 'usr-md5-des', auth: MD5, priv DES -# * 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 -e 8000000004030201 localhost .1.3.6 -# +""" +Specific SNMP Engine ID ++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv3 +* with SNMP EngineID: 8000000004030201 +* with USM user 'usr-md5-des', auth: MD5, priv DES +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 + +The following Net-SNMP command will walk this Agent: + +| $ snmpwalk -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -e 8000000004030201 localhost .1.3.6 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py b/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py index 47610384..196ee9c2 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/implementing-scalar-mib-objects.py @@ -1,19 +1,21 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv2c -# * with SNMP community "public" -# * serving custom Managed Object Instance defined within this script -# * allow read access only to the subtree where the custom MIB object resides -# * over IPv4/UDP, listening at 127.0.0.1:161 -# -# Either of the following Net-SNMP's commands will walk this Agent: -# -# $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 -# +""" +Implementing scalar MIB objects ++++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv2c +* with SNMP community "public" +* serving custom Managed Object Instance defined within this script +* allow read access only to the subtree where the custom MIB object resides +* over IPv4/UDP, listening at 127.0.0.1:161 + +The following Net-SNMP commands will walk this Agent: + +| $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 + +"""# import sys from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context diff --git a/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py b/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py index 9bb49205..bf6d0423 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/implementing-snmp-table.py @@ -1,28 +1,29 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv2c -# * with SNMP community "public" -# * define a simple SNMP Table within a newly created EXAMPLE-MIB -# * pre-populate SNMP Table with a single row of values -# * allow read access only to the subtree where example SNMP Table resides -# * over IPv4/UDP, listening at 127.0.0.1:161 -# -# -# The following Net-SNMP's commands will populate and walk a table: -# -# $ snmpset -v2c -c public 127.0.0.1 1.3.6.6.1.5.2.97.98.99 s 'my value' -# $ snmpset -v2c -c public 127.0.0.1 1.3.6.6.1.5.4.97.98.99 i 4 -# $ snmpwalk -v2c -c public 127.0.0.1 1.3.6 -# -# ...while the following command will destroy the same row -# -# $ snmpset -v2c -c public 127.0.0.1 1.3.6.6.1.5.4.97.98.99 i 6 -# $ snmpwalk -v2c -c public 127.0.0.1 1.3.6 -# +""" +Implementing conceptual table ++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv2c +* with SNMP community "public" +* define a simple SNMP Table within a newly created EXAMPLE-MIB +* pre-populate SNMP Table with a single row of values +* allow read access only to the subtree where example SNMP Table resides +* over IPv4/UDP, listening at 127.0.0.1:161 + +The following Net-SNMP commands will populate and walk a table: + +| $ snmpset -v2c -c public 127.0.0.1 1.3.6.6.1.5.2.97.98.99 s 'my value' +| $ snmpset -v2c -c public 127.0.0.1 1.3.6.6.1.5.4.97.98.99 i 4 +| $ snmpwalk -v2c -c public 127.0.0.1 1.3.6 + +...while the following command will destroy the same row + +| $ snmpset -v2c -c public 127.0.0.1 1.3.6.6.1.5.4.97.98.99 i 6 +| $ snmpwalk -v2c -c public 127.0.0.1 1.3.6 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py index f9115e77..24de0618 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-ipv4-and-ipv6-interfaces.py @@ -1,20 +1,22 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv2c -# * with SNMP community "public" -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 and -# over IPv6/UDP, listening at [::1]:161 -# -# Either of the following Net-SNMP's commands will walk this Agent: -# -# $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 -# $ snmpwalk -v2c -c public udp6:[::1] .1.3.6 -# +""" +Serve multiple network transports ++++++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv2c +* with SNMP community "public" +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 and + over IPv6/UDP, listening at [::1]:161 + +Either of the following Net-SNMP commands will walk this Agent: + +| $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 +| $ snmpwalk -v2c -c public udp6:[::1] .1.3.6 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp, udp6 diff --git a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py index 8d67802c..25beef3f 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/listen-on-multiple-interfaces.py @@ -1,19 +1,21 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv2c -# * with SNMP community "public" -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 and 127.0.0.2:161 interfaces -# -# Either of the following Net-SNMP's commands will walk this Agent: -# -# $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 -# $ snmpwalk -v2c -c public 127.0.0.2 .1.3.6 -# +""" +Listen on multiple network interfaces ++++++++++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv2c +* with SNMP community "public" +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 and 127.0.0.2:161 interfaces + +Either of the following Net-SNMP commands will walk this Agent: + +| $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 +| $ snmpwalk -v2c -c public 127.0.0.2 .1.3.6 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py b/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py index 55e282f4..1e862706 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/listening-on-virtual-network-interface.py @@ -1,35 +1,37 @@ -# -# Command Responder -# -# Listen on all local IPv4 interfaces respond to SNMP GET/SET/GETNEXT/GETBULK -# queries with the following options: -# -# * SNMPv3 -# * with USM user 'usr-md5-des', auth: MD5, priv DES -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 0.0.0.0:161 -# * preserve local IP address when responding (Python 3.3+ required) -# -# The following Net-SNMP's command will walk this Agent: -# -# $ snmpwalk -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 localhost .1.3.6 -# -# In the situation when UDP responder receives a datagram targeted to -# a secondary (AKA virtial) IP interface or a non-local IP interface -# (e.g. routed through policy routing or iptables TPROXY facility), -# OS stack will by default put primary local IP interface address into -# the IP source field of the response IP packet. Such datagram may not -# reach the sender as either the sender itself or a stateful firewall -# somewhere in between would not be able to match response to original -# request. -# -# The following script solves this problem by preserving original request -# destination IP address and put it back into response IP packet's source -# address field. -# -# To respond from a non-local (e.g. spoofed) IP address, uncomment the -# .enableTransparent() method call and run this script as root. -# +""" +Running at secondary network interface +++++++++++++++++++++++++++++++++++++++ + +Listen on all local IPv4 interfaces respond to SNMP GET/SET/GETNEXT/GETBULK +queries with the following options: + +* SNMPv3 +* with USM user 'usr-md5-des', auth: MD5, priv DES +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 0.0.0.0:161 +* preserve local IP address when responding (Python 3.3+ required) + +The following Net-SNMP command will walk this Agent: + +| $ snmpwalk -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 localhost .1.3.6 + +In the situation when UDP responder receives a datagram targeted to +a secondary (AKA virtial) IP interface or a non-local IP interface +(e.g. routed through policy routing or iptables TPROXY facility), +OS stack will by default put primary local IP interface address into +the IP source field of the response IP packet. Such datagram may not +reach the sender as either the sender itself or a stateful firewall +somewhere in between would not be able to match response to original +request. + +The following script solves this problem by preserving original request +destination IP address and put it back into response IP packet's source +address field. + +To respond from a non-local (e.g. spoofed) IP address, uncomment the +.enableTransparent() method call and run this script as root. + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py index d7e3a4d0..5780025f 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-communities.py @@ -1,19 +1,22 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT queries with -# the following options: -# -# * SNMPv1 -# * with SNMP community "public" (read access) or "private" (write access) -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 -# -# The following Net-SNMP's commands will GET/SET a value at this Agent: -# -# $ snmpget -v1 -c public 127.0.0.1 SNMPv2-MIB::sysLocation.0 -# $ snmpset -v1 -c private 127.0.0.1 SNMPv2-MIB::sysLocation.0 s "far away" -# +""" +Multiple SNMP communities ++++++++++++++++++++++++++ + +Respond to SNMP GET/SET/GETNEXT queries with the following options: + +* SNMPv1 +* with SNMP community "public" (read access) or "private" (write access) +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 + +Allow read/write access to all objects in the same MIB subtree. + +The following Net-SNMP's commands will GET/SET a value at this Agent: + +| $ snmpget -v1 -c public 127.0.0.1 SNMPv2-MIB::sysLocation.0 +| $ snmpset -v1 -c private 127.0.0.1 SNMPv2-MIB::sysLocation.0 s "far away" + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py index 870363a5..0a7b3a20 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/multiple-snmp-engines.py @@ -1,28 +1,30 @@ -# -# Multiple Command Responders -# -# Run multiple SNMP Engines each with a complete Command Responder. -# Bind each SNMP Engine to a dedicated network transport endpoint: -# -# * IPv4/UDP, listening at 127.0.0.1:161 -# * IPv4/UDP, listening at 127.0.0.2:161 -# -# Each Command Responder will respond to SNMP GET/SET/GETNEXT/GETBULK -# queries with the following options: -# -# * SNMPv3 -# * with USM user 'usr-md5-des', auth: MD5, priv DES -# * allow read access to SNMPv2-MIB objects (1.3.6) -# * allow write access to SNMPv2-MIB objects (1.3.6.1.2.1) -# -# The following Net-SNMP commands will walk the first and the second -# Agent respectively: -# -# $ snmpwalk -Ob -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 127.0.0.1 usmUserEntry -# $ snmpwalk -Ob -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 127.0.0.2 usmUserEntry -# -# Notice differently configured snmpEngineId's in usmUserEntry columns. -# +""" +Multiple SNMP Engines ++++++++++++++++++++++ + +Run multiple SNMP Engines each with a complete Command Responder. +Bind each SNMP Engine to a dedicated network transport endpoint: + +* IPv4/UDP, listening at 127.0.0.1:161 +* IPv4/UDP, listening at 127.0.0.2:161 + +Each Command Responder will respond to SNMP GET/SET/GETNEXT/GETBULK +queries with the following options: + +* SNMPv3 +* with USM user 'usr-md5-des', auth: MD5, priv DES +* allow read access to SNMPv2-MIB objects (1.3.6) +* allow write access to SNMPv2-MIB objects (1.3.6.1.2.1) + +The following Net-SNMP commands will walk the first and the second +Agent respectively: + +| $ snmpwalk -Ob -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 127.0.0.1 usmUserEntry +| $ snmpwalk -Ob -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 127.0.0.2 usmUserEntry + +Notice differently configured snmpEngineId's in usmUserEntry columns. + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.proto import rfc1902 diff --git a/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py b/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py index 1f11a58f..150a0f48 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/multiple-usm-users.py @@ -1,22 +1,24 @@ -# -# 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 -# +""" +Multiple SNMP USM users ++++++++++++++++++++++++ + +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 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 pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py b/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py index 53dad9a5..d03c52c1 100644 --- a/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py +++ b/examples/v3arch/asyncore/agent/cmdrsp/observe-request-processing.py @@ -1,23 +1,25 @@ -# -# 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 -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 -# * registers its own execution observer to snmpEngine -# -# The following Net-SNMP's command will walk this Agent: -# -# $ snmpwalk -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 localhost .1.3.6 -# -# This script will report some details on request processing as seen -# by rfc3412.receiveMessage() and rfc3412.returnResponsePdu() -# abstract interfaces. -# +""" +Observe SNMP engine operations +++++++++++++++++++++++++++++++ + +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 +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 +* registers its own execution observer to snmpEngine + +The following Net-SNMP command will walk this Agent: + +| $ snmpwalk -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 localhost .1.3.6 + +This script will report some details on request processing as seen +by rfc3412.receiveMessage() and rfc3412.returnResponsePdu() +abstract interfaces. + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py b/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py index d8093ade..ab5f6413 100644 --- a/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py +++ b/examples/v3arch/asyncore/agent/ntforg/multiple-different-notifications-at-once.py @@ -1,21 +1,31 @@ -# -# Notification Originator -# -# Send SNMP INFORM notifications to multiple Managers using the -# following options: -# -# * SNMPv2c -# * with community name 'public' -# * AND -# * SNMPv3 -# * with user 'usr-md5-none', auth: MD5, priv NONE -# * over IPv4/UDP -# * send INFORM notification -# * to multiple Managers at 127.0.0.1:162, 127.0.0.2:162 -# * with TRAP ID 'coldStart' specified as an OID -# * include managed objects information: -# 1.3.6.1.2.1.1.1.0 = 'Example Notificator' -# +""" +Notification over multiple SNMP versions +++++++++++++++++++++++++++++++++++++++++ + +Send SNMP INFORM notifications to multiple Managers using different +security settings: + +* SNMPv2c +* with community name 'public' +* AND +* SNMPv3 +* with user 'usr-md5-none', auth: MD5, priv NONE +* over IPv4/UDP +* send INFORM notification +* to multiple Managers at 127.0.0.1:162, 127.0.0.2:162 +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: + 1.3.6.1.2.1.1.1.0 = 'Example Notificator' + +Functionally similar to: + +| $ snmpinform -v3 -l authPriv -u usr-md5-none -A authkey1 127.0.0.1 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' + +and + +| $ snmpinform -v2c -c public 127.0.0.2 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/send-custom-pdu.py b/examples/v3arch/asyncore/agent/ntforg/send-custom-pdu.py index f1e67e86..10517547 100644 --- a/examples/v3arch/asyncore/agent/ntforg/send-custom-pdu.py +++ b/examples/v3arch/asyncore/agent/ntforg/send-custom-pdu.py @@ -1,17 +1,23 @@ -# -# Notification Originator -# -# Send SNMP TRAP notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * to a Manager at 127.0.0.1:162 -# * initialize TRAP PDU with the following var-binds: -# 1.3.6.1.2.1.1.3.0 = 123 -# 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1 -# +""" +Send crafted TRAP PDU ++++++++++++++++++++++ + +Initialize TRAP PDU and pass it over to unified SNMPv3 message processing +framework for further treatment. + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* initialize TRAP PDU with the following var-binds: + 1.3.6.1.2.1.1.3.0 = 123 + 1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1 + +Functionally similar to: + +| $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.6.3.1.1.5.1 0.0.0.0 1 0 123 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py b/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py index 5b994cf3..ce82f60c 100644 --- a/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py +++ b/examples/v3arch/asyncore/agent/ntforg/send-inform-to-multiple-managers.py @@ -1,19 +1,33 @@ -# -# Notification Originator -# -# Send SNMP TRAP notifications to multiple Managers using the -# following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * to multiple Managers at 127.0.0.1:162, 127.0.0.2:162 -# * with TRAP ID 'coldStart' specified as an OID -# * include managed objects information: -# 1.3.6.1.2.1.1.1.0 = 'Example Notificator' -# 1.3.6.1.2.1.1.5.0 = 'Notificator Example' -# +""" +Notification to multiple addresses +++++++++++++++++++++++++++++++++++ + +Send SNMP TRAP notifications to multiple Managers using different +security settings: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* to multiple Managers at 127.0.0.1:162, 127.0.0.2:162 +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: + 1.3.6.1.2.1.1.1.0 = 'Example Notificator' + 1.3.6.1.2.1.1.5.0 = 'Notificator Example' + +Functionally similar to: + +| $ snmptrap -v2c -c public 127.0.0.1 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' 1.3.6.1.2.1.1.5.0 s 'Notificator Example' + +and + +| $ snmptrap -v2c -c public 127.0.0.2 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' 1.3.6.1.2.1.1.5.0 s 'Notificator Example' + +and + +| $ snmptrap -v2c -c public 127.0.0.3 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' 1.3.6.1.2.1.1.5.0 s 'Notificator Example' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py b/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py index e8b674d6..1c93e620 100644 --- a/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py +++ b/examples/v3arch/asyncore/agent/ntforg/send-notification-over-ipv4-and-ipv6.py @@ -1,18 +1,29 @@ -# -# Notification Originator -# -# Send SNMP TRAP notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP and UDP/IPv6 -# * send TRAP notification -# * to two Managers through different network transports -# * with TRAP ID 'coldStart' specified as an OID -# * include managed objects information: -# 1.3.6.1.2.1.1.1.0 = 'Example Notificator' -# 1.3.6.1.2.1.1.5.0 = 'Notificator Example' -# +""" +Notification over multiple network protocols +++++++++++++++++++++++++++++++++++++++++++++ + +Send SNMP INFORM notifications to multiple Managers over different +network protocols: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP and UDP/IPv6 +* send TRAP notification +* to two Managers through different network transports +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: + 1.3.6.1.2.1.1.1.0 = 'Example Notificator' + 1.3.6.1.2.1.1.5.0 = 'Notificator Example' + +Functionally similar to: + +| $ snmptrap -v2c -c public udp:127.0.0.1 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' 1.3.6.1.2.1.1.5.0 s 'Notificator Example' + +and + +| $ snmptrap -v2c -c public udp6:[::1] 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example notification' 1.3.6.1.2.1.1.5.0 s 'Notificator Example' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp, udp6 from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py b/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py index b99389ab..c7dfedb4 100644 --- a/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py +++ b/examples/v3arch/asyncore/agent/ntforg/send-packet-from-specific-address.py @@ -1,16 +1,22 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv1 -# * with community name 'public' -# * over IPv4/UDP -# * to a Manager at 127.0.0.1 UDP port 162 -# * from local address 127.0.0.1, UDP port 61024 -# * send TRAP notification -# * with TRAP ID 'coldStart' specified as an OID -# +""" +Send packet from specific network interface/port +++++++++++++++++++++++++++++++++++++++++++++++++ + +Send SNMP notification using the following options: + +* SNMPv1 +* with community name 'public' +* over IPv4/UDP +* to a Manager at 127.0.0.1 UDP port 162 +* from local address 127.0.0.1, UDP port 61024 +* send TRAP notification +* with TRAP ID 'coldStart' specified as an OID + +Functionally similar to: + +| $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.6.3.1.1.5.1 0.0.0.0 1 0 0 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg @@ -20,7 +26,8 @@ from pysnmp.proto.api import v2c snmpEngine = engine.SnmpEngine() # SecurityName <-> CommunityName mapping -config.addV1System(snmpEngine, 'my-area', 'public', transportTag='all-my-managers') +config.addV1System(snmpEngine, 'my-area', 'public', + transportTag='all-my-managers') # Specify security settings per SecurityName (SNMPv1 -> 0) config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 0) diff --git a/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py b/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py index 6a888dfb..116d6794 100644 --- a/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py +++ b/examples/v3arch/asyncore/agent/ntforg/usm-md5-none.py @@ -1,16 +1,22 @@ -# -# Notification Originator -# -# Send SNMP INFORM notification using the following options: -# -# * SNMPv3 -# * with user 'usr-md5-none', auth: MD5, priv NONE -# * over IPv4/UDP -# * to a Manager at 127.0.0.1:162 -# * send INFORM notification -# * with TRAP ID 'warmStart' specified as an OID -# * include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' -# +""" +SNMPv3 INFORM, auth: MD5, privacy: none ++++++++++++++++++++++++++++++++++++++++ + +Send SNMP INFORM notification using the following options: + +* SNMPv3 +* with user 'usr-md5-none', auth: MD5, priv NONE +* over IPv4/UDP +* to a Manager at 127.0.0.1:162 +* send INFORM notification +* with TRAP ID 'warmStart' specified as an OID +* include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' + +Functionally similar to: + +| $ snmpinform -v3 -l authNoPriv -u usr-md5-none -A authkey1 demo.snmplabs.com 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 = 'system name' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/v1-trap.py b/examples/v3arch/asyncore/agent/ntforg/v1-trap.py index 83500f24..226788a7 100644 --- a/examples/v3arch/asyncore/agent/ntforg/v1-trap.py +++ b/examples/v3arch/asyncore/agent/ntforg/v1-trap.py @@ -1,28 +1,30 @@ -# -# Notification Originator -# -# Send SNMP notification using the following options: -# -# * SNMPv1 -# * with community name 'public' -# * over IPv4/UDP -# * to a Manager at 127.0.0.1:162 -# * send TRAP notification -# * with TRAP ID 'coldStart' specified as an OID -# * include managed objects information: -# * overriding Uptime value with 12345 -# * overriding Agent Address with '127.0.0.1' -# * overriding Enterprise OID with 1.3.6.1.4.1.20408.4.1.1.2 -# * include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' -# +""" +SNMPv1 TRAP ++++++++++++ + +Send SNMP notification using the following options: + +* SNMPv1 +* with community name 'public' +* over IPv4/UDP +* to a Manager at 127.0.0.1:162 +* send TRAP notification +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: +* overriding Uptime value with 12345 +* overriding Agent Address with '127.0.0.1' +* overriding Enterprise OID with 1.3.6.1.4.1.20408.4.1.1.2 +* include managed object information '1.3.6.1.2.1.1.1.0' = 'my system' + +Functionally similar to: + +| $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 6 432 12345 1.3.6.1.2.1.1.1.0 s 'my system' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c -#from pysnmp import debug - -# Optional debugging ('all' enables full debugging) -#debug.setLogger(debug.Debug('acl', 'io', 'dsp', 'msgproc', 'secmod', 'app')) # Create SNMP engine instance snmpEngine = engine.SnmpEngine() diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py b/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py index dd10f851..026d36ff 100644 --- a/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py +++ b/examples/v3arch/asyncore/agent/ntforg/v2c-inform.py @@ -1,18 +1,24 @@ -# -# Notification Originator -# -# Send SNMP INFORM notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send INFORM notification -# * to a Manager at 127.0.0.1:162 -# * with TRAP ID 'coldStart' specified as an OID -# * include managed objects information: -# 1.3.6.1.2.1.1.1.0 = 'Example Notificator' -# 1.3.6.1.2.1.1.5.0 = 'Notificator Example' -# +""" +INFORM notification ++++++++++++++++++++ + +Send SNMP INFORM notification using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send INFORM notification +* to a Manager at 127.0.0.1:162 +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: + 1.3.6.1.2.1.1.1.0 = 'Example Notificator' + 1.3.6.1.2.1.1.5.0 = 'Notificator Example' + +Functionally similar to: + +| $ snmpinform -v2c -c public demo.snmplabs.com 12345 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.1.0 s 'Example Notificator' 1.3.6.1.2.1.1.5.0 s 'Notificator Example' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg @@ -37,7 +43,7 @@ config.addTransport( ) config.addTargetAddr( snmpEngine, 'my-nms', - udp.domainName, ('127.0.0.1', 162), + udp.domainName, ('195.218.195.228', 162), 'my-creds', tagList='all-my-managers' ) diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py b/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py index 4124a393..b72c5a7d 100644 --- a/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py +++ b/examples/v3arch/asyncore/agent/ntforg/v2c-trap-via-notification-type.py @@ -1,27 +1,31 @@ -# -# Notification Originator -# -# Send SNMP TRAP notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * to a Manager at 127.0.0.1:162 -# * with TRAP ID IF-MIB::ifLink as MIB symbol -# -# The IF-MIB::ifLink NOTIFICATION-TYPE implies including four other -# var-binds into the notification message describing the incident -# occurred. These var-binds are: -# IF-MIB::ifIndex."x" -# IF-MIB::ifAdminStatus."x" -# IF-MIB::ifOperStatus."x" -# IF-MIB::ifDescr."x" -# -# Where "x" is MIB table index (instance index). -# -# To run this example make sure to have IF-MIB.py in search path. -# +""" +Sending notification with OBJECT's +++++++++++++++++++++++++++++++++++ + +Send SNMP TRAP notification using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* to a Manager at 127.0.0.1:162 +* with TRAP ID IF-MIB::ifLink as MIB symbol + +The IF-MIB::ifLink NOTIFICATION-TYPE implies including four other +var-binds into the notification message describing the incident +occurred. These var-binds are: +IF-MIB::ifIndex."x" +IF-MIB::ifAdminStatus."x" +IF-MIB::ifOperStatus."x" +IF-MIB::ifDescr."x" + +Where "x" is MIB table index (instance index). + +Functionally similar to: + +| $ snmptrap -v2c -c public 127.0.0.1 0 1.3.6.1.6.3.1.1.5.3 IF-MIB::ifIndex."1" IF-MIB::ifAdminStatus."1" IF-MIB::ifOperStatus."1" IF-MIB::ifDescr."1" + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py b/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py index 1ada77b9..2a926d88 100644 --- a/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py +++ b/examples/v3arch/asyncore/agent/ntforg/v2c-trap.py @@ -1,18 +1,24 @@ -# -# Notification Originator -# -# Send SNMP TRAP notification using the following options: -# -# * SNMPv2c -# * with community name 'public' -# * over IPv4/UDP -# * send TRAP notification -# * to a Manager at 127.0.0.1:162 -# * with TRAP ID 'coldStart' specified as an OID -# * include managed objects information: -# 1.3.6.1.2.1.1.1.0 = 'Example Notificator' -# 1.3.6.1.2.1.1.5.0 = 'Notificator Example' -# +""" +SNMPv2c TRAP +++++++++++++ + +Send SNMP TRAP notification using the following options: + +* SNMPv2c +* with community name 'public' +* over IPv4/UDP +* send TRAP notification +* to a Manager at 127.0.0.1:162 +* with TRAP ID 'coldStart' specified as an OID +* include managed objects information: + 1.3.6.1.2.1.1.1.0 = 'Example Notificator' + 1.3.6.1.2.1.1.5.0 = 'Notificator Example' + +Functionally similar to: + +| $ snmptrap -v2c -c public 127.0.0.1 12345 1.3.6.1.4.1.20408.4.1.1.2 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/agent/ntforg/v3-trap.py b/examples/v3arch/asyncore/agent/ntforg/v3-trap.py index db2c965a..d43fe271 100644 --- a/examples/v3arch/asyncore/agent/ntforg/v3-trap.py +++ b/examples/v3arch/asyncore/agent/ntforg/v3-trap.py @@ -1,16 +1,23 @@ -# -# Notification Originator -# -# Send SNMP TRAP notification using the following options: -# -# * SNMPv3 -# * with user 'usr-md5-des', auth: MD5, priv DES -# * over IPv4/UDP -# * send TRAP notification -# * to a Manager at 127.0.0.1:162 -# * with TRAP ID 'warmStart' specified as an OID -# * include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' -# +""" +SNMPv3 TRAP, auth: MD5, privacy: DES +++++++++++++++++++++++++++++++++++++ + +Send SNMP TRAP notification using the following options: + +* SNMPv3 +* with user 'usr-md5-des', auth: MD5, priv DES +* over IPv4/UDP +* send TRAP notification +* to a Manager at 127.0.0.1:162 +* with TRAP ID 'warmStart' specified as an OID +* include managed object information 1.3.6.1.2.1.1.5.0 = 'system name' + +Functionally similar to: + +| $ snmptrap -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -e 800000000 +1020304 0 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s 'my system' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntforg diff --git a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py index 01fd25dd..e61e5389 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py +++ b/examples/v3arch/asyncore/manager/cmdgen/custom-contextengineid-and-contextname.py @@ -1,19 +1,22 @@ -# -# GET Command Generator -# -# Send a SNMP GET request -# with SNMPv3 with user 'usr-md5-none', SHA auth and no privacy protocols -# for MIB instance identified by -# contextEngineId: 0x80004fb805636c6f75644dab22cc, -# contextName: da761cfc8c94d3aceef4f60f049105ba -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in tuple form -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 -E 80004fb805636c6f75644dab22cc -n da761cfc8c94d3aceef4f60f049105ba -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 -# +""" +Custom ContextEngineId and ContextName +++++++++++++++++++++++++++++++++++++++ + +Send a SNMP GET request with the following options: + +* with SNMPv3 with user 'usr-md5-none', SHA auth and no privacy protocols +* for MIB instance identified by +* contextEngineId: 0x80004fb805636c6f75644dab22cc, +* contextName: da761cfc8c94d3aceef4f60f049105ba +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 -E 80004fb805636c6f75644dab22cc -n da761cfc8c94d3aceef4f60f049105ba -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py index 5fbd3ebb..b91a4b63 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py +++ b/examples/v3arch/asyncore/manager/cmdgen/custom-timeout-and-retries.py @@ -1,17 +1,20 @@ -# -# GET Command Generator -# -# Send a SNMP GET request -# with SNMPv2c, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# wait 3 seconds for response, retry 5 times (plus one initial attempt) -# for an OID in tuple form -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpget -v2c -c public -ObentU -r 5 -t 1 195.218.195.228 1.3.6.1.2.1.1.1.0 -# +""" +SNMPv2c, custom timeout ++++++++++++++++++++++++ + +Send a SNMP GET request: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* wait 3 seconds for response, retry 5 times (plus one initial attempt) +* for an OID in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v2c -c public -ObentU -r 5 -t 1 195.218.195.228 1.3.6.1.2.1.1.1.0 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py index ebdcb8a2..1856d80e 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py +++ b/examples/v3arch/asyncore/manager/cmdgen/fetch-variables-over-ipv6.py @@ -1,17 +1,20 @@ -# -# GETNEXT Command Generator -# -# Send a series of SNMP GETNEXT requests -# with SNMPv3 with user 'usr-md5-none', MD5 auth and no privacy protocols -# over IPv6/UDP -# to an Agent at [::1]:161 -# for two OIDs in tuple form -# stop on end-of-mib condition for both OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpwalk -v3 -l authNoPriv -u usr-md5-none -A authkey1 -ObentU udp6:[::1]:161 1.3.6.1.2.1.1 1.3.6.1.4.1.1 -# +""" +Walk Agent over IPv6 +++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests with the following options: + +* with SNMPv3 with user 'usr-md5-none', MD5 auth and no privacy protocols +* over IPv6/UDP +* to an Agent at [::1]:161 +* for two OIDs in tuple form +* stop on end-of-mib condition for both OIDs + +This script performs similar to the following Net-SNMP command: + +| $ snmpwalk -v3 -l authNoPriv -u usr-md5-none -A authkey1 -ObentU udp6:[::1]:161 1.3.6.1.2.1.1 1.3.6.1.4.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp6 from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py b/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py index 934fcd67..8bd04a5c 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getbulk-fetch-scalar-and-table-variables.py @@ -1,18 +1,21 @@ -# -# GETBULK Command Generator -# -# Send a series of SNMP GETBULK requests -# with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# with values non-repeaters = 1, max-repetitions = 25 -# for two OIDs in tuple form (first OID is non-repeating) -# stop on end-of-mib condition for both OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpbulkwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -C n1 -C r25 -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 -# +""" +Fetch scalar and table variables +++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETBULK requests with the following options: + +* with SNMPv3 with user 'usr-md5-des', MD5 auth and DES privacy protocols +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* with values non-repeaters = 1, max-repetitions = 25 +* for two OIDs in tuple form (first OID is non-repeating) +* stop on end-of-mib condition for both OIDs + +This script performs similar to the following Net-SNMP command: + +| $ snmpbulkwalk -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -C n1 -C r25 -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdgen from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py b/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py index 6c451a30..9f5db70c 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getbulk-multiple-oids-to-eom.py @@ -1,18 +1,20 @@ -# -# GETBULK Command Generator -# -# Send a series of SNMP GETBULK requests -# with SNMPv2c, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# with values non-repeaters = 0, max-repetitions = 25 -# for two OIDs in tuple form -# stop on end-of-mib condition for both OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpbulkwalk -v2c -c public -C n0 -C r25 -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 -# +""" +Bulk walk MIB ++++++++++++++ + +Send a series of SNMP GETBULK requests +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* with values non-repeaters = 0, max-repetitions = 25 +* for two OIDs in tuple form +* stop on end-of-mib condition for both OIDs + +This script performs similar to the following Net-SNMP command: + +| $ snmpbulkwalk -v2c -c public -C n0 -C r25 -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdgen from pysnmp.carrier.asyncore.dgram import udp diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py index 59e0bba9..d69abfeb 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-and-resolve-with-mib.py @@ -1,17 +1,20 @@ -# -# GETNEXT Command Generator -# -# Send a series of SNMP GETNEXT requests -# with SNMPv1, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for two OIDs in tuple form -# stop on end-of-mib condition for both OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 -# +""" +Walk Agent and resolve variables at MIB ++++++++++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests with the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for two OIDs in tuple form +* stop on end-of-mib condition for both OIDs + +This script performs similar to the following Net-SNMP command: + +| $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py index 5d4420c6..0a41a416 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py +++ b/examples/v3arch/asyncore/manager/cmdgen/getnext-multiple-oids-to-eom.py @@ -1,17 +1,20 @@ -# -# GETNEXT Command Generator -# -# Send a series of SNMP GETNEXT requests -# with SNMPv1, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for two OIDs in tuple form -# stop on end-of-mib condition for both OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 -# +""" +Fetch two subtrees in parallel +++++++++++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests with the following options: + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for two OIDs in tuple form +* stop on end-of-mib condition for both OIDs + +This script performs similar to the following Net-SNMP command: + +| $ snmpwalk -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py index d05be2d5..0914ac36 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py +++ b/examples/v3arch/asyncore/manager/cmdgen/observe-request-processing.py @@ -1,20 +1,23 @@ -# -# GET Command Generator -# -# Send a SNMP GET request -# with SNMPv3 with user 'usr-sha-aes', SHA auth and AES128 privacy protocols -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in tuple form -# also registers its own execution observer to snmpEngine -# -# While execution, this script will report some details on request processing -# as seen by rfc3412.sendPdu() and rfc3412.receiveMessage() abstract interfaces. -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpget -v3 -l authPriv -u usr-sha-aes -a SHA -A authkey1 -x AES -X privkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 -# +""" +Report SNMP engine processing details ++++++++++++++++++++++++++++++++++++++ + +Send SNMP GET request with the following options: + +* with SNMPv3 with user 'usr-sha-aes', SHA auth and AES128 privacy protocols +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in tuple form +* also registers its own execution observer to snmpEngine + +While execution, this script will report some details on request processing +as seen by rfc3412.sendPdu() and rfc3412.receiveMessage() abstract interfaces. + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v3 -l authPriv -u usr-sha-aes -a SHA -A authkey1 -x AES -X privkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py index abf3bab5..5edc744e 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py +++ b/examples/v3arch/asyncore/manager/cmdgen/pull-subtree.py @@ -1,17 +1,19 @@ -# -# GETNEXT Command Generator -# -# Send a series of SNMP GETNEXT requests -# with SNMPv3 with user 'usr-none-none', no auth and no privacy protocols -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in string form -# stop whenever received OID goes out of initial prefix (it may be a table) -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpwalk -v3 -l noAuthNoPriv -u usr-none-none -ObentU 195.218.195.228:161 1.3.6.1.2.1.1 -# +""" +Pull MIB subtree +++++++++++++++++ + +Send a series of SNMP GETNEXT requests +* with SNMPv3 with user 'usr-none-none', no auth and no privacy protocols +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in string form +* stop whenever received OID goes out of initial prefix (it may be a table) + +This script performs similar to the following Net-SNMP command: + +| $ snmpwalk -v3 -l noAuthNoPriv -u usr-none-none -ObentU 195.218.195.228:161 1.3.6.1.2.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py b/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py index 4ce98774..022742a7 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py +++ b/examples/v3arch/asyncore/manager/cmdgen/send-packets-from-specific-interface.py @@ -1,18 +1,21 @@ -# -# GETNEXT Command Generator -# -# Send a series of SNMP GETNEXT requests -# with SNMPv2c, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# sending packets from primary local interface 0.0.0.0, local port 61024 -# for two OIDs in tuple form -# stop on end-of-mib condition for both OIDs -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpwalk -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 -# +""" +Send packets from specific local interface +++++++++++++++++++++++++++++++++++++++++++ + +Send a series of SNMP GETNEXT requests with the following options: + +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* sending packets from primary local interface 0.0.0.0, local port 61024 +* for two OIDs in tuple form +* stop on end-of-mib condition for both OIDs + +This script performs similar to the following Net-SNMP command: + +| $ snmpwalk -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1 1.3.6.1.4.1.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py index 05e82926..55a87202 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py +++ b/examples/v3arch/asyncore/manager/cmdgen/set-multiple-scalar-values.py @@ -1,16 +1,19 @@ -# -# SET Command Generator -# -# Send a SNMP SET request -# with SNMPv1 with community name 'private' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for OIDs in tuple form and an integer and string-typed values -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpset -v1 -c private -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.3.1 s 'my value' 1.3.6.1.2.1.1.9.1.4.1 t 123 -# +""" +SET string and integer scalars +++++++++++++++++++++++++++++++ + +Send SNMP SET request with the following options: + +* with SNMPv1 with community name 'private' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for OIDs in tuple form and an integer and string-typed values + +This script performs similar to the following Net-SNMP command: + +| $ snmpset -v1 -c private -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.3.1 s 'my value' 1.3.6.1.2.1.1.9.1.4.1 t 123 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py index cab29126..998d40f4 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py +++ b/examples/v3arch/asyncore/manager/cmdgen/spoof-source-address.py @@ -1,27 +1,28 @@ -# -# GET Command Generator -# -# Send a SNMP GET request -# with SNMPv2c, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# from a non-local, spoofed IP 1.2.3.4 (root and Python 3.3+ required) -# for an OID in tuple form -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpget -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0 -# -# But unlike the above command, this script issues SNMP request from -# a non-default, non-local IP address. -# -# It is indeed possible to originate SNMP traffic from any valid local -# IP addresses. It could be a secondary IP interface, for instance. -# Superuser privileges are only required to send spoofed packets. -# Alternatively, sending from local interface could also be achieved by -# binding to it (via openClientMode() parameter). -# -# +""" +Spoof source address +++++++++++++++++++++ + +Send a SNMP GET request +* with SNMPv2c, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* from a non-local, spoofed IP 1.2.3.4 (root and Python 3.3+ required) +* for an OID in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v2c -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0 + +But unlike the above command, this script issues SNMP request from +a non-default, non-local IP address. + +It is indeed possible to originate SNMP traffic from any valid local +IP addresses. It could be a secondary IP interface, for instance. +Superuser privileges are only required to send spoofed packets. +Alternatively, sending from local interface could also be achieved by +binding to it (via openClientMode() parameter). + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py index 98205432..f7ff4ee5 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py +++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-aes128.py @@ -1,16 +1,18 @@ -# -# GET Command Generator -# -# Send a SNMP GET request -# with SNMPv3 with user 'usr-sha-aes', SHA auth and AES128 privacy protocols -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in tuple form -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpget -v3 -l authPriv -u usr-sha-aes -a SHA -A authkey1 -x AES -X privkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 -# +""" +SNMPv3, auth: SHA, privacy: AES128 +++++++++++++++++++++++++++++++++++ + +Send a SNMP GET request +* with SNMPv3 with user 'usr-sha-aes', SHA auth and AES128 privacy protocols +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v3 -l authPriv -u usr-sha-aes -a SHA -A authkey1 -x AES -X privkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py index 790fb3f3..1c39d33d 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py +++ b/examples/v3arch/asyncore/manager/cmdgen/usm-sha-none.py @@ -1,16 +1,19 @@ -# -# SET Command Generator -# -# Send a SNMP SET request -# with SNMPv3 with user 'usr-sha-none', SHA auth and no privacy protocols -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in tuple form and a string-typed value -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpset -v3 -l authNoPriv -u usr-sha-none -a SHA -A authkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.3.1 s 'my new value' -# +""" +Set string value +++++++++++++++++ + +Send a SNMP SET request with the following options: + +* with SNMPv3 with user 'usr-sha-none', SHA auth and no privacy protocols +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in tuple form and a string-typed value + +This script performs similar to the following Net-SNMP command: + +| $ snmpset -v3 -l authNoPriv -u usr-sha-none -a SHA -A authkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.3.1 s 'my new value' + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py index af54eb8f..234d414f 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/v1-get.py +++ b/examples/v3arch/asyncore/manager/cmdgen/v1-get.py @@ -1,16 +1,17 @@ -# -# GET Command Generator -# -# Send a SNMP GET request -# with SNMPv1, community 'public' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in tuple form -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpget -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0 -# +""" +SNMPv1 +++++++ + +* with SNMPv1, community 'public' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in tuple form + +This script performs similar to the following Net-SNMP command: + +| $ snmpget -v1 -c public -ObentU 195.218.195.228 1.3.6.1.2.1.1.1.0 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py index 620ededa..9f7068fb 100644 --- a/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py +++ b/examples/v3arch/asyncore/manager/cmdgen/v2c-set.py @@ -1,16 +1,18 @@ -# -# SET Command Generator -# -# Send a SNMP SET request -# with SNMPv2c with community name 'private' -# over IPv4/UDP -# to an Agent at 195.218.195.228:161 -# for an OID in tuple form and an integer-typed value -# -# This script performs similar to the following Net-SNMP command: -# -# $ snmpset -v2c -c private -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.4.1 t 123 -# +""" +Set scalar value +++++++++++++++++ + +Send a SNMP SET request +* with SNMPv2c with community name 'private' +* over IPv4/UDP +* to an Agent at 195.218.195.228:161 +* for an OID in tuple form and an integer-typed value + +This script performs similar to the following Net-SNMP command: + +| $ snmpset -v2c -c private -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.9.1.4.1 t 123 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import cmdgen diff --git a/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py b/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py index ea3aafbc..d8619def 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/determine-peer-network-address.py @@ -1,19 +1,21 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with SNMP community "public" -# * over IPv4/UDP, listening at 127.0.0.1:162 -# * use observer facility to pull lower-level request details from SNMP engine -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test -# +""" +Receive notifications noting peer address ++++++++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:162 +* use observer facility to pull lower-level request details from SNMP engine +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py index c4dbae85..402f9308 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-interfaces.py @@ -1,20 +1,22 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with SNMP community "public" -# * over IPv4/UDP, listening at 127.0.0.1:162 -# over IPv4/UDP, listening at 127.0.0.1:2162 -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test -# $ snmpinform -v2c -c public 127.0.0.1:2162 123 1.3.6.1.6.3.1.1.5.1 -# +""" +Serving multiple network interfaces ++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:162 + over IPv4/UDP, listening at 127.0.0.1:2162 +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test +| $ snmpinform -v2c -c public 127.0.0.1:2162 123 1.3.6.1.6.3.1.1.5.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py index 2b549986..31fcb2b5 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-network-transports.py @@ -1,21 +1,23 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with SNMP community "public" -# * over IPv4/UDP, listening at 127.0.0.1:162 -# over IPv6/UDP, listening at [::1]:162 -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test -# $ snmptrap -v2c -c public udp6:[::1]:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test -# $ snmpinform -v2c -c public 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# +""" +Using multiple network transports ++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:162 + over IPv6/UDP, listening at [::1]:162 +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test +| $ snmptrap -v2c -c public udp6:[::1]:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test +| $ snmpinform -v2c -c public 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp, udp6 from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py b/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py index f78d11c8..037062b9 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/multiple-usm-users.py @@ -1,23 +1,27 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv3 -# * with USM users: -# 'usr-md5-des', auth: MD5, priv DES, ContextEngineId: 8000000001020304 -# 'usr-md5-none', auth: MD5, priv NONE, ContextEngineId: 8000000001020304 -# 'usr-sha-aes128', auth: SHA, priv AES, ContextEngineId: 8000000001020304 -# * over IPv4/UDP, listening at 127.0.0.1:162 -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# $ snmptrap -v3 -u usr-md5-none -l authNoPriv -A authkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# $ snmpinform -v3 -u usr-sha-aes128 -l authPriv -a SHA -A authkey1 -x AES -X privkey1 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# +""" +Multiple SNMP USM users ++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv3 +* with USM users: + + * 'usr-md5-des', auth: MD5, priv DES, ContextEngineId: 8000000001020304 + * 'usr-md5-none', auth: MD5, priv NONE, ContextEngineId: 8000000001020304 + * 'usr-sha-aes128', auth: SHA, priv AES, ContextEngineId: 8000000001020304 + +* over IPv4/UDP, listening at 127.0.0.1:162 +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 +| $ snmptrap -v3 -u usr-md5-none -l authNoPriv -A authkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 +| $ snmpinform -v3 -u usr-sha-aes128 -l authPriv -a SHA -A authkey1 -x AES -X privkey1 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py b/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py index 5651a6f7..ed44146c 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/observe-request-processing.py @@ -1,22 +1,24 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with SNMP community "public" -# * over IPv4/UDP, listening at 127.0.0.1:162 -# over IPv6/UDP, listening at [::1]:162 -# * registers its own execution observer to snmpEngine -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test -# $ snmptrap -v2c -c public udp6:[::1]:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test -# $ snmpinform -v2c -c public 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# +""" +Observe SNMP engine internal operations ++++++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* over IPv4/UDP, listening at 127.0.0.1:162 + over IPv6/UDP, listening at [::1]:162 +* registers its own execution observer to snmpEngine +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v1 -c public 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test +| $ snmptrap -v2c -c public udp6:[::1]:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test +| $ snmpinform -v2c -c public 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp, udp6 from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py index 57a70308..759bf980 100644 --- a/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py +++ b/examples/v3arch/asyncore/manager/ntfrcv/regexp-community-name.py @@ -1,28 +1,30 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with any SNMP community matching regexp '.*love.*' -# * over IPv4/UDP, listening at 127.0.0.1:162 -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v1 -c rollover 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test -# $ snmpinform -v2c -c glove 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# -# The Notification Receiver below taps on v1/v2c SNMP security module -# to deliver certains values, normally internal to SNMP Engine, up to -# the context of user application. -# -# This script examines the value of CommunityName, as it came from peer SNMP -# Engine, and may modify it to match the only locally configured CommunityName -# 'public'. This effectively makes NotificationReceiver accepting messages with -# CommunityName's, not explicitly configured to local SNMP Engine. -# +""" +Serve SNMP Community names defined by regexp +++++++++++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with any SNMP community matching regexp '.*love.*' +* over IPv4/UDP, listening at 127.0.0.1:162 +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v1 -c rollover 127.0.0.1 1.3.6.1.4.1.20408.4.1.1.2 127.0.0.1 1 1 123 1.3.6.1.2.1.1.1.0 s test +| $ snmpinform -v2c -c glove 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 + +The Notification Receiver below taps on v1/v2c SNMP security module +to deliver certains values, normally internal to SNMP Engine, up to +the context of user application. + +This script examines the value of CommunityName, as it came from peer SNMP +Engine, and may modify it to match the only locally configured CommunityName +'public'. This effectively makes NotificationReceiver accepting messages with +CommunityName's, not explicitly configured to local SNMP Engine. + +"""# from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv diff --git a/examples/v3arch/asyncore/proxy/command/udp6-to-udp4-conversion.py b/examples/v3arch/asyncore/proxy/command/udp6-to-udp4-conversion.py index 07497b4e..a13df6b6 100644 --- a/examples/v3arch/asyncore/proxy/command/udp6-to-udp4-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/udp6-to-udp4-conversion.py @@ -1,26 +1,29 @@ -# -# SNMP Command Proxy example -# -# Act as a local SNMPv1/v2c Agent listening on a UDP/IPv6 transport, relay -# messages to distant SNMPv1/2c Agent over UDP/IPv4 transport: -# with local SNMPv2c community 'public' -# local Agent listening at [::1]:161 -# remote SNMPv2c community 'public' -# remote Agent listening at 195.218.195.228:161 -# -# This script can be queried with the following Net-SNMP command: -# -# $ snmpget -v2c -c public udp6:[::1]:161 sysDescr.0 -# -# due to proxy, it is equivalent to -# -# $ snmpget -v2c -c public 195.218.195.228:161 sysDescr.0 -# -# Warning: for production operation you would need to modify this script -# so that it will re-map possible duplicate request-ID values, coming in -# initial request PDUs from different Managers, into unique values to -# avoid sending duplicate request-IDs to Agents. -# +""" +IPv6-to-IPv4 conversion ++++++++++++++++++++++++ + +Act as a local SNMPv1/v2c Agent listening on a UDP/IPv6 transport, relay +messages to distant SNMPv1/2c Agent over UDP/IPv4 transport: + +* with local SNMPv2c community 'public' +* local Agent listening at [::1]:161 +* remote SNMPv2c community 'public' +* remote Agent listening at 195.218.195.228:161 + +This script can be queried with the following Net-SNMP command: + +| $ snmpget -v2c -c public udp6:[::1]:161 sysDescr.0 + +due to proxy, it is equivalent to + +| $ snmpget -v2c -c public 195.218.195.228:161 sysDescr.0 + +Warning: for production operation you would need to modify this script +so that it will re-map possible duplicate request-ID values, coming in +initial request PDUs from different Managers, into unique values to +avoid sending duplicate request-IDs to Agents. + +"""# from pysnmp.carrier.asyncore.dgram import udp, udp6 from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, cmdgen, context diff --git a/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py b/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py index e6a805c6..4e78dfca 100644 --- a/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py @@ -1,26 +1,29 @@ -# -# SNMP Command Proxy example -# -# Act as a local SNMPv2c Agent, relay messages to distant SNMPv1 Agent: -# over IPv4/UDP -# with local SNMPv2c community public -# local Agent listening at 127.0.0.1:161 -# remote SNMPv1, community public -# remote Agent listening at 195.218.195.228:161 -# -# This script can be queried with the following Net-SNMP command: -# -# $ snmpbulkwalk -v2c -c public -ObentU 127.0.0.1:161 system -# -# due to proxy, it is equivalent to -# -# $ snmpwalk -v1 -c public 195.218.195.228:161 system -# -# Warning: for production operation you would need to modify this script -# so that it will re-map possible duplicate request-ID values, coming in -# initial request PDUs from different Managers, into unique values to -# avoid sending duplicate request-IDs to Agents. -# +""" +SNMPv2c-to-SNMPv1 conversion +++++++++++++++++++++++++++++ + +Act as a local SNMPv2c Agent, relay messages to distant SNMPv1 Agent: + +* over IPv4/UDP +* with local SNMPv2c community public +* local Agent listening at 127.0.0.1:161 +* remote SNMPv1, community public +* remote Agent listening at 195.218.195.228:161 + +This script can be queried with the following Net-SNMP command: + +| $ snmpbulkwalk -v2c -c public -ObentU 127.0.0.1:161 system + +due to proxy, it is equivalent to + +| $ snmpwalk -v1 -c public 195.218.195.228:161 system + +Warning: for production operation you would need to modify this script +so that it will re-map possible duplicate request-ID values, coming in +initial request PDUs from different Managers, into unique values to +avoid sending duplicate request-IDs to Agents. + +"""# from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, cmdgen, context diff --git a/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py b/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py index 453d8bb5..ca269f73 100644 --- a/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py @@ -1,26 +1,28 @@ -# -# SNMP Command Proxy example -# -# Act as a local SNMPv1/v2c Agent, relay messages to distant SNMPv3 Agent: -# over IPv4/UDP -# with local SNMPv2c community 'public' -# local Agent listening at 127.0.0.1:161 -# remote SNMPv3 user usr-md5-none, MD5 auth and no privacy protocols -# remote Agent listening at 195.218.195.228:161 -# -# This script can be queried with the following Net-SNMP command: -# -# $ snmpget -v2c -c public 127.0.0.1:161 1.3.6.1.2.1.1.1.0 -# -# due to proxy, it is equivalent to -# -# $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 -# -# Warning: for production operation you would need to modify this script -# so that it will re-map possible duplicate request-ID values, coming in -# initial request PDUs from different Managers, into unique values to -# avoid sending duplicate request-IDs to Agents. -# +""" +SNMPv2c-to-SNMPv3 conversion +++++++++++++++++++++++++++++ + +Act as a local SNMPv1/v2c Agent, relay messages to distant SNMPv3 Agent: +* over IPv4/UDP +* with local SNMPv2c community 'public' +* local Agent listening at 127.0.0.1:161 +* remote SNMPv3 user usr-md5-none, MD5 auth and no privacy protocols +* remote Agent listening at 195.218.195.228:161 + +This script can be queried with the following Net-SNMP command: + +| $ snmpget -v2c -c public 127.0.0.1:161 1.3.6.1.2.1.1.1.0 + +due to proxy, it is equivalent to + +| $ snmpget -v3 -l authNoPriv -u usr-md5-none -A authkey1 -ObentU 195.218.195.228:161 1.3.6.1.2.1.1.1.0 + +Warning: for production operation you would need to modify this script +so that it will re-map possible duplicate request-ID values, coming in +initial request PDUs from different Managers, into unique values to +avoid sending duplicate request-IDs to Agents. + +"""# from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, cmdgen, context diff --git a/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py b/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py index 992ff7fb..da9aba3e 100644 --- a/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py @@ -1,26 +1,28 @@ -# -# SNMP Command Proxy example -# -# Act as a local SNMPv3 Agent, relay messages to distant SNMPv1/v2c Agent: -# over IPv4/UDP -# with local SNMPv3 user usr-md5-des, MD5 auth and DES privacy protocols -# local Agent listening at 127.0.0.1:161 -# remote SNMPv1, community public -# remote Agent listening at 195.218.195.228:161 -# -# This script can be queried with the following Net-SNMP command: -# -# $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.1.0 -# -# due to proxy, it is equivalent to -# -# $ snmpget -v2c -c public 195.218.195.228:161 1.3.6.1.2.1.1.1.0 -# -# Warning: for production operation you would need to modify this script -# so that it will re-map possible duplicate request-ID values, coming in -# initial request PDUs from different Managers, into unique values to -# avoid sending duplicate request-IDs to Agents. -# +""" +SNMPv3-to-SNMPv2c conversion +++++++++++++++++++++++++++++ + +Act as a local SNMPv3 Agent, relay messages to distant SNMPv1/v2c Agent: +* over IPv4/UDP +* with local SNMPv3 user usr-md5-des, MD5 auth and DES privacy protocols +* local Agent listening at 127.0.0.1:161 +* remote SNMPv1, community public +* remote Agent listening at 195.218.195.228:161 + +This script can be queried with the following Net-SNMP command: + +| $ snmpget -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 -ObentU 127.0.0.1:161 1.3.6.1.2.1.1.1.0 + +due to proxy, it is equivalent to + +| $ snmpget -v2c -c public 195.218.195.228:161 1.3.6.1.2.1.1.1.0 + +Warning: for production operation you would need to modify this script +so that it will re-map possible duplicate request-ID values, coming in +initial request PDUs from different Managers, into unique values to +avoid sending duplicate request-IDs to Agents. + +"""# from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, cmdgen, context diff --git a/examples/v3arch/twisted/agent/cmdrsp/implementing-scalar-mib-objects.py b/examples/v3arch/twisted/agent/cmdrsp/implementing-scalar-mib-objects.py index 091bb755..565419d4 100644 --- a/examples/v3arch/twisted/agent/cmdrsp/implementing-scalar-mib-objects.py +++ b/examples/v3arch/twisted/agent/cmdrsp/implementing-scalar-mib-objects.py @@ -1,20 +1,22 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv2c -# * with SNMP community "public" -# * serving custom Managed Object Instance defined within this script -# * allow read access only to the subtree where the custom MIB object resides -# * over IPv4/UDP, listening at 127.0.0.1:161 -# * using Twisted fraework for network transport -# -# Either of the following Net-SNMP's commands will walk this Agent: -# -# $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 -# +""" +Implementing scalar MIB objects ++++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv2c +* with SNMP community "public" +* serving custom Managed Object Instance defined within this script +* allow read access only to the subtree where the custom MIB object resides +* over IPv4/UDP, listening at 127.0.0.1:161 +* using Twisted fraework for network transport + +Either of the following Net-SNMP commands will walk this Agent: + +| $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 + +"""# import sys from twisted.internet import reactor from pysnmp.entity import engine, config diff --git a/examples/v3arch/twisted/agent/cmdrsp/multiple-interfaces.py b/examples/v3arch/twisted/agent/cmdrsp/multiple-interfaces.py index 4f8b29de..a9e3e002 100644 --- a/examples/v3arch/twisted/agent/cmdrsp/multiple-interfaces.py +++ b/examples/v3arch/twisted/agent/cmdrsp/multiple-interfaces.py @@ -1,20 +1,22 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with -# the following options: -# -# * SNMPv2c -# * with SNMP community "public" -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 and 127.0.0.2:161 interfaces -# * using Twisted framework for network transport -# -# Either of the following Net-SNMP's commands will walk this Agent: -# -# $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 -# $ snmpwalk -v2c -c public 127.0.0.2 .1.3.6 -# +""" +Listen on multiple network interfaces ++++++++++++++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT/GETBULK queries with +the following options: + +* SNMPv2c +* with SNMP community "public" +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 and 127.0.0.2:161 interfaces +* using Twisted framework for network transport + +Either of the following Net-SNMP commands will walk this Agent: + +| $ snmpwalk -v2c -c public 127.0.0.1 .1.3.6 +| $ snmpwalk -v2c -c public 127.0.0.2 .1.3.6 + +"""# from twisted.internet import reactor from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context diff --git a/examples/v3arch/twisted/agent/cmdrsp/multiple-snmp-communities.py b/examples/v3arch/twisted/agent/cmdrsp/multiple-snmp-communities.py index d3462444..da6cc5f4 100644 --- a/examples/v3arch/twisted/agent/cmdrsp/multiple-snmp-communities.py +++ b/examples/v3arch/twisted/agent/cmdrsp/multiple-snmp-communities.py @@ -1,20 +1,22 @@ -# -# Command Responder -# -# Listen and respond to SNMP GET/SET/GETNEXT queries with -# the following options: -# -# * SNMPv1 -# * with SNMP community "public" (read access) or "private" (write access) -# * allow access to SNMPv2-MIB objects (1.3.6.1.2.1) -# * over IPv4/UDP, listening at 127.0.0.1:161 -# * using Twisted fraework for network transport -# -# The following Net-SNMP's commands will GET/SET a value at this Agent: -# -# $ snmpget -v1 -c public 127.0.0.1 SNMPv2-MIB::sysLocation.0 -# $ snmpset -v1 -c private 127.0.0.1 SNMPv2-MIB::sysLocation.0 s "far away" -# +""" +Multiple SNMP communities ++++++++++++++++++++++++++ + +Listen and respond to SNMP GET/SET/GETNEXT queries with +the following options: + +* SNMPv1 +* with SNMP community "public" (read access) or "private" (write access) +* allow access to SNMPv2-MIB objects (1.3.6.1.2.1) +* over IPv4/UDP, listening at 127.0.0.1:161 +* using Twisted fraework for network transport + +The following Net-SNMP commands will GET/SET a value at this Agent: + +| $ snmpget -v1 -c public 127.0.0.1 SNMPv2-MIB::sysLocation.0 +| $ snmpset -v1 -c private 127.0.0.1 SNMPv2-MIB::sysLocation.0 s "far away" + +"""# from twisted.internet import reactor from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context diff --git a/examples/v3arch/twisted/agent/cmdrsp/multiple-usm-users.py b/examples/v3arch/twisted/agent/cmdrsp/multiple-usm-users.py index 36d9d36e..91fd9557 100644 --- a/examples/v3arch/twisted/agent/cmdrsp/multiple-usm-users.py +++ b/examples/v3arch/twisted/agent/cmdrsp/multiple-usm-users.py @@ -1,23 +1,26 @@ -# -# 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 -# * using Twisted framework for network transport -# -# 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 -# +""" +Multiple SNMP USM users ++++++++++++++++++++++++ + +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 + * 'usr-sha-none', auth: SHA, no privacy + * '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 +* using Twisted framework for network transport + +Either of the following Net-SNMP 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 diff --git a/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py b/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py index 4f9b68f0..b7edf7dd 100644 --- a/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py +++ b/examples/v3arch/twisted/manager/ntfrcv/multiple-interfaces.py @@ -1,21 +1,24 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv1/SNMPv2c -# * with SNMP community "public" -# * over IPv4/UDP, listening at 127.0.0.1:162 -# over IPv4/UDP, listening at 127.0.0.1:2162 -# * using Twisted framework for network transport -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test -# $ snmpinform -v2c -c public 127.0.0.1:2162 123 1.3.6.1.6.3.1.1.5.1 -# +""" +Serving multiple network interfaces ++++++++++++++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv1/SNMPv2c +* with SNMP community "public" +* listen on two local network interfaces: + * IPv4/UDP, listening at 127.0.0.1:162 + * IPv4/UDP, listening at 127.0.0.1:2162 +* using Twisted framework for network transport +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v2c -c public 127.0.0.1:162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test +| $ snmpinform -v2c -c public 127.0.0.1:2162 123 1.3.6.1.6.3.1.1.5.1 + +"""# from twisted.internet import reactor from pysnmp.entity import engine, config from pysnmp.carrier.twisted.dgram import udp diff --git a/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py b/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py index 1192427c..a82bd3dd 100644 --- a/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py +++ b/examples/v3arch/twisted/manager/ntfrcv/multiple-usm-users.py @@ -1,24 +1,26 @@ -# -# Notification Receiver -# -# Receive SNMP TRAP/INFORM messages with the following options: -# -# * SNMPv3 -# * with USM users: -# 'usr-md5-des', auth: MD5, priv DES, ContextEngineId: 8000000001020304 -# 'usr-md5-none', auth: MD5, priv NONE, ContextEngineId: 8000000001020304 -# 'usr-sha-aes128', auth: SHA, priv AES, ContextEngineId: 8000000001020304 -# * over IPv4/UDP, listening at 127.0.0.1:162 -# * using Twisted framework for network transport -# * print received data on stdout -# -# Either of the following Net-SNMP's commands will send notifications to this -# receiver: -# -# $ snmptrap -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# $ snmptrap -v3 -u usr-md5-none -l authNoPriv -A authkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# $ snmpinform -v3 -u usr-sha-aes128 -l authPriv -a SHA -A authkey1 -x AES -X privkey1 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 -# +""" +Multiple SNMP USM users ++++++++++++++++++++++++ + +Receive SNMP TRAP/INFORM messages with the following options: + +* SNMPv3 +* with USM users: + * 'usr-md5-des', auth: MD5, priv DES, ContextEngineId: 8000000001020304 + * 'usr-md5-none', auth: MD5, priv NONE, ContextEngineId: 8000000001020304 + * 'usr-sha-aes128', auth: SHA, priv AES, ContextEngineId: 8000000001020304 +* over IPv4/UDP, listening at 127.0.0.1:162 +* using Twisted framework for network transport +* print received data on stdout + +Either of the following Net-SNMP commands will send notifications to this +receiver: + +| $ snmptrap -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 +| $ snmptrap -v3 -u usr-md5-none -l authNoPriv -A authkey1 -e 8000000001020304 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 +| $ snmpinform -v3 -u usr-sha-aes128 -l authPriv -a SHA -A authkey1 -x AES -X privkey1 127.0.0.1 123 1.3.6.1.6.3.1.1.5.1 + +"""# from twisted.internet import reactor from pysnmp.entity import engine, config from pysnmp.carrier.twisted.dgram import udp |