summaryrefslogtreecommitdiff
path: root/examples/v3arch/asyncore/oneliner/agent
diff options
context:
space:
mode:
Diffstat (limited to 'examples/v3arch/asyncore/oneliner/agent')
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py42
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py46
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py43
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py44
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py36
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py34
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py27
-rw-r--r--examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py37
8 files changed, 309 insertions, 0 deletions
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py
new file mode 100644
index 0000000..6eebaa9
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v2c-with-mib-lookup.py
@@ -0,0 +1,42 @@
+#
+# 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
+#
+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 ]))
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py
new file mode 100644
index 0000000..071c336
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextengineid.py
@@ -0,0 +1,46 @@
+#
+# 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.
+#
+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 ]))
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py
new file mode 100644
index 0000000..ed87fdc
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3-with-custom-contextname.py
@@ -0,0 +1,43 @@
+#
+# 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.
+#
+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 ]))
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py
new file mode 100644
index 0000000..2996eb5
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/inform-v3.py
@@ -0,0 +1,44 @@
+##
+# 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'
+#
+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 ]))
+
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py
new file mode 100644
index 0000000..1d2b825
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-custom-values.py
@@ -0,0 +1,36 @@
+#
+# 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'
+#
+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)
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py
new file mode 100644
index 0000000..a704146
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v1-with-default-values.py
@@ -0,0 +1,34 @@
+#
+# 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'
+#
+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)
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py
new file mode 100644
index 0000000..b243f43
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v2c-with-mib-lookup.py
@@ -0,0 +1,27 @@
+#
+# 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
+#
+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)
diff --git a/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py
new file mode 100644
index 0000000..bbc9194
--- /dev/null
+++ b/examples/v3arch/asyncore/oneliner/agent/ntforg/trap-v3-with-custom-engineid.py
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+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)