LUALoriotPro WEB site

LoriotPro scripting documentation
Extensions for LUA language

Table of contents Search function

Print the current page Mail this  link UTUBE Channel version française

Creating a virtual snmp object

We know that using  a virtual snmp object perform a call to a LUA script. Calling a script with arguments is possible and allows you to initialize parameters (or arguments) that the script can use ( a host IP address for example or a snmp index.

When the script ends, it can return 2 variables that LoriotPro can use to display the results.

Table of parameter that can be passed to a script

Parameter

Description

 lp_host

The IP address of a host in a character string format

 lp_oid

The name of the virtual snmp object in a character string format

 lp_index

A snmp object index in a character string format starting with a dot (example: ".2")

Table of parameters that can return from a script

Parameter

Description

 lp_value

A value as a double (64 bits)  when it is an integer

 lp_buffer

A character string

Example:

Let us see what it looks like if we want to use a virtual snmp object to get the available disk space use in percent of our logical C drive.

The file your-script.mib contains the definition of the virtual snmp object lp_your_diskused that refers to a script . The script performs the required snmp queries and calculation.

The virtual snmp object with an embedded script:

YOUR-SCRIPT-MIB DEFINITIONS ::= BEGIN

IMPORTS
    luteus           FROM LUTEUS-TC-MIB;
    scripts          FROM LUTEUS-TC-MIB;
your_script     OBJECT IDENTIFIER ::= { scripts 1000 }

lp_your_diskused OBJECT-TYPE    
    SYNTAX      Integer32
    ACCESS      lp_access_script
    STATUS      current
    DESCRIPTION    "Perform the calculation of lp_value = (lp.Get(lp_host,'hrstorageused.index') / lp.Get(lp_host,'hrstoragesize.index'))*100; "

<LP_SCRIPT>
     lp_buffer
="BAD"
     get1=("hrstorageused"..lp_index); --concatenation
     get2=("hrstoragesize"..lp_index); --concatenation
     lp_value = (lp.Get(lp_host,get1)/(lp.Get(lp_host,get2)+0.001))*100;
     lp_buffer ="OK"
<LP_SCRIPT>

    ::= { your_script  1 }
END

Writing rules:

We use the enterprises.luteus father oid to attach our proprietary MIB file. The enterprises.luteus.scripts oid (oid 1000) is the father object under which we declare the snmp virtual object.

OID number that you create must start at 1000 (1 to 999 is reserved to Luteus). To avoid conflict between oid numbers you can request us a range of values.

If you want to provide your own script with your company MIB files, attach the snmp virtual objects to your own company object OID.

The object name is limited to 20 characters

As in the upper example the script can be embedded in the virtaul snmp object. The script can also be define in an external file.

The script should be define between the tag <LP_SCRIPT>. If you don't use the embedded mode this tags are no required.
During the MIB compilation phase a LUA script file "lp_your_diskused.lua" in our example will be created in the directory bin/config/script. You can create and copy the LUA script file in the directory bin/config/script

Once the MIB file is compiled it is still possible to modify the LUA script

WARNING : if you do a new compilation you change will be lost

-- lp_host and lp_index is passed to the script by LoriotPro calling program or plugin
-- lp_iod is not used in the lp_your_diskused.lua script
-- lp_value is returned  by the script

Before creating an new snmp virtual object with a new script it is good to debelopp it and test it. The script can be preliminary tested from the SDE (Script Development Environment. Refer to the script editor chapter. Her under the script that we will attach to our lp_your_diskused snmp virtual object.

press the F5 key to run the script

When the script is fully tested you can edit the your-script.mib  file in the bin/mibs directory and run the MIB compiler.

When compilation is done we can check that our snmp virtual object is in our MIB tree.

The LUA script file « lp_your_diskused.lua » is in the  bin/config/script directory

We can open the file to see the script with a simple text editor

The lp_your_diskused object can be used as any other snmp object within all programs and plugin of LoriotPro

But be carefull this object has an index (the index define on which storage device or disk in your system you want to execute the script.

A simple test consist of using the snmp requester

In this example the snmp virtual object return the curretn disk utilization in percent. We get  94,02 % of utilization hereon our  logical C drive.

The script can be used from our linear graph program.

 

By changing the index number it is easy to get the control over  other disk.

Example from the  VuMeter  plugin.

Example with th e « Bulk Threshold Control » plugin.

Behind this concept of snmp virtual object, the kernel of LoriotPro performs real SNMP get on the host in synchronous mode. Of course the request get a return value at null from the host because this virtual snmp object is not defined in the host snmp agent. The object declaration ( lp_access_script) is recognized by LoriotPro and the return value is replaced by the result values coming from the script. But the script itself,  like in our example, can perform many snmp requests on real snmp objects.

Snmp virtual object can be used in Active View too.

 


www.loriotpro.com