diff options
Diffstat (limited to 'examples/v3arch/oneliner/agent/ntforg')
11 files changed, 69 insertions, 59 deletions
diff --git a/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py b/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py index 088b72b..2dfbc55 100644 --- a/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py +++ b/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-snmp-engines.py @@ -26,19 +26,19 @@ # from pysnmp.entity.rfc3413.oneliner import ntforg from pysnmp.entity import engine -from pysnmp.entity.rfc3413 import context from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher -from pysnmp.proto import rfc1902 # 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.UdpTransportTarget(('localhost', 1162)), + ntforg.ContextData() ), # 2-nd target (SNMPv3 over IPv4/UDP) ( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - ntforg.UdpTransportTarget(('localhost', 162)) ) + ntforg.UdpTransportTarget(('localhost', 162)), + ntforg.ContextData() ), ) def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -69,19 +69,18 @@ snmpEngineB.registerTransportDispatcher(transportDispatcher, 'B') ntfOrg = ntforg.AsyncNotificationOriginator() -for authData, transportTarget in targets: +for authData, transportTarget, contextData in targets: snmpEngine = transportTarget.getTransportInfo()[1][1] % 3 and \ snmpEngineA or snmpEngineB sendPduHandle = ntfOrg.sendNotification( snmpEngine, authData, transportTarget, - context.SnmpContext(snmpEngine), - ntforg.null, - 'inform', - ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), - ( ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'), - rfc1902.OctetString('my name') ), ), + contextData, + 'inform', # NotifyType + ntforg.NotificationType( + ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ), cbInfo=(cbFun, snmpEngine) ) diff --git a/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py b/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py index a19bc11..fc4a358 100644 --- a/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py +++ b/examples/v3arch/oneliner/agent/ntforg/inform-async-multiple-transports-and-protocols.py @@ -12,19 +12,19 @@ # * include managed object information specified as var-bind objects pair # from pysnmp.entity.rfc3413.oneliner import ntforg -from pysnmp.entity.rfc3413 import context from pysnmp.entity import engine -from pysnmp.proto import rfc1902 # 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.UdpTransportTarget(('localhost', 162)), + ntforg.ContextData() ), # 2-nd target (SNMPv3 over IPv4/UDP) ( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), - ntforg.UdpTransportTarget(('localhost', 162)) ) + ntforg.UdpTransportTarget(('localhost', 162)), + ntforg.ContextData() ), ) def cbFun(snmpEngine, sendRequestHandle, errorIndication, @@ -43,17 +43,16 @@ snmpEngine = engine.SnmpEngine() ntfOrg = ntforg.AsyncNotificationOriginator() -for authData, transportTarget in targets: +for authData, transportTarget, contextData in targets: sendPduHandle = ntfOrg.sendNotification( snmpEngine, authData, transportTarget, - context.SnmpContext(snmpEngine), - ntforg.null, - 'inform', - ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), - ( ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'), - rfc1902.OctetString('my name') ), ), + contextData, + 'inform', # NotifyType + ntforg.NotificationType( + ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + ).addVarBinds( ( '1.3.6.1.2.1.1.1.0', 'my name' ) ), cbInfo=(cbFun, None) ) diff --git a/examples/v3arch/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py b/examples/v3arch/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py index ca51d28..330b6b2 100644 --- a/examples/v3arch/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py +++ b/examples/v3arch/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py @@ -19,8 +19,11 @@ errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification( ntforg.CommunityData('public'), ntforg.UdpTransportTarget(('localhost', 162)), 'inform', - ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), - ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'my system' ), + ntforg.NotificationType( + ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + ).addVarBinds( + ( ntforg.ObjectIdentity('SNMPv2-MIB', 'sysName', 0), 'my system' ) + ), lookupNames=True, lookupValues=True ) diff --git a/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py b/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py index 60ab7b2..5e8c053 100644 --- a/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py +++ b/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py @@ -20,17 +20,15 @@ from pysnmp.entity.rfc3413.oneliner import ntforg from pysnmp.proto import rfc1902 snmpEngine = engine.SnmpEngine() -snmpContext = context.SnmpContext( - snmpEngine,contextEngineId=rfc1902.OctetString(hexValue='8000000004030201') -) -ntfOrg = ntforg.NotificationOriginator(snmpEngine, snmpContext) +ntfOrg = ntforg.NotificationOriginator(snmpEngine) errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification( ntforg.UsmUserData('usr-md5-none', 'authkey1'), ntforg.UdpTransportTarget(('localhost', 162)), 'inform', - '1.3.6.1.6.3.1.1.5.2' + ntforg.NotificationType(ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')), + contextEngineId=rfc1902.OctetString(hexValue='8000000004030201') ) if errorIndication: diff --git a/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py b/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py index 1d1085e..dfe0ad0 100644 --- a/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py +++ b/examples/v3arch/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py @@ -15,22 +15,17 @@ # the ContextName being used. # from pysnmp.entity import engine -from pysnmp.entity.rfc3413 import context from pysnmp.entity.rfc3413.oneliner import ntforg snmpEngine = engine.SnmpEngine() -snmpContext = context.SnmpContext(snmpEngine) -# register default collection of Managed Objects under new contextName -snmpContext.registerContextName('my-context', snmpContext.getMibInstrum()) - -ntfOrg = ntforg.NotificationOriginator(snmpEngine, snmpContext) +ntfOrg = ntforg.NotificationOriginator(snmpEngine) errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification( ntforg.UsmUserData('usr-md5-none', 'authkey1'), ntforg.UdpTransportTarget(('localhost', 162)), 'inform', - '1.3.6.1.6.3.1.1.5.2', + ntforg.NotificationType(ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2')), contextName='my-context' ) diff --git a/examples/v3arch/oneliner/agent/ntforg/inform-v3.py b/examples/v3arch/oneliner/agent/ntforg/inform-v3.py index 41d996e..f9abe91 100644 --- a/examples/v3arch/oneliner/agent/ntforg/inform-v3.py +++ b/examples/v3arch/oneliner/agent/ntforg/inform-v3.py @@ -19,8 +19,11 @@ errorIndication, errorStatus, errorIndex, varBinds = ntfOrg.sendNotification( ntforg.UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), ntforg.UdpTransportTarget(('localhost', 162)), 'inform', - '1.3.6.1.6.3.1.1.5.2', - ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name')) + ntforg.NotificationType( + ntforg.ObjectIdentity('1.3.6.1.6.3.1.1.5.2') + ).addVarBinds( + ('1.3.6.1.2.1.1.5.0', rfc1902.OctetString('system name')) + ) ) if errorIndication: diff --git a/examples/v3arch/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py b/examples/v3arch/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py index a075fda..c9e955e 100644 --- a/examples/v3arch/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py +++ b/examples/v3arch/oneliner/agent/ntforg/trap-async-multiple-transports-and-protocols.py @@ -12,7 +12,6 @@ # * include managed object information specified as var-bind objects pair # from pysnmp.entity.rfc3413.oneliner import ntforg -from pysnmp.entity.rfc3413 import context from pysnmp.entity import engine from pysnmp.proto import rfc1902 @@ -21,27 +20,31 @@ from pysnmp.proto import rfc1902 targets = ( # 1-st target (SNMPv1 over IPv4/UDP) ( ntforg.CommunityData('public', mpModel=0), - ntforg.UdpTransportTarget(('localhost', 162)) ), + ntforg.UdpTransportTarget(('localhost', 162)), + ntforg.ContextData() ), # 2-nd target (SNMPv2c over IPv4/UDP) ( ntforg.CommunityData('public'), - ntforg.UdpTransportTarget(('localhost', 162)) ) + ntforg.UdpTransportTarget(('localhost', 162)), + ntforg.ContextData() ), ) snmpEngine = engine.SnmpEngine() ntfOrg = ntforg.AsyncNotificationOriginator() -for authData, transportTarget in targets: +for authData, transportTarget, contextData in targets: ntfOrg.sendNotification( snmpEngine, authData, transportTarget, - context.SnmpContext(snmpEngine), - ntforg.null, - 'trap', - ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), - ( ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'), - rfc1902.OctetString('my name') ), ) + contextData, + 'trap', # NotifyType + ntforg.NotificationType( + ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart') + ).addVarBinds( + ( rfc1902.ObjectName('1.3.6.1.2.1.1.1.0'), + rfc1902.OctetString('my name') ) + ) ) snmpEngine.transportDispatcher.runDispatcher() diff --git a/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-custom-values.py b/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-custom-values.py index e2ba44a..7db778e 100644 --- a/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-custom-values.py +++ b/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-custom-values.py @@ -15,6 +15,9 @@ # from pysnmp.entity.rfc3413.oneliner import ntforg from pysnmp.proto import rfc1902 +#from pysnmp import debug + +#debug.setLogger(debug.Debug('mibview')) ntfOrg = ntforg.NotificationOriginator() @@ -22,11 +25,14 @@ errorIndication = ntfOrg.sendNotification( ntforg.CommunityData('public', mpModel=0), ntforg.UdpTransportTarget(('localhost', 162)), 'trap', - '1.3.6.1.4.1.20408.4.1.1.2.0.432', - ('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')) + ntforg.NotificationType( + ntforg.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: diff --git a/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-default-values.py b/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-default-values.py index 4a845f4..beab6e7 100644 --- a/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-default-values.py +++ b/examples/v3arch/oneliner/agent/ntforg/trap-v1-with-default-values.py @@ -22,9 +22,12 @@ errorIndication = ntfOrg.sendNotification( ntforg.CommunityData('public', mpModel=0), ntforg.UdpTransportTarget(('localhost', 162)), 'trap', - '1.3.6.1.6.3.1.1.5.2', - ('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')) + ntforg.NotificationType( + ntforg.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: diff --git a/examples/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py b/examples/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py index 7d01883..502b3a0 100644 --- a/examples/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py +++ b/examples/v3arch/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py @@ -18,8 +18,7 @@ errorIndication = ntfOrg.sendNotification( ntforg.CommunityData('public'), ntforg.UdpTransportTarget(('localhost', 162)), 'trap', - ntforg.MibVariable('SNMPv2-MIB', 'coldStart'), - ( ntforg.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new name' ) + ntforg.NotificationType(ntforg.ObjectIdentity('SNMPv2-MIB', 'coldStart')) ) if errorIndication: diff --git a/examples/v3arch/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py b/examples/v3arch/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py index 7aa72f4..60cb0a6 100644 --- a/examples/v3arch/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py +++ b/examples/v3arch/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py @@ -30,7 +30,9 @@ errorIndication = ntfOrg.sendNotification( privProtocol=ntforg.usmAesCfb128Protocol), ntforg.UdpTransportTarget(('127.0.0.1', 162)), 'trap', - ntforg.MibVariable('SNMPv2-MIB', 'authenticationFailure') + ntforg.NotificationType( + ntforg.ObjectIdentity('SNMPv2-MIB', 'authenticationFailure') + ) ) if errorIndication: |