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

lp.GetFastNextDirectoryUID

LoriotPro has extended the LUA sripting language by providing its own LUA libraries. The new functions provided are dedicated to the creation of monitoring and SNMP automation application.

Syntax

‘uid’,level,dt = lp.GetFastNextDirectoryUID('uid','array');

Description

The lp.GetFastNextDirectoryUID LUA function retrieve the next UID of an item of the directory tree. This is very useful to browse the tree for finding information about an object.

Parameters

‘uid’               A UID, a unique number representing an unsigned 64 bits but stored as a character string.

Return Values

‘uid’               A UID, a unique number representing an unsigned 64 bits but stored as a character string.

level             The level of the next object in the tree

                                                              If = 0 next

                                                              If = 1 one level down (enter a branch)

                                                              If = -1 one level up (leave a branch)

                                                             If  = -x x level up (leave x branches)

'array' A LUA table with some properties of the Directory object below

UID The UID ( unique identifier) of the object
name The name of the directory object
object_type

A number that defines the type of object:

COUNTRY=1;
ORGANIZATION =2;
ORGANIZATION_UNIT=3;
NETWORK=4;
FACTORY=5;
HOST=6;
HOST_FUNCTION=7;
HOST_ALIAS=8;
HOST_EXECLINK=9;
HOST_MRTG=10;
HOST_PLUGIN=11;
HOST_ADVPOLLING=12;

string The object parameter in a character string format
ip The object ip address when applicable
plugin_name The object name when it is a plugin
UID_father The UID ( unique identifier) of the father object
UID_same  
UID_child The UID ( unique identifier) of the next child object
child The number of child objects for this father object
status The current status of the Object:
UID_alias The UID ( unique identifier) of the next alias object
alias The number of alias objects for this father object
lock_http  
access_level  

 

'dt' a pointer

Return nil if an error occurs

Example

 

deb=true -- true/false : turn on/off the verbose mode for debuging

---------------------------------------------------------------
function tab(fois)
str=""
for i=0,math.abs(fois) do str = str.."\t" end
return(str)
end
---------------------------------------------------------------
function GetDirItemType(DirItem)
--ParamType
--[[
LP_LUA_DT_COUNTRY=1;
LP_LUA_DT_ORGANIZATION =2;
LP_LUA_DT_ORGANIZATION_UNIT=3;
LP_LUA_DT_NETWORK=4;
LP_LUA_DT_FACTORY=5;
LP_LUA_DT_HOST=6;
LP_LUA_DT_HOST_FUNCTION=7;
LP_LUA_DT_HOST_ALIAS=8;
LP_LUA_DT_HOST_EXECLINK=9;
LP_LUA_DT_HOST_MRTG=10;
LP_LUA_DT_HOST_PLUGIN=11;
LP_LUA_DT_HOST_ADVPOLLING=12;]]
dit = DirItem.object_type
if dit == 1 or dit == 2 or dit ==3 then return "CONTAINER"
elseif dit == 4 then return "NETWORK"
elseif dit == 6 then return "HOST"
else return "OTHER"
end
end
---------------------------------------------------------------
--MAIN
--Browse the tree
--
levelmove=0;--the move from one level to another in the tree: 1 = Going down one level, -1 is going up one level
level=0;-- the current level in the tree
OpenItems={}-- a table with a list of last opened items type per level {"CONTAINER","CONTAINER","HOST"...

lp.Trace("Opening ROOT\n")
uid,dt=lp.GetFirstDirectoryUID('DirItem')
if uid then
while (uid ~= nil) do --Browse the tree
level = level - levelmove --current level position in the tree 0 = root

------Manage the opening of one branch or one object
OpenItemsIdx=math.abs(level)+1
table.insert(OpenItems,OpenItemsIdx,GetDirItemType(DirItem))
if deb then
--if deb then lp.Trace(tab(level).."Add to Idx "..OpenItemsIdx.." "..GetDirItemType(DirItem).."\n")end
--if deb then lp.Trace(tab(level)..levelmove.." "..level)--.."\t"..uid) end
lp.Trace(tab(level).."Opening "..GetDirItemType(DirItem).."\n")
--Show(DirItem)
end


--Getting next object in the tree
uid,levelmove,dt=lp.GetFastNextDirectoryUID(dt,'DirItem')

------Manage the closing of the opened branches (CONTAINER) or objects (HOST,PLUGIN)
if levelmove == nil then --case end of the tree, no child
for i=table.getn(OpenItems),1,-1 do
if deb then lp.Trace(tab(i-1).."i="..i.." Closing: "..OpenItems[i].."\n") end

end
break
end

for i=0,levelmove,-1 do -- There is a child
Idx=OpenItemsIdx+i -- the index of the current type of object to close
if deb then lp.Trace(tab(Idx-1).."i="..i.." Idx="..Idx.." Closing: "..OpenItems[Idx].."\n") end
table.remove(OpenItems,Idx)
end
end
end
lp.Trace("Closing ROOT\n")

 


www.loriotpro.com