Running LuaSNMP

 LuaSNMP scripts

LuaSNMP scripts are standard Lua scripts and may utilise all the features provided by Lua and it's companion libraries. You start a LuaSNMP script simply from the command line:

$ lua SCRIPTFILE

However, in order to make use of LuaSNMP it must be loaded into the Lua universe. This can be done by using Lua's -l commandline option:

$ lua -l snmp -l OTHER SCRIPTFILE

This line starts the Lua interpreter and loads LuaSNMP and other modules specified via the -l command line option before the user script SCRIPTFILE is loaded and executed.

The has now access to all the LuaSNMP definitions via the global table snmp and snmp.mib.

You can also specify lua as the interpreter to use inside the Lua script, which then allows you to directly execute the script.

#!/usr/bin/env lua
...

Note, that this line is NOT standard Lua code and must only appear in the first line of your script.

Loading "snmp"

A more flexible way is to load the  LuaSNMP library from within your Lua script:

...
-- Load the LuaSNMP module
require "snmp"
...

This loads all definitions provided by LuaSNMP into the new global namespace snmp. MIB access functions are accessible via the submodule snmp.mib.

Since the namespaces are accessed frequently, it is recommended to access LuaSNMP definitions using a local reference to the namespaces. It also allows you to rename the namespace.

-- Load the LuaSNMP module 
local snmp = require "snmp"

-- Get simple access to MIB access functions
local mib = snmp.mib

In the case the user defined Lua code is distributed among different scipt files, it is always possible to set such local references:

-- Since snmp is a symbol in the global Lua namespace the following
code is always valid:
local snmp, mib = snmp, snmp.mib
Configuration Files

LuaSNMP honors Net-SNMP snmp.conf configuration files in two ways: