From f849e7306a11b5858725c312ec56b096b7d7eda3 Mon Sep 17 00:00:00 2001 From: elie Date: Mon, 3 Sep 2012 21:45:38 +0000 Subject: updates --- docs/pysnmp-tutorial.html | 210 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 194 insertions(+), 16 deletions(-) (limited to 'docs') diff --git a/docs/pysnmp-tutorial.html b/docs/pysnmp-tutorial.html index 37a7f2d..3d19594 100644 --- a/docs/pysnmp-tutorial.html +++ b/docs/pysnmp-tutorial.html @@ -1018,8 +1018,8 @@ initial names (e.g. OBJECT IDENTIFIER's)

-The MibVariable object is used on input to -allow symbolic MIB table columns specification. + The MibVariable object is used on input to + allow symbolic MIB table columns specification.

@@ -1081,8 +1081,8 @@ for as long as possible within user applicatin.

-The following method of NotificationOriginator class instance -implements specific notifications types. +All notifications are sent by in invocation of the following method: +

@@ -1116,9 +1116,54 @@ unconfirmed notification or "inform" for a confirmed one.

The notificationType parameter indicates the kind of event to notify Manager about in form of SMI NOTIFICATION-TYPE object -name. For instance, (('SNMPv2-MIB', 'coldStart'),) or (1,3,6,1,6,3,1,1,5,1) -is a value of coldStart notification type as defined in SNMPv2-MIB module. -

+name. Either +ObjectIdentifier class +instance, its initialization value (like '1.3.6.1.6.3.1.1.5.1') or +MibVariable object can be used on input to +allow MIB symbols references. +For example, '1.3.6.1.6.3.1.1.5.1' or MibVariable('SNMPv2-MIB', 'coldStart') +specify SNMPv2-MIB::coldStart type of trap. +

+ +

+When sending SNMP v1 traps, the notificationType +parameter encodes both Generic and Specific trap numbers +hardwired into SNMP v1 TRAP PDU, but missing in SNMP v2c TRAP and INFORM +PDUs. +

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+notificationType + +GenericTrap + +SpecificTrap +
1.3.6.1.6.3.1.1.5.1coldStart(0)0
1.3.6.1.6.3.1.1.5.2warmStart(1)0
1.3.6.1.6.3.1.1.5.3linkDown(2)0
1.3.6.1.6.3.1.1.5.4linkUp(3)0
1.3.6.1.6.3.1.1.5.5authenticationFailure(4)0
1.3.6.1.6.3.1.1.5.6egpNeighborLoss(5)0
1.3.6.1.6.3.1.1.5.0.1enterpriseSpecific(6)1
1.3.6.1.6.3.1.1.5.0.999enterpriseSpecific(6)999
1.3.6.1.6.3.1.1.5.0.NenterpriseSpecific(6)N

The *varBinds input parameter is a tuple of Managed @@ -1133,11 +1178,31 @@ The sendNotification method returns an in getCmd method.

+

+When sending SNMP traps to a SNMPv1 system, PDU parameters +that are present in SNMPv1 PDU but are missing in SNMPv2c PDU +are mapped one to another via special Managed Objects Inctance +values in *varBinds. +

+ +
    +
  • SNMP v1 PDU enterprise parameter is passed as a value of +1.3.6.1.6.3.1.1.4.3.0 Managed Object Instance in *varBinds. +If not specified, the default value is 1.3.6.1.6.3.1.1.5. If Generic +encoded in notificationType is enterpriseSpecific, +the enterprise parameter is implicitly initialized into +notificationType value minus trailing sub-OID. +
  • SNMP v1 PDU agent-addr parameter is passed as a value of +1.3.6.1.6.3.18.1.3.0 Managed Object Instance in *varBinds. +
  • SNMP v1 PDU time-stamp parameter is passed as a value of +1.3.6.1.2.1.1.3.0 Managed Object Instance in *varBinds. +
+

-The following code sends SNMP TRAP message: +The following code sends SNMP v2c TRAP message:

  • using SNMP v2c
  • with community name 'public' @@ -1166,6 +1231,43 @@ if errorIndication:
+

+The following code sends SNMP v1 TRAP message: +

+

+
+
+from pysnmp.entity.rfc3413.oneliner import ntforg
+from pysnmp.proto import rfc1902
+
+ntfOrg = ntforg.NotificationOriginator()
+
+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'))
+)
+
+if errorIndication:
+    print('Notification not sent: %s' % errorIndication)
+
+
+

2.1.2 Asynchronous One-line Applications @@ -1191,6 +1293,16 @@ All Command Generator Applications are implemented within a single class:

Create an asynchronous SNMP Command Generator object.

+ +

+Although instantiation of this class is cheap, in the course of its further +use, SNMP engine configuration is built and maintained though methods +invocation. +Therefore it is advised to keep and reuse CommandGenerator instance +(or snmpEngine instance if passed as an initializer) +for as long as possible within user applicatin. +

+ @@ -1220,7 +1332,7 @@ Prepare SNMP GET request to be dispatched. Return the

The cbFun parameter is a reference to a callable object -(such as Python function) that takes the following parameters: +(such as a Python function) having the following signature:

@@ -1254,13 +1366,10 @@ have the same meaning as in getCmd method.

-

-If cbFun has no more requests pending and want to complete, -it must return a true value. Otherwise, it returns false. -

+

The authData, transportTarget, varNames, lookupNames and @@ -1278,6 +1387,71 @@ matching subsequent response to this request. +

+The following code performs multiple, simultaneous SNMP GET operations +against distinct Agents identified by their transport addresses. +Authentication information and queried Managed Objects Instances used in +this example are the same for all targets. So the GET operation is performed: +

+

+ +
+
+from pysnmp.entity.rfc3413.oneliner import cmdgen
+
+def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx):
+    if errorIndication:
+        print(errorIndication)
+        return
+    if errorStatus:
+        print('%s at %s' % (errorStatus.prettyPrint(),
+                            errorIndex and varBinds[int(errorIndex)-1] or '?')
+        )
+        return
+    
+    for oid, val in varBinds:
+        if val is None:
+            print(oid.prettyPrint())
+        else:
+            print('%s = %s' % (oid.prettyPrint(), val.prettyPrint()))
+
+cmdGen  = cmdgen.AsynCommandGenerator()
+
+for transportTarget in ( cmdgen.UdpTransportTarget(('127.0.0.1', 161)),
+                         cmdgen.UdpTransportTarget(('127.0.0.2', 161)),
+                         cmdgen.UdpTransportTarget(('127.0.0.3', 161)) ):
+    cmdGen.getCmd(
+        cmdgen.CommunityData('public'),
+        cmdgen.UdpTransportTarget(('localhost', 161)),
+        ( cmdgen.MibVariable('SNMPv2-MIB', 'sysDescr', 0),
+          cmdgen.MibVariable('SNMPv2-MIB', 'sysLocation', 0) ),
+        # User-space callback function and its context
+        (cbFun, None),
+        lookupNames=True, lookupValues=True
+    )
+
+cmdGen.snmpEngine.transportDispatcher.runDispatcher()
+
+
+ +

+It is trivial to modify the above code to make it using different +SNMP versions, credentials and query different Managed Objects Instances +per each target. +

+ +

+All queries are made in parallel, so with default timeout and retries +settings, the above code will terminate in 6 seconds regardless of +Agents avialability and responsiveness. +

+
asyncSetCmd( @@ -1299,7 +1473,7 @@ Prepare SNMP SET request to be dispatched. Return the The authData, transportTarget, varNames, lookupNames and lookupValues parameters have the same meaning as in - method except that +setCmd method except that varBinds is passed as a sequence, not as individual Managed Objects Instances.

@@ -1343,6 +1517,10 @@ Managed Objects Instances names. The cbFun and cbCtx parameters have the same meaning as in AsynCommandGenerator.asyncGetCmd method. +Appliction can indicate to GETNEXT SNMP Application that it is no more +interested in further information from Agent and wishes to stop by +returning True from the cbFun. Otherwise it should return +False.

@@ -1384,8 +1562,8 @@ Managed Objects Instances names.

The cbFun and cbCtx parameters -have the same meaning as in -AsynCommandGenerator.asyncGetCmd method. +have the same meaning as in +AsynCommandGenerator.asyncNextCmd method.

-- cgit v1.2.1