amit_saxena

LUA script to fetch information about processes running on a host using rsp probe !

Discussion created by amit_saxena on Apr 14, 2011

Hi all,

 

I just wrote a sample LUA program to fetch information about processes running on a host using rsp probe. The LUA program is copied in this post.

 

I have following queries regarding the LUA program.

 

1. How to check for what reason the call to nimbus.request failed ? I am looking for following scenarios.

 

    a) the call back function does not exists.

    b) wrong or unsupported value is provided for the key in PDS

    c) not all key-value pairs are provided in the PDS

 

At present, I am only printing "no data" in case the call to nimbus.request function fails.

 

2. The inbuilt LUA editor in nas does not offer complete functionality of an editor. Is there any free editor available with embedded LUA documentation for reference (if possible) ? At present, I am coding in GVIM in windows with online LUA help from http://www.lua.org opened.

 

3. Is there any operator like "x" in perl available in LUA also ? The way I am concatenating the string, while taking care of spaces for proper indentation, is tedious and error prone.

 

4. Finally, the review comments regarding the LUA script. I am very sure that it can be redesigned for improved efficiency.

 

Please suggest.

 

 

--printf ("Process PID\tProcess Name\tProcess PPID\tProcess cmdline\tHostname") local header_string local delim local i1 local process_info_text  -- Creating the header string --  header_string = "Process PID"  delim = "" for i1 = 1,20 - #header_string do    delim = delim .. " " end header_string = header_string .. delim .. "Process Name"  delim = "" for i1 = 1,40 - #header_string do    delim = delim .. " " end header_string = header_string .. delim  .. "Process PPID"  delim = "" for i1 = 1,60 - #header_string do    delim = delim .. " " end header_string = header_string .. delim  .. "Process Command line"  delim = "" for i1 = 1,170 - #header_string do    delim = delim .. " " end header_string = header_string .. delim  .. "Hostname"  printf ( "%s",header_string)  -- Creating the pds handle  mypds = pds.create () pds.putString ( mypds, "hostname", "10.10.10.10" )  -- Invoking callback function get_processes for rsp probe  output1,return_status1 = nimbus.request ( "/TESTDomain/TESTHubPrimary/winxp-02/rsp", "get_processes", mypds ) if return_status1 == NIME_OK then    for key1,value1 in pairs (output1["table"]) do       process_info_text = ""       for key2,value2 in pairs (value1) do           if key2 == "hostname" then             delim = ""             for i1 = 1,170 - #process_info_text do                delim = delim .. " "             end             process_info_text = process_info_text .. delim .. value2          end           if key2 == "process_name" then             delim = ""             for i1 = 1,20 - #process_info_text do                delim = delim .. " "             end             process_info_text = process_info_text .. delim .. value2          end           if key2 == "process_pid" then             process_info_text = process_info_text .. value2          end           if key2 == "process_ppid" then             delim = ""             for i1 = 1,40 - #process_info_text do                delim = delim .. " "             end             process_info_text = process_info_text .. delim .. value2          end           if key2 == "process_cmdline" then             delim = ""             for i1 = 1,60 - #process_info_text do                delim = delim .. " "             end             process_info_text = process_info_text .. delim .. value2          end       end        printf ("%s",process_info_text)     end else    printf ("No Data") end  pds.delete (mypds) 

 

 

 

 

Thanks & Regards,

Amit Saxena

Outcomes