DX Infrastructure Manager

Expand all | Collapse all

test via LUA Script if alarm has a note attached to it

  • 1.  test via LUA Script if alarm has a note attached to it

    Posted 04-19-2011 02:17 AM

    Is it possible (and if so, how?) to test an alarm via AO rule / LUA Script to see if the alarm has a note attached to it?

    I found a mention of a note_list in the nas.pdf, but not sure what to do with it.  Any help would be appreciated.



  • 2.  Re: test via LUA Script if alarm has a note attached to it

    Posted 04-19-2011 09:03 AM

    From what I see, it does not look like this is supported natively in the NAS Lua extensions. I think you are stuck using the note_list callback. You could probably do something like this:

     

    local al = alarm.get()

    local args = pds.create()

    pds.putString(args, "nimid", al.nimid)

    resp,rc = nimbus.request("nas", "note_list", args)

    pds.delete(args)

     

    if rc == NIME_OK then

       -- Process the 'resp' variable here...not sure how

    else

       print("Received error "..rc)

    end


    The trick is looking at the response from the note_list callback and figuring out how to interpret it.



  • 3.  Re: test via LUA Script if alarm has a note attached to it

    Posted 04-19-2011 10:42 AM

    Hi,

     

    I am no lua or nas expert, but it appear that the notes property on alarms is set to 0 if it has no notes and 1 if it has a note attached to it.

     

    But there appears to be no easy way to grab which note it is attached to.

     

    Here is an example demonstrating what I mean with the notes property on an alarm.

     

     

    al=alarm.list()
    if al ~= nil then
       for i=1,#al do
          sNote = "No"
          -- Print nimid, hostname, severity, message and note
          if al[i].notes == 1 then
             sNote = "yes"
          end
          printf("%02d %s %s %s %s Note: %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message, sNote)
       end
    end
    
    printf "select alarms with notes"
    al=alarm.list("notes","1")
    if al ~= nil then
       for i=1,#al do
          -- Print nimid, hostname, severity, message and note
          printf("%02d %s %s %s %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message)
       end
    end

    output might be something like

     

     

    ----------- Executing script at 19.04.2011 09:30:24 ----------
    
      01 FA11050196-91595 w7geha information Testmessage2 Note: yes
      02 FA11050196-91594 w7geha information Testmessage 1 Note: No
      select alarms with notes
      01 FA11050196-91595 w7geha information Testmessage2

     

    Here I have attached a note to test message 2.

     

     

    Here is another example I cooked up. There may be better ways to do this. It assumes you have nis bridge turned on in NAS.

     

     

     

    sQueryFormat = "SELECT" ..
    "     n.* " ..
    "FROM" ..
    "     NAS_NOTES n " ..
    "INNER JOIN " ..
    "     NAS_ALARM_NOTE an ON an.note_id = n.note_id " ..
    "INNER JOIN " ..
    "     NAS_ALARMS a ON a.nimid = an.nimid " ..
    "WHERE " ..
    "     a.nimid = '$NIMID$' " 
    
    sData_engine = "provider=nis;database=none;driver=/***/***/***/data_engine;"
    
    database.open(sData_engine)
    
    printf "select alarms with notes"
    al=alarm.list("notes","1")
    if al ~= nil then
       for i=1,#al do
          -- Print nimid, hostname, severity, message and note
          printf("Alarm: %02d %s %s %s %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message)
          sQuery = string.gsub(sQueryFormat,"'$NIMID$'","'" .. al[i].nimid .. "'")
          -- printf(sQuery)
          rs = database.query(sQuery)
          for j=1, #rs do
             printf("Note id: %d, note key: %s, description: %s", rs[j].note_id, rs[j].note_key, rs[j].description)
          end
       end
    end
    
    database.close()

     

     

    Output may look like

     

     

    ----------- Executing script at 19.04.2011 09:36:57 ----------
    
      select alarms with notes
      Alarm: 01 FA11050196-91595 w7geha information Testmessage2
      Note id: 24, note key: TK03195155-00002, description: test notat 2

     

     

    Thanks,

    Geir.



  • 4.  Re: test via LUA Script if alarm has a note attached to it

    Posted 04-19-2011 04:00 PM

    Geir,

     

    Where do you see a notes property on alarms?

    Thanks,

    Keith



  • 5.  Re: test via LUA Script if alarm has a note attached to it

    Posted 04-20-2011 09:26 AM

    Hi Keith,

     

    as far as I can see, the alarms returned by alarm.list has a "notes" field which is either 0 or 1.

    It is a column in the NAS_ALARM table in the NIS bridge and I believe also in the internal sqlite db ( but I haven't looked there to confirm. I assume they are 1 to 1 between the table schema in NIS db and sqlite db. )

     

    Geir.

     



  • 6.  Re: test via LUA Script if alarm has a note attached to it

    Posted 06-03-2011 05:43 PM

    Interesting. I can see in the NAS 3.51 Tech Brief that the NAS_ALARMS database table has a notes column. However the documentation regarding the LUA table returned by an alarm.get() and alarm.list() does not include the notes key. Is there a more current version of the tech Brief available that has this documented?



  • 7.  Re: test via LUA Script if alarm has a note attached to it

    Posted 06-06-2011 10:08 AM

    Hi,

     

    I will attach version 3.60 which is the latest, but I see the documentation is missing the notes key still in the table documentation describing what is returned from the alarm.list.

     

    Geir.



  • 8.  Re: test via LUA Script if alarm has a note attached to it

    Posted 09-27-2011 05:29 PM
    Geir is my hero today!


  • 9.  RE: Re: test via LUA Script if alarm has a note attached to it

    Posted 08-19-2019 08:48 AM
    ​A very old thread I know, but I'm running the following script but not getting the notes displayed to the alerts in the "select alarms with notes" section..

    al=alarm.list()
    if al ~= nil then
       for i=1,#al do
          sNote = "No"
          -- Print nimid, hostname, severity, message and note
          if al[i].notes == 1 then
             sNote = "yes"
          end
          printf("%02d %s %s %s %s Note: %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message, sNote)
       end
    end

    printf "select alarms with notes"
    al=alarm.list("notes","1")
    if al ~= nil then
       for i=1,#al do
          -- Print nimid, hostname, severity, message and note
          printf("%02d %s %s %s %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message)
       end
    end

    I can't see where it's printing the note in the print command? I've tried adding a[i].notes or a[i].note but it's not playing ball.

    This would be really useful to play a part in a use case I have where I need to extract the note (service desk ticket reference) and email an extract of a log file to the Service desk to attach to the ticket, but I need the ticket reference in the note to include in the email subject.

    Any input on this would be great.

    Thanks,

    ------------------------------
    CA - UIM administrator
    ------------------------------



  • 10.  RE: Re: test via LUA Script if alarm has a note attached to it

    Posted 08-23-2019 03:23 AM
    I tried the original script and this worked fine on UIM 9.0.2
    You only need the second part of the script because the first part will print all open alarms with an indication if there is a note or not.
    Do you have 'open' alarms with a note in it?


  • 11.  RE: Re: test via LUA Script if alarm has a note attached to it

    Posted 08-23-2019 04:21 AM
    Hi Luc,

    Yep, we had loads of open alarms with notes attached.

    I'll give it another go and post the output.

    ------------------------------
    CA - UIM administrator
    ------------------------------