1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html lang=
"en-gb"><head><title>LuaSNMP - Reference
</title>
64 <link media=
"screen" href=
"style.css" rel=
"stylesheet" type=
"text/css" />
102 <link media=
"print" rel=
"stylesheet" href=
"styleprint.css" type=
"text/css" /></head><body>
134 <div style=
"top: 12px; height: 129px; left: 0px; text-align: center; width: 925px;" id=
"logo"><a name=
"home2" /><a href=
"http://www.lua.org"><img style=
"border: 0px solid ; left: 0px; top: 6px; width: 115px; height: 118px; float: left;" id=
"lualogo" alt=
"www.lua.org" src=
"luasnmp2.png" hspace=
"20" /></a></div>
155 <h1 style=
"height: 120px; margin-left: 0px; width: 928px;"><big><big><a name=
"home"><br />
175 LuaSNMP - Reference
</a></big><a name=
"home" /></big><a name=
"home"> <br />
195 Network Management Access with Lua
</a></h1>
235 <div id=
"leftnavigation">
256 <a name=
"home"> </a><li style=
"margin-left: 0px; width: 185px;"><a class=
"current" href=
"index.html">Home
</a>
277 <li><a href=
"index.html#license">License
</a></li>
297 <li><a href=
"index.html#features">Features
</a></li>
317 <li><a href=
"index.html#download">Download
</a></li>
337 <li><a href=
"index.html#installation">Installation
</a></li>
357 <li><a href=
"running.html">MANUAL
</a></li>
415 <li><a href=
"running.html">Running
</a></li>
435 <li><a href=
"#object_names">Object Names
</a></li>
451 <li><a href=
"#data_types"><span style=
"text-decoration: underline;"><span style=
"font-weight: bold;">Data Types
</span></span></a></li>
453 <li><a href=
"#datatype_general"><span style=
"text-decoration: underline;"><span style=
"font-weight: bold;">General
</span></span></a></li>
454 <li><a href=
"#counter64"><span style=
"text-decoration: underline;"><span style=
"font-weight: bold;">Counter64
</span></span></a></li>
470 <li><a href=
"#varbinds">Varbinds
</a></li>
506 <li><a href=
"#varbinds_general">General
</a></li>
517 <li><a href=
"#varbind_meta">Metamethods
</a></li>
549 <li><a href=
"#sessions">SNMP Sessions
</a></li>
562 <li><a href=
"#trap_handling">Trap Handling
</a></li>
571 <li><a href=
"mib.html">Access to MIBs
</a></li>
591 <li><a href=
"snmp.html">Access to SNMP
</a></li>
611 <li><a href=
"examples.html">Examples
</a> </li>
669 <li><a href=
"index.html#whatsnew">What's New
</a></li>
689 <li><a href=
"index.html#credits">Credits
</a></li>
709 <li><a href=
"index.html#links">Links
</a></li>
729 <li><a href=
"index.html#todo">ToDo
</a></li>
790 <h1><a name=
"object_names">Object Names
</a></h1>
804 <p><a name=
"object_names">Most functions in LuaSNMP accept either object identifiers in pseudo-numerical dot-notation or symbolic object names
</a></p>
818 <p><a name=
"object_names">Here are some basic rules:
</a></p>
846 <li>Object names
<span style=
"font-style: italic;">may
</span> have an index suffix, e.g. sysContact.
<span style=
"font-weight: bold;">0</span></li>
860 <li>Object identifiers or OIDs
<span style=
"font-style: italic;">must
</span> follow a textual dot-notation, e.g.
"1.3.6.1.2.1.1.4"</li>
874 <li>Object identifiers
<span style=
"font-style: italic;">may
</span> have an index suffix, e.g.
"1.3.6.1.2.1.1.4.<span style="font-weight: bold;
">0</span>"</li>
888 <li>Most function accept a mixed notation using node IDs or symbolic names, e.g. iso.org.dod.internet.mgmt.mib-
2.
<span style=
"font-weight: bold;">1</span>.sysContact.
<span style=
"font-weight: bold;">0</span></li>
902 <li>Any object name or object identifier
<span style=
"font-style: italic;">may
</span> be prepended by a module name, separated by a double or a single colon, e.g.
<span style=
"font-weight: bold;">SNMPv2-MIB
</span>::sysContact
.0 or
<span style=
"font-weight: bold;">SNMPv2-MIB:
</span>1.3.6.1.2.1.1.4.0<br />
917 Note, that the module name becomes an integral part of an object name. The object will not be found if the module name is wrong.
</li>
945 <h3><a name=
"datatype_general">General
</a></h3>
957 <p>LuaSNMP maps SNMP data types to Lua basic types as specified in the
958 table below. SNMP basic data types are associated to a set of
959 numerical
"codes". These numerical codes are used by the LuaSNMP
960 functions when identifying the SNMP data type of a given variable
961 instance value. Additionally LuaSNMP maintains a database to map the numerical codes to textual type names.
</p>
974 <table style=
"width: 658px; height: 795px;" border=
"1" bordercolor=
"#000000" cellpadding=
"4" cellspacing=
"1">
1007 <td bgcolor=
"#ffffff" valign=
"top" width=
"23%">
1008 <font size=
"-1"><b>SNMP Type
</b></font></td>
1020 <td bgcolor=
"#ffffff" valign=
"top" width=
"26%">
1021 <font size=
"-1"><b>LuaSNMP Code
</b></font></td>
1033 <td bgcolor=
"#ffffff" valign=
"top" width=
"12%">
1034 <font size=
"-1"><b>Lua Type
</b></font></td>
1046 <td bgcolor=
"#ffffff" valign=
"top" width=
"38%">
1047 <font size=
"-1"><b>Representation
</b></font></td>
1082 <td valign=
"top" width=
"23%">
1083 <font size=
"-1">OBJECT IDENTIFIER
</font></td>
1095 <td valign=
"top" width=
"26%">
1096 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_OBJID (
1)
</font></td>
1108 <td valign=
"top" width=
"12%">
1109 <font size=
"-1">string
</font></td>
1121 <td valign=
"top" width=
"38%">
1122 <font size=
"-1">Decimal numbers separated by dots (
<i>dotted notation
</i>). e.g.:
"1.3.6.1.2.1.1.5"</font></td>
1157 <td valign=
"top" width=
"23%">
1158 <font size=
"-1">OCTET STRING
</font></td>
1170 <td valign=
"top" width=
"26%">
1171 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_OCTETSTR (
2)
</font></td>
1183 <td valign=
"top" width=
"12%">
1184 <font size=
"-1">string
</font></td>
1196 <td valign=
"top" width=
"38%">
1197 <font size=
"-1">Hexadecimal numbers (
00 to ff) separated by colons.
<br />
1209 <font size=
"-1">e.g.:
"00:00:80:a4:32:f3"</font></td>
1244 <td valign=
"top" width=
"23%">
1245 <font size=
"-1">INTEGER
</font></td>
1257 <td valign=
"top" width=
"26%">
1258 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_INTEGER (
3)
</font></td>
1270 <td valign=
"top" width=
"12%">
1271 <font size=
"-1">number
</font></td>
1283 <td valign=
"top" width=
"38%">
1284 <font size=
"-1"> </font></td>
1319 <td valign=
"top" width=
"23%">
1320 <font size=
"-1">NetworkAddress
</font></td>
1332 <td valign=
"top" width=
"26%">
1333 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_NETADDR (
4)
</font></td>
1345 <td valign=
"top" width=
"12%">
1346 <font size=
"-1">string
</font></td>
1358 <td valign=
"top" width=
"38%">
1359 <font size=
"-1">Decimal numbers (
0 to
255) separated by dots (
<i>dotted notation
</i>).
1371 </font><font size=
"-1">e.g.:
"139.82.95.11"</font></td>
1406 <td valign=
"top" width=
"23%">
1407 <font size=
"-1">IpAddress
</font></td>
1419 <td valign=
"top" width=
"26%">
1420 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_IPADDR (
5)
</font></td>
1432 <td valign=
"top" width=
"12%">
1433 <font size=
"-1">string
</font></td>
1445 <td valign=
"top" width=
"38%">
1446 <font size=
"-1">Similar to NetworkAddress.
</font></td>
1481 <td valign=
"top" width=
"23%">
1482 <font size=
"-1">Counter
</font></td>
1494 <td valign=
"top" width=
"26%">
1495 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_COUNTER (
6)
</font></td>
1507 <td valign=
"top" width=
"12%">
1508 <font size=
"-1">number
</font></td>
1520 <td valign=
"top" width=
"38%">
1521 <font size=
"-1"> </font></td>
1556 <td valign=
"top" width=
"23%">
1557 <font size=
"-1">Gauge32
</font></td>
1569 <td valign=
"top" width=
"26%">
1570 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_GAUGE (
7)
</font></td>
1582 <td valign=
"top" width=
"12%">
1583 <font size=
"-1">number
</font></td>
1595 <td valign=
"top" width=
"38%">
1596 <font size=
"-1"> </font></td>
1631 <td valign=
"top" width=
"23%">
1632 <font size=
"-1">TimeTicks
</font></td>
1644 <td valign=
"top" width=
"26%">
1645 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_TIMETICKS (
8)
</font></td>
1657 <td valign=
"top" width=
"12%">
1658 <font size=
"-1">table
</font></td>
1670 <td valign=
"top" width=
"38%">
1671 <font size=
"-1">A table representing a record structure with fields:
<i>ticks
</i>(raw value)
<i>, days, hours, minutes, seconds e deciseconds
</i>. Each field contains a numerical value.
</font></td>
1706 <td valign=
"top" width=
"23%">
1707 <font size=
"-1">Opaque
</font></td>
1719 <td valign=
"top" width=
"26%">
1720 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_OPAQUE (
9)
</font></td>
1732 <td valign=
"top" width=
"12%">
1733 <font size=
"-1">string
</font></td>
1745 <td valign=
"top" width=
"38%">
1746 <font size=
"-1">Similar to OCTET STRING.
</font></td>
1781 <td valign=
"top" width=
"23%">
1782 <font size=
"-1">NULL
</font></td>
1794 <td valign=
"top" width=
"26%">
1795 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_NULL (
10)
</font></td>
1807 <td valign=
"top" width=
"12%">
1808 <font size=
"-1">nil
</font></td>
1820 <td valign=
"top" width=
"38%">
1821 <font size=
"-1"><b>nil
</b></font></td>
1856 <td valign=
"top" width=
"23%">
1857 <font size=
"-1">Counter64
</font></td>
1869 <td valign=
"top" width=
"26%">
1870 <font size=
"-1">snmp.
</font><font size=
"-1">TYPE_COUNTER64 (
11)
</font></td>
1882 <td valign=
"top" width=
"12%">
1883 userdata
<font size=
"-1" /></td>
1895 <td valign=
"top" width=
"38%">
1896 <font size=
"-1">see
<a href=
"#counter64">Counter64
</a></font></td>
1931 <td><font size=
"-1">Bitstring
</font></td>
1942 <td><font size=
"-1">snmp.
</font><font size=
"-1">TYPE_BITSTRING (
12)
</font></td>
1953 <td><font size=
"-1">string
</font></td>
1964 <td><font size=
"-1">Binary number, e.g.
"10010001"</font></td>
1997 <td><font size=
"-1">NsapAddress
</font></td>
2008 <td><font size=
"-1">snmp.
</font><font size=
"-1">TYPE_NSAPADDRESS(
13)
</font></td>
2019 <td><font size=
"-1">string
</font></td>
2030 <td><font size=
"-1"><br />
2064 <td><font size=
"-1">UInteger
</font></td>
2075 <td><font size=
"-1">snmp.
</font><font size=
"-1">TYPE_UINTEGER (
14)
</font></td>
2086 <td><font size=
"-1">number
</font></td>
2131 <td><font size=
"-1">Uinteger32
</font></td>
2142 <td><font size=
"-1">snmp.
</font><font size=
"-1">TYPE_UNSIGNED32 (
15)
</font></td>
2153 <td><font size=
"-1">number
</font></td>
2164 <td><font size=
"-1"><br />
2198 <td><font size=
"-1">Integer32
</font></td>
2209 <td><font size=
"-1">snmp.
</font><font size=
"-1">TYPE_INTEGER32 (
16)
</font><font size=
"-1"><font size=
"-1" /></font></td>
2220 <td><font size=
"-1">number
</font></td>
2231 <td><font size=
"-1"><br />
2257 <td><font size=
"-1">Opaque: Float
</font></td>
2260 <td><font size=
"-1">snmp.TYPE_FLOAT (
120)
</font></td>
2263 <td><font size=
"-1">number
</font></td>
2266 <td><font size=
"-1"><br />
2276 <td><font size=
"-1">Opaque: Double
</font></td>
2279 <td><font size=
"-1">snmp.TYPE_DOUBLE (
121)
</font></td>
2282 <td><font size=
"-1">number
</font></td>
2285 <td><font size=
"-1"><br />
2295 <td><font size=
"-1">Opaque: Integer64
</font></td>
2298 <td><font size=
"-1">snmp.TYPE_INTEGER64 (
122)
</font></td>
2301 <td><font size=
"-1">number
</font></td>
2304 <td><font size=
"-1"><br />
2314 <td><font size=
"-1">Opaque: Unsigned64
</font></td>
2317 <td><font size=
"-1">snmp.TYPE_UNSIGNED64 (
123)
</font></td>
2320 <td><font size=
"-1">number
</font></td>
2323 <td><font size=
"-1"><br />
2341 <td colspan=
"4" rowspan=
"1">Special type values
</td>
2374 <td><font size=
"-1">NO SUCH OBJECT
</font></td>
2385 <td><font size=
"-1">snmp.NOSUCHOBJECT
=
128</font></td>
2396 <td><font size=
"-1"><br />
2408 <td><font size=
"-1"><br />
2442 <td><font size=
"-1">NO SUCH INSTANCE
</font></td>
2453 <td><font size=
"-1">snmp.NOSUCHINSTANCE =
129<br />
2475 <td><font size=
"-1"><br />
2487 <td><font size=
"-1"><br />
2521 <td><font size=
"-1">END OF MIB VIEW
</font></td>
2532 <td><font size=
"-1">snmp.ENDOFMIBVIEW
=
130</font></td>
2543 <td><font size=
"-1"><br />
2555 <td><font size=
"-1"><br />
2605 <h3><a name=
"counter64">Counter64
<br />
2607 <p>The
64 bit wide SNMP type COUNTER64 cannot be
2608 handled using native Lua types without loosing precision. LuaSNMP
2609 defines and integrates a user defined type
"counter64" to handle this
2610 situation. This type allows you to create and return
varbinds
2611 containing true
64 bit values.
<br />
2613 <p>COUNTER64 is a userdata from the Lua perspective and a metatable
2614 defining methods for conversions and some arithmetic operations is set
2615 automatically.
<br />
2617 <p>The counter64 data type is managed via a submodule snmp.counter64 which provides the following services:
<br />
2619 <p><span style=
"font-weight: bold;">Creation
</span><br />
2623 <li>Creation of a counter64 instance using
<span style=
"font-weight: bold;">counter64.number(val).
</span>The instance is a value of type
"userdata".
<br />
2624 <span style=
"font-weight: bold;">val
</span>can be
<br />
2627 <li>a Lua number, which is not sufficient to achieve true
64 bit precision
</li>
2628 <li>an expresssion, that has a counter64 data type as result, e.g.
2629 counter64.pow(
2,
64) -
1 delivers the maximum value
2630 18446744073709551615.
</li>
2631 <li>a Lua table providing the fields
<span style=
"font-weight: bold; font-style: italic;">high
</span> and
<span style=
"font-weight: bold; font-style: italic;">low
</span>as
32 bit numbers
<span style=
"font-weight: bold;" /></li>
2634 <span style=
"font-weight: bold;">
2636 <h3><span style=
"font-weight: bold;"><p><span style=
"font-weight: bold;">Conversion Operations
</span><br />
2639 <li><span style=
"font-weight: bold;">Counter64 =
> Lua number
<br />
2640 </span><span style=
"font-style: italic;">n = counter64.tonumber(val) ==
> Lua number type (default: double), e.g.
1.844674407371e+19<br />
2641 </span>only
53 bits are maintained.
<br />
2642 <span style=
"font-weight: bold;" /></li>
2644 <span style=
"font-weight: bold;" />
2646 <li><span style=
"font-weight: bold;">Counter64 =
> decimal string
<br />
2647 </span><span style=
"font-style: italic;">s = counter64.tostring(val) ==
> e.g.
"</span>18446744073709551615" (
64 bit)
<br />
2650 <span style=
"font-weight: bold;" />
2652 <li><span style=
"font-weight: bold;">Counter64 =
> hexadecimal string
<br />
2653 </span><span style=
"font-style: italic;">s = counter64.tohex(val) ==
> e.g.
0xffffffffffffffff (
64 bit)
</span><span style=
"font-weight: bold;"><br />
2656 <span style=
"font-weight: bold;" />
2658 <li><span style=
"font-weight: bold;">Counter64 =
> table
<br />
2659 </span><span style=
"font-style: italic;">t = counter64.totable(val)
==
> {high =
<num32
>, low=
<num32
>}
</span><span style=
"font-weight: bold;"><br />
2662 <span style=
"font-weight: bold;">
2663 <p><span style=
"font-weight: bold;">Arithmetic and boolean Operations
</span><br />
2665 <p>The following arithmetic operations are available. The result is
2666 automatically converted to counter64. Operands can be either counter64
2667 userdata or numbers.
<br />
2670 <ul style=
"font-weight: bold; font-style: italic;">
2671 <li><span style=
"font-weight: bold;">Addition:
</span><br />
2672 <span style=
"font-style: italic;">result = val1 + val2 or counter64.add(val1, val2)
</span></li>
2674 <ul style=
"font-weight: bold; font-style: italic;">
2675 <li><span style=
"font-weight: bold;">Substraction:
</span><br />
2676 <span style=
"font-style: italic;">result = val1 - val2 or counter64.sub(val1, val2)
</span>; the result is always an unsigned
64 bit value
</li>
2678 <ul style=
"font-weight: bold; font-style: italic;">
2679 <li><span style=
"font-weight: bold;">Multiplication:
</span><br />
2680 <span style=
"font-style: italic;">result = val1 * val2 or counter64.mul(val1, val2)
</span></li>
2682 <ul style=
"font-weight: bold; font-style: italic;">
2683 <li><span style=
"font-weight: bold;">Division:
</span><br />
2684 <span style=
"font-style: italic;">result = val1 / val2 or counter64.div(val1, val2)
</span></li>
2686 <ul style=
"font-weight: bold; font-style: italic;">
2687 <li><span style=
"font-weight: bold;">Modulo:
</span><br />
2688 <span style=
"font-style: italic;">result = counter64.mod(val1, val2)
</span></li>
2691 <li><span style=
"font-weight: bold;">Div and Modulo:
</span><br style=
"font-weight: bold; font-style: italic;" />
2692 <span style=
"font-style: italic;">div, mod = counter64.divmod(val1, val2)
</span></li>
2693 </ul><span style=
"font-weight: bold;" />
2695 <li><span style=
"font-weight: bold;">Comparision:
<br />
2696 </span>All standard Lua compare operators
<,
>, ==, ~=,
>=,
<= deliver boolean results.
<span style=
"font-weight: bold;"><br />
2697 </span>Additionally, the function
<br />
2698 <span style=
"font-style: italic;">result = counter64.compare(val1, val2)
</span><br />
2699 delivers numbers:
<span style=
"font-weight: bold;"><br />
2700 </span><span style=
"font-style: italic;">-
</span><span style=
"font-style: italic;">1, if val1
< val2
</span><br style=
"font-style: italic;" />
2701 <span style=
"font-style: italic;"> 0, if val1 == val2
</span><br style=
"font-style: italic;" />
2702 <span style=
"font-style: italic;"> 1, if val1
> val2
</span></li>
2704 <span style=
"font-weight: bold;" />
2706 <li><span style=
"font-weight: bold;">Negation
<br />
2707 </span><span style=
"font-style: italic;">result = - val or
<br />
2708 result = counter64.neg(val)
<br />
2709 </span>NOTE: The resulting bit pattern is correct, but since
2710 Counter64 is an unsigned type, you will never see negative counter64
2711 values.
<span style=
"font-style: italic;"><br />
2714 <span style=
"font-weight: bold;" />
2716 <li><span style=
"font-weight: bold;">Zero Test:
<br />
2717 </span>result = counter64.iszero(val) delivers true if
<span style=
"font-style: italic;">val
</span> is
0.
<span style=
"font-style: italic;"><span style=
"font-weight: bold;"><br />
2722 <h1><a name=
"varbinds">Varbinds
</a></h1>
2734 <h3><a name=
"varbinds_general">General
</a></h3>
2746 <a name=
"varbinds_general">SNMP operations are defined on a list of MIB variable instances called a
<i>varbind list
</i>. Each element of a varbind list - a
<span style=
"font-weight: bold;">varbind element
</span>
2747 - describes a specific MIB variable instance. A varbind element
2748 specifies three MIB instance attributes: its
<span style=
"font-weight: bold;">object identifier
</span>, its
2749 <span style=
"font-weight: bold;">data type
</span> and its
<span style=
"font-weight: bold;">value
</span>.
2751 <p><a name=
"varbinds_general">LuaSNMP represents a
<span style=
"font-weight: bold;">varbind list
</span> as a table containing
<span style=
"font-weight: bold;">varbind elements
</span>
2752 indexed by consecutive numerical values, starting with
1. A varbind
2753 element is represented as a table containing the values of the three
2754 MIB instance attributes. The strings
<b>"oid"</b>,
<b> "type"</b> and
<b>"value" </b>index the three attributes of a varbind table. LuaSNMP represents the values of the varbind attributes as follows:
</a></p>
2767 <p><a name=
"varbinds_general"><b>oid
</b> - a string containing the
<i>object identifier
</i> that identifies the MIB instance.
</a></p>
2779 <p><a name=
"varbinds_general"><b>type
</b> - the numerical code associated by LuaMan to the SNMP data type of the MIB instance, as specified in the table above (
</a><a href=
"#data_types">Data Types
</a>).
</p>
2791 <p><b>value
</b>- the value of the MIB instance, represented as specified in the table above (
<a href=
"#data_types">Data Types
</a>).
</p>
2815 <p>The following example illustrates a LuaSNMP representation of a varbind list:
</p>
2827 <pre>vlist = {
<br /> {oid =
"1.3.6.1.2.1.1.4.0", type = TYPE_DISPLAY, value =
"Lua"},
<br /> {oid =
"1.3.6.1.2.1.1.6.0", type = TYPE_DISPLAY, value =
"Program" }
<br />}
<br /></pre>
2839 <p>When a previously loaded MIB module contains the description of a
2840 given MIB variable, LuaSNMP allows a management application to use this
2841 variable's
<span style=
"font-weight: bold;">MIB label
</span> instead of its object identifier, and also to omit the
<span style=
"font-weight: bold;">type
</span> attribute, as shown in the example below:
</p>
2853 <pre> vb = {oid =
"sysContact.0", value =
"Ana"}
</pre>
2865 <p>A management application can also omit the
<span style=
"font-weight: bold;">value
</span><span style=
"font-weight: bold;"> </span>attribute when specifying varbind tables for retrieving - or
<i style=
"font-weight: bold;">getting
</i><span style=
"font-weight: bold;"> </span>- the values of MIB instances. LuaMan functions, however, will always return fully specified varbind tables.
</p>
2877 <p>It is important to note that varbind tables resulting from SNMPv2 operations can signal exception, or error, conditions (
<i>NO SUCH OBJECT, NO SUCH INSTANCE, END OF MIB VIEW
</i>) in their
<span style=
"font-weight: bold;">type
</span><span style=
"font-weight: bold;">
2878 </span>attribute. LuaSNMP represents these exception conditions with the
2879 numerical codes snmp.NOSUCHOBJECT, snmp.NOSUCHINSTANCE and
2880 snmp.ENDOFMIBVIEW.
</p>
2891 <h3><a name=
"varbind_meta">Varbind Metamethods
</a></h3>
2902 <p><a name=
"varbind_meta">Every varbind element returned by
LuaSNMP has a metatable
2903 assigned. This metatable allows the following special operation on
2904 varbind elements:
</a></p>
2915 <h5><a name=
"varbind_meta">Creation of varbind elements
</a></h5>
2926 <p><a name=
"varbind_meta">A varbind element can be created using the function
<span style=
"font-style: italic;"><span style=
"font-weight: bold;">snmp
</span></span><span style=
"font-weight: bold; font-style: italic;">.newvar(NAME, VALUE).
</span>This function returns a new varbind element as Lua table with approriate metamethods set.
</a></p>
2937 <pre><a name=
"varbind_meta">leuwer@goofy:luasnmp$ lua -l snmp -i
<br />> vb1=snmp.newvar(
"ifSpeed.1",
1000)
<br />> vb2=snmp.newvar(
"sysContact.0",
"atHome")
<br />> vb3=snmp.newvar(
"ifName.2",
"Ethernet")
<br />> vb4=snmp.newvar(
"ifSpeed.2",
2000)
<br /></a></pre>
2948 <h5><a name=
"varbind_meta">Conversion to string:
</a></h5>
2959 <p><a name=
"varbind_meta">When the function tostring(vb) is applied to a varbind element, it
2960 returns a printable string representation of the varbind element.
</a></p>
2971 <pre><a name=
"varbind_meta">> print(tostring(vb1))
<br />IF-MIB::ifSpeed
.1 = Gauge32:
1000<br />> print(vb2)
<br />SNMPv2-MIB::sysContact
.0 = STRING: atHome
<br />> print(vb3)
<br />IF-MIB::ifName
.2 = STRING: Ethernet
<br />> print(tostring(vb4))
<br />IF-MIB::ifSpeed
.2 = Gauge32:
2000<br /></a></pre>
2982 <h5><a name=
"varbind_meta">Comparision of varbind elements
</a></h5>
2993 <p><a name=
"varbind_meta">A compare operation on varbind elements compares their values. Note
2994 that the comparison is performed on equivalent Lua type (see Data Types
2995 above). Comparing varbind elements with values of different Lua types
2996 leads to an error.
</a></p>
3007 <pre><a name=
"varbind_meta">> =vb1
<vb4
<br />true
<br />> =vb1
<=vb4
<br />true
<br />> =vb1
>vb4
<br />false
<br />> =vb2
<vb3
<br />false
<br />> =vb2
>vb3
<br />true
<br />> =vb1
< vb2
<br />./snmp.lua:
316: attempt to compare number with string
<br />stack traceback:
<br /> ./snmp.lua:
316: in function
<./snmp.lua:
316><br /> stdin:
1: in main chunk
<br /> [C]: ?
</a></pre>
3018 <h5><a name=
"varbind_meta">Concatenation of varbind elements
</a></h5>
3029 <p><a name=
"varbind_meta">Applying the concatenation operator on varbind elements creates a
3030 varbind list. Any number of varbinds can be concatenated. Concatenation
3031 a varbind element and a varbind list creates a new varbind list which
3032 contains the varbind element and all elements of the varbind list.
</a></p>
3043 <pre><a name=
"varbind_meta">> vlist = vb1..vb2..vb3
<br />> table.foreach(vlist, print)
<br />1 IF-MIB::ifSpeed
.1 = Gauge32:
1000<br />2 SNMPv2-MIB::sysContact
.0 = STRING: atHome
<br />3 IF-MIB::ifName
.2 = STRING: Ethernet
<br />><br /></a></pre>
3054 <a name=
"varbind_meta">om
<br />
3065 </a><h1><a name=
"sessions">SNMP Sessions
</a></h1>
3076 <p><a name=
"sessions">Similarly to other SNMP APIs, LuaSNMP implements the concept of SNMP
3077 sessions. Before invoking SNMP operations on an SNMP peer, a management
3078 application must create, or open, an SNMP session. An SNMP session is a
3079 special object that stores the configuration parameters that control
3080 the protocol interactions with an SNMP peer. These configuration
3081 parameters include the IP address of the SNMP peer, the protocol
3082 version to be used and authentication information. All invocations of
3083 SNMP operations must specify an SNMP session.
</a></p>
3094 <p><a name=
"sessions">When creating an SNMP session, an application can also define
3095 default callback functions for receiving responses to asynchronous SNMP
3096 operations and for handling notifications (trap and inform messages)
3097 sent by the associated peer.
</a></p>
3108 <p><a name=
"sessions">The configuration parameters stored in a LuaSNMP
session are described below.
</a></p>
3119 <h5><a name=
"sessions">peer = STRING
</a></h5>
3131 <p><a name=
"sessions">Defines the network (IP) address of the associated SNMP peer, and
3132 can be provided either as an IP address in dotted notation (e.g.
3133 "139.82.95.11") or as a host name that can be translated to an IP
3144 <a name=
"sessions">The default value for this parameter is
"0.0.0.0", and indicates an
3145 SNMP session that is not associated to a specific peer. This kind of
3146 "unassociated" SNMP sessions can be used for receiving all
3147 notifications (traps and informs) sent by the SNMP agents and managers
3148 on the network (see configuration parameters trap and inform). Note,
3149 however, that SNMP operations can only be invoked for SNMP sessions
3150 associated to specific peers.
</a></p>
3161 <h5><a name=
"sessions">version = NUMBER
</a></h5>
3167 <p><a name=
"sessions">Defines the SNMP protocol version to be used when interacting with
3168 the SNMP peer associated to the session. LuaSNMP supports
3169 SNMPv1,
SNMPv2C and SNMPv3. A
<span style=
"font-weight: bold;">default value
</span>can be defined with the
<span style=
"font-weight: bold;">defCommunity
</span> configuration directive in snmp.conf. The
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> for this parameter
3170 is
<span style=
"font-weight: bold;">snmp.SNMPv2C
</span>. LuaSNMP provides the following constants to define the session's version:
</a></p>
3199 <a name=
"sessions"> </a><li><span style=
"font-weight: bold;"><a name=
"sessions">snmp.SNMPv1 =
1</a></span></li>
3205 <a name=
"sessions"> </a><li><span style=
"font-weight: bold;"><span style=
"font-weight: bold;"><a name=
"sessions">snmp.SNMPv2C = snmp.SNMPv2c =
2</a></span></span></li>
3211 <a name=
"sessions"> </a><li><span style=
"font-weight: bold;"><a name=
"sessions">snmp.SNMPv3 =
3</a></span></li>
3228 <h5><a name=
"sessions">community = STRING
</a></h5>
3239 <p><a name=
"sessions">Defines the community string to be used for authenticating the SNMP
3240 messages sent to the associated peer. A
<span style=
"font-weight: bold;">default value
</span>can be defined with the
<span style=
"font-weight: bold;">defVersion
</span> configuration directive in snmp.conf. The
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> for this
3241 parameter is
<span style=
"font-weight: bold;">"public"</span>. The community is only used for SNMPv1 and SNMPv2C
</a></p>
3252 <h5><a name=
"sessions">port = NUMBER
</a></h5>
3263 <p><a name=
"sessions">Defines the UDP port used by the associated peer for receiving SNMP requests. A default value can be defined via the
<span style=
"font-weight: bold;">defaultPort
</span> configuration directive in
<span style=
"font-weight: bold;">snmp.conf
</span>. See the Net-SNMP manual page snmp.conf (
5) for details.
The
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> for this parameter is
<span style=
"font-weight: bold;">161</span>.
</a></p>
3274 <h5><a name=
"sessions">retries = NUMBER
</a></h5>
3285 <p><a name=
"sessions">Defines the maximum number of retransmissions of an SNMP message. The
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> is
<span style=
"font-weight: bold;">5.
</span></a></p>
3296 <h5><a name=
"sessions">timeout = NUMBER
</a></h5>
3307 <p><a name=
"sessions">Defines the time (in seconds) to wait for a response to an SNMP
3308 request. In order to avoid congestion problems, every retransmission of
3309 a given SNMP request will double the previous timeout value.
The
3310 <span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> for this parameter is
<span style=
"font-weight: bold;"> 1.
</span></a></p>
3321 <h5><a name=
"sessions">callback =FUNCTION
</a></h5>
3334 <p><a name=
"sessions">This parameter defines a default user function to be invoked when a
3335 response to an asynchronous SNMP operation is received, or when an
3336 asynchronous request times out.
<br />
3346 Note, however, that an application can define a specific function
3347 for processing the response to a given asynchronous request. In this
3348 case, this specific function overrides the default callback function
3349 configured for the session.
<br />
3359 The
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> for this parameter is
<span style=
"font-weight: bold;">nil
</span>, indicating that no
3360 default function for handling asynchronous responses is defined for the
3372 <h5><a name=
"sessions">trap = FUNCTION
</a></h5>
3384 <p><a name=
"sessions">This parameter defines a user function to be invoked when a trap
3385 message is received. Note that when a trap message is received, LuaSNMP
3386 invokes the trap handling functions specified for all SNMP sessions
3387 associated to the originating agent, and also the trap handling
3388 functions specified for
"unassociated" sessions (peer =
"0.0.0.0").
<br />
3398 The
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> for this parameter is
<span style=
"font-weight: bold;">nil
</span>, indicating that no trap handling function is defined for the session.
</a></p>
3408 <p><a name=
"sessions">Note, that the trap callback function is also invoked for solicited traps = informs.
<br />
3418 See Trap Handling for more details on trap handling in LuaSNMP.
</a></p>
3428 <h5><a name=
"sessions">user = STRING
</a></h5>
3438 <p><a name=
"sessions">This parameter defines the user name to be used during SNMP version
3 USM based
authentication. A
<span style=
"font-weight: bold;">default
</span> <span style=
"font-weight: bold;">value
</span> can be specified using the
<span style=
"font-weight: bold;">defSecurityName
</span>configuration directive in snmp.conf. See the Net-SNMP manual page snmp.conf (
5) for details.
</a></p>
3448 <h5><a name=
"sessions">password = STRING
<br />
3458 autPassphrase = STRING
</a></h5>
3468 <p><a name=
"sessions">This parameter defines the
pass phrase to be used during SNMP
3469 version
3 USM based authentication. A default value can be specified
3470 using the
<span style=
"font-weight: bold;">defAuthPassphrase
</span> or
<span style=
"font-weight: bold;">defPassphrase
</span> configuration directives in
<span style=
"font-weight: bold;">snmp.conf
</span>. See the Net-SNMP manual page snmp.conf (
5) for details.
</a></p>
3480 <p><a name=
"sessions">Note, that password is used as the pass phrase for both
3481 authentication and encryption if no dedicated pass phrase is specified
3482 for encryption.
</a></p>
3492 <h5><a name=
"sessions">authType = STRING
</a></h5>
3502 <p><a name=
"sessions">This parameter defines the
<span style=
"font-weight: bold;">authentication method
</span> to be used for SNMP version
3 authentication. Possible values are
<span style=
"font-weight: bold;">"MD5"</span> or
<span style=
"font-weight: bold;">"SHA"</span>. A default value can be specified using the
<span style=
"font-weight: bold;">defAuthType
</span> configuration directive in
<span style=
"font-weight: bold;">snmp.conf
</span>. If no authentication method is defined LuaSNMP assumes
<span style=
"font-weight: bold;">"MD5"</span> as
<span style=
"font-weight: bold;">default value.
</span></a></p>
3512 <h5><a name=
"sessions">privType = STRING
</a></h5>
3522 <p><a name=
"sessions">This parameter defines the
<span style=
"font-weight: bold;">encryption method
</span> to be used for SNMP version
3 PDU encryption. Possible values are
<span style=
"font-weight: bold;">"DES"</span> or
<span style=
"font-weight: bold;">"AES"</span>. A default value can be specified using the
<span style=
"font-weight: bold;">defPrivType
</span><span style=
"font-weight: bold;"> </span>in
<span style=
"font-weight: bold;"> snmp.conf
</span>. If no authentication method is defined LuaSNMP assumes
<span style=
"font-weight: bold;">"DES"</span><span style=
"font-weight: bold;"> </span>as
<span style=
"font-weight: bold;">default value.
</span></a></p>
3532 <h5><a name=
"sessions">privPassphrase = STRING
</a></h5>
3542 <p><a name=
"sessions">This parameter defines the
pass phrase to be used during SNMP version
3543 3 PDU encryption.
A default value can be specified using the
3544 <span style=
"font-weight: bold;">defPrivPassphrase
</span> or
<span style=
"font-weight: bold;">defPassphrase
</span> configuration directives in
3545 <span style=
"font-weight: bold;">snmp.conf
</span>. See the Net-SNMP manual page snmp.conf (
5) for details.
</a></p>
3555 <p><a name=
"sessions">Note, that
<span style=
"font-weight: bold;">password
</span> is used as the pass phrase for both authentication
3556 and encryption if no dedicated pass phrase is specified for encryption.
</a></p>
3566 <h5><a name=
"sessions">securityLevel = STRING
</a></h5>
3576 <p><a name=
"sessions">Defines the security level to be used in SNMP version
3. The parameter can take the following values:
</a></p>
3586 <p style=
"margin-left: 40px;"><span style=
"font-weight: bold;"><a name=
"sessions">"noAuthNoPriv"</a></span><a name=
"sessions"> <span style=
"font-weight: bold;">-
</span> LuaSNMP does not require authentication nor does it perform encryption
</a></p>
3596 <p style=
"margin-left: 40px;"><span style=
"font-weight: bold;"><a name=
"sessions">"authNoPriv" -
</a></span><a name=
"sessions">LuaSNMP requires authentication but does NOT perform encryption.
<br />
3616 <div style=
"margin-left: 40px;"><span style=
"font-weight: bold;"><a name=
"sessions">"authPriv" -
</a></span><a name=
"sessions">LuaSNMP requires authentication AND performs encryption
</a></div>
3626 <p><a name=
"sessions">A
<span style=
"font-weight: bold;">default value
</span> can be defined using the
<span style=
"font-weight: bold;">defSecurityLevel
</span> configuration directive in snmp.conf. See the Net-SNMP manual page snmp.conf (
5) for details.
<br />
3636 If no security level is defined during session creation and there is no configuration available via snmp.conf, LuaSNMP defines
<span style=
"font-weight: bold;">"authNoPriv"</span> as default value.
<br />
3656 <h5><a name=
"sessions">includeroot = BOOLEAN
</a></h5>
3666 <p><a name=
"sessions">This parameter defines whether the SNMP access function
<span style=
"font-weight: bold; font-style: italic;">walk(NODE)
</span>shall include the given NODE. Normally, the walk starts with the successor of the given NODE. The default value is
<span style=
"font-weight: bold;">false
</span>.
</a></p>
3676 <h5><a name=
"sessions">sprintvar = FUNCTION
</a></h5>
3686 <p><a name=
"sessions">This parameter instructs LuaSNMP to use the given FUNCTION to convert varbind elements to readable strings.
</a></p>
3696 <h5><a name=
"sessions">sprintval = FUNCTION
</a></h5>
3706 <p><a name=
"sessions">This parameter instructs LuaSNMP to use the given FUNCTION to convert varbind values to readable strings.
</a></p>
3716 <h5><a name=
"sessions">context = STRING
</a></h5>
3726 <p><a name=
"sessions">This parameter defines the context to which this session shall have access.
<span style=
"font-weight: bold;">Defaults
</span> to an empty context
<span style=
"font-weight: bold;">""</span>.
</a></p>
3736 <h5><a name=
"sessions">contextID = STRING
</a></h5>
3746 <p><a name=
"sessions">This parameter sets the context engineID used for SNMPv3 REQUEST
3747 messages scopedPdu.
If not specified, this will default to
3748 the authoritative
<span style=
"font-weight: bold;">engineID.
</span></a></p>
3758 <h5><a name=
"sessions">engineID = STRING
</a></h5>
3768 <p><a name=
"sessions">This parameter sets
the
authoritative
3769 (security)
engineID
used
for
SNMPv3
3770 REQUEST
messages.
It
is
typically
3771 not necessary to specify this, as it will usually be discovered
3772 automatically.
</a></p>
3782 <h5><a name=
"sessions">engineBoots = STRING
</a></h5>
3792 <p><a name=
"sessions">This parameter is not (yet) supported. It's typically not required because this value is automatically discovered.
</a></p>
3802 <h5><a name=
"sessions">engineTime = STRING
</a></h5>
3812 <p><a name=
"sessions">This parameter is not (yet) supported. It's typically not required because this value is automatically discovered.
</a></p>
3823 <h1><a name=
"trap_handling">Trap Handling
</a></h1>
3831 <p><a name=
"trap_handling">LuaSNMP handles traps via the
<span style=
"font-weight: bold;">snmptrapd
</span> from the NetSNMP library using the
<span style=
"font-weight: bold;">traphandle
</span> directive in
<span style=
"font-weight: bold;">snmptrapd.conf(
5)
</span>.
</a></p>
3839 <p><a name=
"trap_handling">In order to capture traps in this way
you have to configure the
3840 script trapd.lua provided with LuaSNMP to handle
traps via the
<span style=
"font-weight: bold;">traphandle
</span> directive. Insert the following line into snmptrapd.conf:
</a></p>
3847 <pre><a name=
"trap_handling">traphandle default PATH_TO_LUA/lua50 PATH_TO_TRAPD/trapd.lua [FWDPORT]
</a></pre>
3854 <p><a name=
"trap_handling">The script trapd.lua simply forwards all information received by snmptrapd to LuaSNMP using a UDP socket with localhost on
<span style=
"font-weight: bold;">port
6000</span>. In order to change the port, set the environment variable
<span style=
"font-weight: bold;">LUASNMP_TRAPDPORT
</span>to the desired port number and provide the same number in the traphandle directive in
<span style=
"font-weight: bold;">snmptrapd.conf
</span>.
</a></p>
3861 <p><a name=
"trap_handling">Note, that for informs the response to the inform message is sent AFTER trapd.lua has finished.
</a></p>
3895 <div style=
"font-weight: normal;" id=
"footer"><small>(c)
2006-
2010 Herbert Leuwer, March
2006 <a href=
"mailto:herbert.leuwer@t-online.de">Contact
</a></small></div>