diff options
author | elie <elie> | 2012-08-30 17:11:38 +0000 |
---|---|---|
committer | elie <elie> | 2012-08-30 17:11:38 +0000 |
commit | 91ff0520b9f700b0dade026facebc4f734780da1 (patch) | |
tree | 82dee46504dd3ae2f7b94f55115f8d5a6c75f659 /docs | |
parent | 70d683ae77ce2c72df439f884c1ef9e78cbe97b8 (diff) | |
download | pysnmp-91ff0520b9f700b0dade026facebc4f734780da1.tar.gz |
more updates
Diffstat (limited to 'docs')
-rw-r--r-- | docs/pysnmp-tutorial.html | 308 |
1 files changed, 203 insertions, 105 deletions
diff --git a/docs/pysnmp-tutorial.html b/docs/pysnmp-tutorial.html index 5ecfa31..f0903ab 100644 --- a/docs/pysnmp-tutorial.html +++ b/docs/pysnmp-tutorial.html @@ -664,13 +664,17 @@ belong to protocol-level </DL> <P> -The following code performs SNMP GET operation using SNMP v2c with -community name 'public' over IPv4/UDP against SNMP Agent at -localhost (UDP port 161) requesting current values for two Managed Objects -specified in string form. +The following code performs SNMP SET operation +<UL> +<LI>using SNMP v2c +<LI>with community name 'public' +<LI>over IPv4/UDP +<LI>against an Agent listening at localhost (UDP port 161) +<LI>requesting two Managed Object Instances specified by name in string form +</UL> </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> from pysnmp.entity.rfc3413.oneliner import cmdgen @@ -750,11 +754,12 @@ The following code performs SNMP SET operation </P> <P> The <A HREF="#MibVariable">MibVariable</A> object is used on input to -allow symbolic Managed Object Instance name specification. Response values -are requested to be returned also in form of a MibVariable object. +allow symbolic Managed Object Instance name specification. Response names +are requested to be returned also in form of a MibVariable object and +response values converted into MIB-defined type. </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> from pysnmp.entity.rfc3413.oneliner import cmdgen @@ -861,9 +866,9 @@ parameter to <STRONG>nextCmd</STRONG> method. <P> In some cases application is also interested in some contiguous set of Managed Objects Instances not necessarily strictly belonging to the same subtree. -The <STRONG>maxRows=NNN</STRONG> parameter to <STRONG>nextCmd</STRONG> would stop -Command Generator once the required number (NNN) of Managed Objects Instances are -retrieved from the Agent. +The <STRONG>maxRows=NNN</STRONG> parameter to <STRONG>nextCmd</STRONG> would +stop Command Generator once the required number (NNN) of Managed Objects +Instances are retrieved from the Agent. </P> <P> @@ -875,30 +880,60 @@ Properties of the <STRONG>varBinds</STRONG> parameter is the same as in <P> The following code performs SNMP GETNEXT operation against a MIB subtree -over SNMPv3: +<UL> +<LI>using SNMP v1 +<LI>with community name 'public' +<LI>over IPv4/UDP +<LI>against an Agent listening at localhost (UDP port 161) +<LI>for some columns of the IF-MIB::ifEntry table +<LI>stop reading values from Agent once response names leave the scopes of +initial names (e.g. OBJECT IDENTIFIER's) +</UL> +</P> + +<P> +The <A HREF="#MibVariable">MibVariable</A> object is used on input to +allow symbolic MIB table columns specification. Response values +are requested to be converted into MIB-defined type. </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<P> +Note: the code below needs access to IF-MIB (e.g. IF-MIB.py) which +is installed with the <A HREF="https://sourceforge.net/projects/pysnmp/files/pysnmp-mibs/">pysnmp-mibs package</A> or could be +<A HREF="#DATA-MODEL-MANAGED-OBJECTS">converted manually</A> into +pysnmp MIB module from IF-MIB text source. +</P> + +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> ->>> from pysnmp.entity.rfc3413.oneliner import cmdgen ->>> errorIndication, errorStatus, errorIndex, varBindTable = cmdgen.CommandGenerator().nextCmd( -... cmdgen.UsmUserData('my-user', 'my-authkey', 'my-privkey'), -... cmdgen.UdpTransportTarget(('localhost', 161)), -... '1.3.6.1.2.1.1' -... ) ->>> print(errorIndication) -None ->>> print(errorStatus) -0 ->>> for varBindTableRow in varBindTable: -... print(varBindTableRow) -... -[(ObjectName('1.3.6.1.2.1.1.1.0'), OctetString("'Linux saturn 2.6.21 - #2 Mon Mar 19 17:07:18 MSD 2006 i686'"))] -[(ObjectName('1.3.6.1.2.1.1.2.0'), ObjectIdentifier('1.3.6.1.4.1.8072.3.2.10'))] -[ skipped ] -[(ObjectName('1.3.6.1.2.1.1.9.1.4.9'), TimeTicks('17'))] ->>> +from pysnmp.entity.rfc3413.oneliner import cmdgen + +cmdGen = cmdgen.CommandGenerator() + +errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd( + cmdgen.CommunityData('public', mpModel=0), + cmdgen.UdpTransportTarget(('localhost', 161)), + cmdgen.MibVariable('IF-MIB', 'ifDescr'), + cmdgen.MibVariable('IF-MIB', 'ifType'), + cmdgen.MibVariable('IF-MIB', 'ifMtu'), + cmdgen.MibVariable('IF-MIB', 'ifSpeed'), + cmdgen.MibVariable('IF-MIB', 'ifPhysAddress'), + lookupValues=True +) + +if errorIndication: + print(errorIndication) +else: + if errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' + ) + ) + else: + for varBindTableRow in varBindTable: + for name, val in varBindTableRow: + print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) </PRE> </TD></TR></TABLE> @@ -959,31 +994,48 @@ having same meaning as in <A HREF="#CommandGenerator.nextCmd">nextCmd</A> method <P> The following code performs SNMP GETBULK operation against a MIB subtree -over SNMPv3: +<UL> +<LI>using SNMP v3 +<LI>with SNMPv3, user 'usr-sha-aes128', SHA auth, AES128 privacy +<LI>over IPv6/UDP +<LI>against an Agent listening at ::1 (UDP port 161) +<LI>with values non-repeaters = 0, max-repetitions = 20 +<LI>for the SNMPv2-MIB::system subtree +<LI>stop reading values from Agent once response names leave the scopes of +initial names (e.g. OBJECT IDENTIFIER's) +</UL> +</P> + +<P> +The <A HREF="#MibVariable">MibVariable</A> object is used on input to +allow symbolic MIB table columns specification. </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> ->>> from pysnmp.entity.rfc3413.oneliner import cmdgen ->>> errorIndication, errorStatus, errorIndex, varBindTable = cmdgen.CommandGenerator().bulkCmd( -... cmdgen.UsmUserData('my-user', 'my-authkey', 'my-privkey'), -... cmdgen.UdpTransportTarget(('localhost', 161)), -... 0, 25, # nonRepeaters, maxRepetitions -... '1.3.6.1.2.1.1' -... ) ->>> print(errorIndication) -None ->>> print(errorStatus) -0 ->>> for varBindTableRow in varBindTable: -... print(varBindTableRow) -... -[(ObjectName('1.3.6.1.2.1.1.1.0'), OctetString("'Linux saturn 2.6.21 - #2 Mon Mar 19 17:07:18 MSD 2006 i686'"))] -[(ObjectName('1.3.6.1.2.1.1.2.0'), ObjectIdentifier('1.3.6.1.4.1.8072.3.2.10'))] -[ skipped ] -[(ObjectName('1.3.6.1.2.1.1.9.1.4.9'), TimeTicks('17'))] ->>> +errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd( + cmdgen.UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1', + authProtocol=cmdgen.usmHMACSHAAuthProtocol, + privProtocol=cmdgen.usmAesCfb128Protocol), + cmdgen.UdpTransportTarget(('localhost', 161)), + 0, 20, + cmdgen.MibVariable('SNMPv2-MIB', 'system') +) + +if errorIndication: + print(errorIndication) +else: + if errorStatus: + print('%s at %s' % ( + errorStatus.prettyPrint(), + errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' + ) + ) + else: + for varBindTableRow in varBindTable: + for name, val in varBindTableRow: + print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) + </PRE> </TD></TR></TABLE> @@ -1061,7 +1113,7 @@ in <A HREF="#CommandGenerator.getCmd">getCmd</A> method. The following code sends SNMP TRAP over SNMPv3: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> >>> from pysnmp.entity.rfc3413.oneliner import cmdgen, ntforg >>> from pysnmp.proto.api import v2c @@ -1336,7 +1388,7 @@ The following code performs SNMP GET operation asynchronously through SNMPv3: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> >>> from pysnmp.entity.rfc3413.oneliner import cmdgen >>> @@ -1483,7 +1535,7 @@ The following code sends SNMP INFORM notification asynchronously through SNMPv3: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> >>> from pysnmp.entity.rfc3413.oneliner import cmdgen, ntforg >>> from pysnmp.proto.api import v2c @@ -1739,7 +1791,7 @@ instead of <STRONG>ObjectName</STRONG> objects. <P> Create an object representing a varying amount of Managed Object Name -information. As a bare minimum <STRONG>MibVariable</STRONG> object +information. At the bare minimum <STRONG>MibVariable</STRONG> object will only hold an OBJECT IDENTIFIER that identifies particular Managed Object. However more information on Managed Object may be gathered by PySNMP during the course of SNMP request processing. @@ -1801,6 +1853,7 @@ are interpreted as an sub-OBJECT IDENTIFIER </UL> </DD> +</DL> <P> Methods of the <STRONG>MibVariable</STRONG> objects are as follows: @@ -1849,8 +1902,8 @@ identified by this particular name. Return <STRONG>True</STRONG> if MIB lookup for initial initializers was successful and complete MIB information is available. </P> -</DD> +</DD> </DL> <A NAME="VAL-IMPL"></A> @@ -2098,11 +2151,11 @@ a single SNMP entity. </H4> <P> -In PySNMP, <A HREF="#MANAGED-OBJECTS">Managed Objects</A> take shape of -Python class instances that implement various -<A HREF="#SMI">SMIv2</A> items. Collections of Managed Objects, or -<A HREF="#MIB">MIB</A>s, translate, in a one-to-one fashion, into Python -modules. +In PySNMP, <A HREF="#MANAGED-OBJECTS">Managed Objects</A> specified in MIBs +take shape of Python objects that implement various kinds of +<A HREF="#SMI">SMIv2</A> definitions. +Managed Objects specified in a <A HREF="#MIB">MIB</A> file translate +in a one-to-one fashion into Python modules. </P> <P> @@ -2125,9 +2178,15 @@ implements the following classes: )</DT> <DD> <P> -Create a definition of scalar Managed Object with name -<STRONG>name</STRONG> and associated value of type -<STRONG>syntax</STRONG>. +A representation of a scalar Managed Object specification identified by +<STRONG>name</STRONG> with associated value of type <STRONG>syntax</STRONG>. +Objects of this kind never hold actual values, rather they serve the following +purposes: +<UL> +<LI>Logically bind Managed Object Name with Value +<LI>Specify value type (including TEXTUAL-CONVENTION-based constraints) +<LI>Provide human-friendly Managed Object name and value representation +</UL> </P> <A NAME="MANAGED-OBJECT-NAME"></A> @@ -2139,8 +2198,8 @@ either a tuple of integers or tuple-like </P> <P> -The <STRONG>syntax</STRONG> parameter represents Managed Object's -<A HREF="#MANAGED-OBJECT-SYNTAX">value type</A>. +The <STRONG>syntax</STRONG> parameter represents Managed Object Instance +<A HREF="#VAL-IMPL">value type</A>. </P> </DD> </DL> @@ -2150,21 +2209,53 @@ The <STRONG>MibScalar</STRONG> class implements the following methods: </P> <A NAME="MibScalar.getName"></A> -<A NAME="MibScalar.getSyntax"></A> -<A NAME="MibScalar.getMaxAccess"></A> -<A NAME="MibScalar.getUnits"></A> -<A NAME="MibScalar.getStatus"></A> -<A NAME="MibScalar.getDescription"></A> <DL> <DT><STRONG>getName</STRONG>()</DT> +<DD> +<P> +Return the <STRONG>name</STRONG> initializer an +<A HREF="http://pyasn1.sourceforge.net/#1.1.8">OctetIdentifier</A> object. +</P> +</DD> +</DL> + +<A NAME="MibScalar.getSyntax"></A> +<DL> <DT><STRONG>getSyntax</STRONG>()</DT> -<DT><STRONG>getMaxAccess</STRONG>()</DT> +<DD> +<P> +Return the <STRONG>syntax</STRONG> initializer which is a +<A HREF="#VAL-IMPL">PyASN1 object</A> including its +<A HREF="#TEXTUAL-CONVENTION-AS-A-TYPE">TEXTUAL-CONVENTION</A> +derivative. The <STRONG>syntax</STRONG> object does not carry any value, it +denotes an acceptable type specifier and may be used for cloning +compliant objects for building SNMP messages or pretty printing concrete +values. +</P> +</DD> +</DL> + +<A NAME="MibScalar.getUnits"></A> +<DL> <DT><STRONG>getUnits</STRONG>()</DT> -<DT><STRONG>getStatus</STRONG>()</DT> +<DD> +<P> +Return value units in form of a Python string. This is mostly used for +pretty printing things like "10 seconds", not just "10". +</P> +</DD> +</DL> + +<A NAME="MibScalar.getDescription"></A> +<DL> <DT><STRONG>getDescription</STRONG>()</DT> <DD> <P> -Each of these methods return certain property of Managed Object. +Return a textual, human-readable description of the Managed Object semantics, +meaning, uses and restrictions. Since these descriptions may be quite large, +they are not loaded into memory by default. This setting can be altered +through a property of <A HREF="#MibBuilder">MibBuilder</A>. + </P> </DD> </DL> @@ -2176,16 +2267,19 @@ Each of these methods return certain property of Managed Object. )</DT> <DD> <P> -Create an instance of scalar Managed Object or +A representation of scalar Managed Object Instance or <A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> element -with name <STRONG>name</STRONG> and associated value -<STRONG>syntax</STRONG>. +with <STRONG>name</STRONG> and associated value carried by the +<STRONG>syntax</STRONG> object. This class is a subclass of +<A HREF="#MibScalar">MibScalar</A> but, unlike +<STRONG>MibScalar</STRONG>, it represents existing Managed +Object holding a value. </P> <P> -The <STRONG>name</STRONG> of Managed Object instance is a concatination -of <STRONG>name</STRONG> of Managed Object definition and some -instance identifier. For scalar types, instance identifier is a single +The <STRONG>name</STRONG> of Managed Object Instance is a concatination +of <STRONG>name</STRONG> of a Managed Object and instance identifier. +For scalar Managed Objects, instance identifier is always a single zero (0,). For <A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> elements instance identifier is a concatination of table indices. </P> @@ -2204,10 +2298,11 @@ have the same meaning as in <A HREF="#MibScalar">MibScalar</A> class. )</DT> <DD> <P> -Create a definition of -<A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> Column with -name <STRONG>name</STRONG> and associated value of type -<STRONG>syntax</STRONG>. +A representation of +<A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> Column +specification with <STRONG>name</STRONG> and associated value +of type <STRONG>syntax</STRONG>. This class is a subclass of +<A HREF="#MibScalar">MibScalar</A>. </P> <P> @@ -2251,9 +2346,10 @@ is instantiated. )</DT> <DD> <P> -Create a definition of -<A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> Row with -name <STRONG>name</STRONG>. +A representation of a <A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> +Row specification with <STRONG>name</STRONG>. +This class is a subclass of <A HREF="#MibScalar">MibScalar</A> although +it can't have any associated value. </P> <P> @@ -2310,9 +2406,11 @@ The number of types of returned index values depend on MIB Table definition. )</DT> <DD> <P> -Create a definition of -<A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> with name -<STRONG>name</STRONG>. +Represents +<A HREF="#CONCEPTUAL-TABLES">Conceptual Table</A> specification +with <STRONG>name</STRONG>. This class is a subclass of +<A HREF="#MibScalar">MibScalar</A> although it can't have +any associated value. </P> <P> @@ -2327,7 +2425,7 @@ The following examples explain how MIB text could be expressed in terms of PySNMP SMI data model. First example is on a scalar: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> myManagedObject = MibScalar((1, 3, 6, 1, 4, 1, 20408, 2, 1), OctetString()).setMaxAccess("readonly") @@ -2342,7 +2440,7 @@ associated with its parent Managed Object, by the on the basis of their names relation. </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> myManagedObjectInstance = MibScalarInstance(myManagedObject.getName() + (0,), myManagedObject.getSyntax().clone('my string')) @@ -2353,7 +2451,7 @@ myManagedObjectInstance = MibScalarInstance(myManagedObject.getName() + (0,), Let's consider SNMP Conceptual Table created in an "MY-MIB.py" file: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> myTable = MibTable((1, 3, 6, 1, 4, 1, 20408, 2, 1)) myTableEntry = MibTableRow(myTable.getName() + (1,)).setIndexNames((0, "MY-MIB", "myTableIndex")) @@ -2367,7 +2465,7 @@ Populate Managed Objects table with Managed Objects Instance in the first column. </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> myTableValueInstance = MibScalarInstance(myTableValue.getName() + (1,), myTableValue.getSyntax().clone('my value')) @@ -2529,7 +2627,7 @@ In the following example MIB builder will be created, MIB modules loaded up and Managed Object definition looked up by symbolic name: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> >>> from pysnmp.smi import builder >>> @@ -2643,7 +2741,7 @@ raised. </DD> </DL> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> >>> from pysnmp.smi import builder, view >>> @@ -2717,7 +2815,7 @@ as used in <A HREF="#MibBuilder">MibBuilder</A> interface. The </DD> </DL> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> >>> from pysnmp.smi import builder, view >>> @@ -2812,7 +2910,7 @@ Instance would represent particular file contents. File contents would be solely dependent on SNMP updates. </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> class MyFile(OctetString): def clone(self, value=None): @@ -2838,7 +2936,7 @@ following code would be run periodically to measure most recent file size and re-build its SMI projection: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> myManagedObjectInstance = MibScalarInstance( (1, 3, 6, 1, 4, 1, 20408, 1), Integer(os.stat('/var/adm/messages')[6]) @@ -2976,7 +3074,7 @@ sources. The following is a re-implementation of file size monitor: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> class FileWatcherInstance(MibScalarInstance): def readTest(self, name, val, idx, (acFun, acCtx)): @@ -3089,7 +3187,7 @@ The following is a re-implementation of SMI-to-filesystem binding for file modification: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> class MyFileInstance(MibScalarInstance): def writeTest(self, name, val, idx, (acFun, acCtx)): @@ -3220,7 +3318,7 @@ may destroy previously created object at a third-party system. The following is a SMI-to-filesystem binding for file creation: </P> -<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=100%><TR><TD> +<TABLE BGCOLOR="lightgray" BORDER=0 WIDTH=90% ALIGN=CENTER><TR><TD> <PRE> class MyFileInstance(MibScalarInstance): def createTest(self, name, val, idx, (acFun, acCtx)): |