diff options
Diffstat (limited to 'examples/v3arch/agent')
-rw-r--r-- | examples/v3arch/agent/ntforg/inform-multiple-protocols.py | 26 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/inform-v2c.py | 28 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/inform-v3.py | 24 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v1-from-specific-address.py | 22 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v1.py | 25 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v2c-multiple-addresses.py | 27 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v2c-multiple-targets.py | 25 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v2c-multiple-transports.py | 27 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v2c-with-objects.py | 83 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v2c.py | 27 | ||||
-rw-r--r-- | examples/v3arch/agent/ntforg/trap-v3.py | 25 |
11 files changed, 132 insertions, 207 deletions
diff --git a/examples/v3arch/agent/ntforg/inform-multiple-protocols.py b/examples/v3arch/agent/ntforg/inform-multiple-protocols.py index a3fbb8d..8f70ef9 100644 --- a/examples/v3arch/agent/ntforg/inform-multiple-protocols.py +++ b/examples/v3arch/agent/ntforg/inform-multiple-protocols.py @@ -18,7 +18,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -80,9 +80,6 @@ config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() -# Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Error/confirmation receiver def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): @@ -94,18 +91,15 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, # Build and submit notification message to dispatcher sendRequestHandle = ntfOrg.sendVarBinds( snmpEngine, - # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')) ], + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')) + ], cbFun ) diff --git a/examples/v3arch/agent/ntforg/inform-v2c.py b/examples/v3arch/agent/ntforg/inform-v2c.py index 08993b0..9c52655 100644 --- a/examples/v3arch/agent/ntforg/inform-v2c.py +++ b/examples/v3arch/agent/ntforg/inform-v2c.py @@ -15,7 +15,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -59,9 +59,6 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() -# Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Error/confirmation receiver def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): @@ -73,19 +70,16 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, # Build and submit notification message to dispatcher sendRequestHandle = ntfOrg.sendVarBinds( snmpEngine, - # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), - ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ], + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) + ], cbFun ) diff --git a/examples/v3arch/agent/ntforg/inform-v3.py b/examples/v3arch/agent/ntforg/inform-v3.py index facebe3..ef5355a 100644 --- a/examples/v3arch/agent/ntforg/inform-v3.py +++ b/examples/v3arch/agent/ntforg/inform-v3.py @@ -13,7 +13,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -54,11 +54,8 @@ config.addVacmUser(snmpEngine, 3, 'usr-md5-none', 'authNoPriv', (), (), (1,3,6)) # *** SNMP engine configuration is complete by this line *** -# Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Create Notification Originator App instance. -ntfOrg = ntforg.NotificationOriginator(snmpContext) +ntfOrg = ntforg.NotificationOriginator() # Error/confirmation receiver def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -71,18 +68,11 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, # Build and submit notification message to dispatcher sendRequestHandle = ntfOrg.sendVarBinds( snmpEngine, - # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ], + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds: SNMPv2-MIB::coldStart, ... + [ ((1,3,6,1,6,3,1,1,5,1), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ], cbFun ) diff --git a/examples/v3arch/agent/ntforg/trap-v1-from-specific-address.py b/examples/v3arch/agent/ntforg/trap-v1-from-specific-address.py index 2bfa05d..04dcd56 100644 --- a/examples/v3arch/agent/ntforg/trap-v1-from-specific-address.py +++ b/examples/v3arch/agent/ntforg/trap-v1-from-specific-address.py @@ -13,7 +13,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -57,22 +57,16 @@ config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() - # Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Build and submit notification message to dispatcher ntfOrg.sendVarBinds( snmpEngine, - # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))) + ] ) print('Notification is scheduled to be sent') diff --git a/examples/v3arch/agent/ntforg/trap-v1.py b/examples/v3arch/agent/ntforg/trap-v1.py index f21bde5..2ac5071 100644 --- a/examples/v3arch/agent/ntforg/trap-v1.py +++ b/examples/v3arch/agent/ntforg/trap-v1.py @@ -17,7 +17,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c #from pysnmp import debug @@ -64,28 +64,21 @@ config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() - # Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Build and submit notification message to dispatcher ntfOrg.sendVarBinds( snmpEngine, # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name: Generic Trap #6 (enterpriseSpecific) - # and Specific Trap 432 - '1.3.6.1.4.1.20408.4.1.1.2.0.432', - # instance Index - None, - # additional var-binds - [ + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ # Uptime value with 12345 (v2c.ObjectIdentifier('1.3.6.1.2.1.1.3.0'), v2c.TimeTicks(12345)), + # trap OID: Generic Trap #6 (enterpriseSpecific) + # and Specific Trap 432 + (v2c.ObjectIdentifier('1.3.6.1.6.3.1.1.5.1'), + v2c.ObjectIdentifier('1.3.6.1.4.1.20408.4.1.1.2.0.432')), # Agent Address with '127.0.0.1' (v2c.ObjectIdentifier('1.3.6.1.6.3.18.1.3.0'), v2c.IpAddress('127.0.0.1')), diff --git a/examples/v3arch/agent/ntforg/trap-v2c-multiple-addresses.py b/examples/v3arch/agent/ntforg/trap-v2c-multiple-addresses.py index 329268f..709e972 100644 --- a/examples/v3arch/agent/ntforg/trap-v2c-multiple-addresses.py +++ b/examples/v3arch/agent/ntforg/trap-v2c-multiple-addresses.py @@ -16,7 +16,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -74,25 +74,20 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() -# Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Build and submit notification message to dispatcher ntfOrg.sendVarBinds( snmpEngine, # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), - ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ] + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) + ] ) print('Notifications are scheduled to be sent') diff --git a/examples/v3arch/agent/ntforg/trap-v2c-multiple-targets.py b/examples/v3arch/agent/ntforg/trap-v2c-multiple-targets.py index 0ca3d70..cd6432b 100644 --- a/examples/v3arch/agent/ntforg/trap-v2c-multiple-targets.py +++ b/examples/v3arch/agent/ntforg/trap-v2c-multiple-targets.py @@ -16,7 +16,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -70,22 +70,23 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # *** SNMP engine configuration is complete by this line *** -# Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Create Notification Originator App instance. -ntfOrg = ntforg.NotificationOriginator(snmpContext) +ntfOrg = ntforg.NotificationOriginator() # Build and submit notification message to dispatcher -ntfOrg.sendNotification( +ntfOrg.sendVarBinds( snmpEngine, # Notification targets - 'my-notification', - # Trap OID (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # ( (oid, value), ... ) - ( ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), - ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ) + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) + ] ) print('Notifications are scheduled to be sent') diff --git a/examples/v3arch/agent/ntforg/trap-v2c-multiple-transports.py b/examples/v3arch/agent/ntforg/trap-v2c-multiple-transports.py index ea204f2..e2589da 100644 --- a/examples/v3arch/agent/ntforg/trap-v2c-multiple-transports.py +++ b/examples/v3arch/agent/ntforg/trap-v2c-multiple-transports.py @@ -15,7 +15,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp, udp6 -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -73,25 +73,20 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() - # Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Build and submit notification message to dispatcher ntfOrg.sendVarBinds( snmpEngine, # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), - ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ] + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) + ] ) print('Notification is scheduled to be sent') diff --git a/examples/v3arch/agent/ntforg/trap-v2c-with-objects.py b/examples/v3arch/agent/ntforg/trap-v2c-with-objects.py index e4ac2e0..ad17348 100644 --- a/examples/v3arch/agent/ntforg/trap-v2c-with-objects.py +++ b/examples/v3arch/agent/ntforg/trap-v2c-with-objects.py @@ -8,28 +8,24 @@ # * over IPv4/UDP # * send TRAP notification # * to a Manager at 127.0.0.1:162 -# * with TRAP ID ACCOUNTING-CONTROL-MIB::acctngFileFull as MIB symbol +# * with TRAP ID IF-MIB::ifLink as MIB symbol # -# The ACCOUNTING-CONTROL-MIB::acctngFileFull NOTIFICATION-TYPE implies -# including three other var-binds into the TRAP describing the incident -# occurred. These var-binds are: -# ACCOUNTING-CONTROL-MIB::acctngFileMaximumSize.0 -# ACCOUNTING-CONTROL-MIB::acctngFileNameSuffix.0 -# ACCOUNTING-CONTROL-MIB::acctngFileName.0 +# 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" # -# To run this example make sure to have ACCOUNTING-CONTROL-MIB.py in -# search path. +# Where "x" is MIB table index (instance index). +# +# To run this example make sure to have IF-MIB.py in search path. # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context -from pysnmp.proto.api import v2c - -# Create SNMP engine instance -snmpEngine = engine.SnmpEngine() - -# Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) +from pysnmp.entity.rfc3413 import ntforg +from pysnmp.smi import rfc1902, view # # Here we fill in some values for Managed Objects Instances (invoked @@ -37,33 +33,19 @@ snmpContext = context.SnmpContext(snmpEngine) # In real Agent app, these values should already be initialized during # Agent runtime. # +instanceIndex = (1,) +objects = { + ('IF-MIB', 'ifIndex'): instanceIndex[0], + ('IF-MIB', 'ifAdminStatus'): 'up', + ('IF-MIB', 'ifOperStatus'): 'down', + ('IF-MIB', 'ifDescr'): 'eth0' +} -mibInstrumCtl = snmpContext.getMibInstrum('') -( MibScalarInstance, ) = mibInstrumCtl.mibBuilder.importSymbols( - 'SNMPv2-SMI', - 'MibScalarInstance' - ) -( acctngFileFull, - acctngFileMaximumSize, - acctngFileNameSuffix, - acctngFileName ) = mibInstrumCtl.mibBuilder.importSymbols( - 'ACCOUNTING-CONTROL-MIB', - 'acctngFileFull', - 'acctngFileMaximumSize', - 'acctngFileNameSuffix', - 'acctngFileName' - ) - -mibInstrumCtl.mibBuilder.exportSymbols( - '__ACCOUNTING-CONTROL-MIB', - MibScalarInstance(acctngFileMaximumSize.name, (0,), acctngFileMaximumSize.syntax.clone(123)), - MibScalarInstance(acctngFileNameSuffix.name, (0,), acctngFileNameSuffix.syntax.clone('.log')), - MibScalarInstance(acctngFileName.name, (0,), acctngFileName.syntax.clone('mylogfile')), -) +# Create SNMP engine instance +snmpEngine = engine.SnmpEngine() -# -# End of Agent's Managed Object Instances initialization -# +# MIB view controller is used for MIB lookup purposes +mibViewController = view.MibViewController(snmpEngine.getMibBuilder()) # SecurityName <-> CommunityName mapping config.addV1System(snmpEngine, 'my-area', 'public', transportTag='all-my-managers') @@ -107,16 +89,13 @@ ntfOrg = ntforg.NotificationOriginator() # Build and submit notification message to dispatcher ntfOrg.sendVarBinds( snmpEngine, - # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name - ('ACCOUNTING-CONTROL-MIB', 'acctngFileFull'), - # MIB scalar/table instances of NOTIFICATION-TYPE objects - (0,) + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + rfc1902.NotificationType( + rfc1902.ObjectIdentity('IF-MIB', 'linkUp'), + instanceIndex=instanceIndex, + objects=objects + ).resolveWithMib(mibViewController) ) print('Notification is scheduled to be sent') diff --git a/examples/v3arch/agent/ntforg/trap-v2c.py b/examples/v3arch/agent/ntforg/trap-v2c.py index 4e3465b..d63a371 100644 --- a/examples/v3arch/agent/ntforg/trap-v2c.py +++ b/examples/v3arch/agent/ntforg/trap-v2c.py @@ -15,7 +15,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance @@ -58,9 +58,6 @@ config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() - # Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Error/confirmation receiver def cbFun(snmpEngine, sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): @@ -73,18 +70,16 @@ def cbFun(snmpEngine, sendRequestHandle, errorIndication, sendRequestHandle = ntfOrg.sendVarBinds( snmpEngine, # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), - ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) ], + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,1,0), v2c.OctetString('Example Notificator')), + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) + ], cbFun ) diff --git a/examples/v3arch/agent/ntforg/trap-v3.py b/examples/v3arch/agent/ntforg/trap-v3.py index bff341a..266d91e 100644 --- a/examples/v3arch/agent/ntforg/trap-v3.py +++ b/examples/v3arch/agent/ntforg/trap-v3.py @@ -13,7 +13,7 @@ # from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import ntforg, context +from pysnmp.entity.rfc3413 import ntforg from pysnmp.proto.api import v2c # Create SNMP engine instance with specific (and locally unique) @@ -62,24 +62,19 @@ config.addVacmUser(snmpEngine, 3, 'usr-md5-des', 'authPriv', (), (), (1,3,6)) # Create Notification Originator App instance. ntfOrg = ntforg.NotificationOriginator() - # Create default SNMP context where contextEngineId == SnmpEngineId -snmpContext = context.SnmpContext(snmpEngine) - # Build and submit notification message to dispatcher ntfOrg.sendVarBinds( snmpEngine, # Notification targets - 'my-notification', - # SNMP Context - snmpContext, - # contextName - '', - # notification name (SNMPv2-MIB::coldStart) - (1,3,6,1,6,3,1,1,5,1), - # instance Index - None, - # additional var-binds: ( (oid, value), ... ) - [ ((1,3,6,1,2,1,1,5,0), v2c.OctetString('system name')) ] + 'my-notification', # notification targets + None, '', # contextEngineId, contextName + # var-binds + [ + # SNMPv2-SMI::snmpTrapOID.0 = SNMPv2-MIB::coldStart + ((1,3,6,1,6,3,1,1,4,1,0), v2c.ObjectIdentifier((1,3,6,1,6,3,1,1,5,1))), + # additional var-binds: ( (oid, value), ... ) + ((1,3,6,1,2,1,1,5,0), v2c.OctetString('Notificator Example')) + ] ) print('Notification is scheduled to be sent') |