UK CA Unified Infrastructure Management User Group

 View Only
  • 1.  Add Note to Alarm via Lua

    Posted Mar 01, 2019 09:34 AM

    Hi,

     

    I'm looking for a little usage advice on the note.create and note.attach.

     

    I have a script that posts to a ticketing system and returns the ticket reference number, I'm looking at getting this added to the alert it is referring to so we can see the ticket reference attached to the alarm.

     

    Here is the full code:

     

    a = alarm.get("XI42492581-93895")

     

    --Strips characters to avoid XML character limitations:

     

    message1 = string.gsub(a.message, "%&","&")  -- change string parts
    --message2 = string.gsub(message1, "=","equals ")
    message3 = string.gsub(message1, "%<=","less than or equal to")
    message4 = string.gsub(message3, "%>=","greater than or equal to")
    message5 = string.gsub(message4, "%<","less than")
    message6 = string.gsub(message5, "%>","greater than")

    require ("library/xml-alarms-lib")

    buf = xml_alarm_constructor_for_REST(ticketing_system)

    filename = "/tmp/" .. os.clock() .. "_alarm_input.xml"
    --filename = "/tmp/alarm_input.xml"

    if buf ~= "" then
                   file.create (filename, buf )
    --               file.create ("TESTFILE")
                   output, rc = action.command ("/opt/nimsoft/scripts/Alert_Via_Ticketing_System.sh " .. filename)
                   --output,rc = action.command ("/root/Alert_Via_UMP.sh " .. filename)
                   --print (output, "\t", rc)
                   for i,line in ipairs(output) do
                      print(line)

     

    --HERE'S THE PROBLEMATIC LINE.....

    note.attach ("Ticket ID-"..line)

                   end

    else
                    print "No open alarms, file is not written..."
    end

    file.delete (filename)