DX Unified Infrastructure Management

 View Only
  • 1.  Get all active alarms using Lua

    Posted Mar 24, 2016 10:02 AM

    I know the get_alarms utility only returns the first 500 records. Does anyone have the code for Lua to grab them all?


    I found this topic that does it in perl and .net:  getting all alarms from NAS


    I think the issue is that I'm not creating a session but haven't done that before.

  • 2.  Re: Get all active alarms using Lua
    Best Answer

    Posted Mar 29, 2016 11:17 AM

    Yes, this works in Lua like it does in the other languages. You do need a session to collect all of the alarms over the 500 limit. You start by creating a session with the nimbus.session_open() function. After that you use the nimbus.session_request() function instead of the nimbus.request() function, and you keep calling it as long as the return code is NIME_OK (0). Once you get back NIME_NOENT (4), then you're done. You can call the nimbus.session_close() function to close the session when done.

  • 3.  Re: Get all active alarms using Lua

    Posted Mar 29, 2016 04:20 PM

    Thank you Keith! That worked perfectly. Here is the code I'm using to do this in case anyone else needs it:




    -- This function is used to easily view the table structure found in Nimsoft

    -- usage would be:  tdump(robot)


    function tdump(t)

      local function dmp(t, l, k)

      if type(t) == "table" then

      print(string.format("%s%s:", string.rep(" ", l*2), tostring(k)))

      for k, v in pairs(t) do

      dmp(v, l+1, k)



      print(string.format("%s%s:%s", string.rep(" ", l*2), tostring(k), tostring(t)))



      dmp(t, 1, "root")


    --end tdump(pTable)-----------------------------------------------------------------------------------




    nsa_dir="E:\\Program Files (x86)\\Nimsoft\\sdk\\nsa\\"



    require (nsa_dir.."library\\uim_env_vars")

    --above 'require' provides uimDomain, uimHub, uimServer, uimUser, uimPW, uimInstallLoc variables.



    -- Log in to NimBUS. This is mandatory for most of the processes ran in this script.

    nimbusLoginResult,nimbusLoginSID = nimbus.login(uimUser,uimPW)



    pSessionHandle = nimbus.session_open("/"..uimDomain.."/"..uimHub.."/"..uimServer.."/nas")



    args = pds.create()

    pds.putInt(args, "show_all", 1)



    local alarm_list_full = {}

    local cycles          = 0



    while true do

        local alarm_list_partial,rc = nimbus.session_request(pSessionHandle, "get_alarms", args)

        print("return code = "..rc)



        if rc == NIME_OK then

            for k,v in pairs(alarm_list_partial.alarms) do

                table.insert(alarm_list_full, v)


        elseif rc == NIME_NOENT then

            print("All done in "..cycles.." requests")



            print("ERROR: Got rc = "..rc..", ending loop")





        cycles = cycles + 1

        if cycles > 100 then

            print("Too many cycles or A LOT of alarms, ending loop")






    nimbus.session_close (pSessionHandle)



    print("Total alarm count = "..#alarm_list_full)