DX Unified Infrastructure Management

Expand all | Collapse all

Create new alarm using Lua

  • 1.  Create new alarm using Lua

    Posted Jun 26, 2016 08:10 AM

    Hello,

     

    Is there a simple way to create alarm on specific robot using Lua script ?

     

    Thank you,

    Amit



  • 2.  Re: Create new alarm using Lua

    Broadcom Employee
    Posted Jun 27, 2016 01:27 AM

    Below is an example .Can be  executed directly from the nas -> Auto-Operator -> Scripts

    -- create alarm

    for i=1,10 do

    nimbus.request("/<some_domain>/<some_hub>/<some_robot>/controller", "test_alarm", 2)

    end



  • 3.  Re: Create new alarm using Lua

    Posted Jun 27, 2016 02:23 AM

    Hi,

    Thanks, but this creates a test alarm.

    I need to create an alarm where i can set the text...

     

    Amit,



  • 4.  Re: Create new alarm using Lua

    Broadcom Employee
    Posted Jun 27, 2016 04:06 AM

    Hi Amit,

    Here is a script that I've used in the past to create a completely new alarm building it from the pds.

    Hope it helps!

    cheers

    Rowan

     

     

     

    local a = alarm.get()

     

    -- Generates a nimid

    function unique_id()

      

       key = ""

       base="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

       math.random();math.random()

      

     

    key = mid(base,math.random(1,26),1) .. mid(base,math.random(1,26),1) ..

    sprintf("%07d", math.random(1,100000000)) .. "-" ..

    sprintf("%05d",math.random(1,100000))

       return key

    end

     

    -----------------------------------------------------------------------------------------

    -- rawalarm (source,severity,subsystem,message ]]]])

    -- returns 0 - ok, rest error

    ---

    function rawalarm (source,severity,subsystem,message,suppkey,domain,origin,robot,probe,devid,metid,tzoffset,md5sum)

       -- expect following parameters

       if type(severity) ~= "number" then return 1 end

       if type(message) ~= "string" then return 1 end

       if type(subsystem) ~= "string" then return 1 end

       if type(source) ~= "string" then return 1 end

     

       -- set default values for optional parameters.

       if type(domain) ~= "string" then domain="lua-domain" end

       if type(origin) ~= "string" then origin="lua-origin" end

       if type(robot) ~= "string" then robot="lua-robot" end

       if type(probe) ~= "string" then probe="lua-probe" end

       if type(suppkey) ~= "string" then suppkey="lua-suppkey" end

     

       msg = pds.create ()

       nimid = unique_id()

      

       -- Create message header

       pds.putString (msg,"nimid",nimid)

       pds.putInt    (msg,"nimts",timestamp.now() )

       pds.putInt    (msg,"tz_offset",tzoffset)

       pds.putString (msg,"source",source)

       pds.putString (msg,"md5sum","")

       pds.putString (msg,"robot",robot)

       pds.putString (msg,"domain",domain)

       pds.putString (msg,"origin",origin)

       pds.putInt    (msg,"pri",severity)

       pds.putString (msg,"subject","alarm")

       pds.putString (msg,"suppression","y+000000000#" .. suppkey)

       pds.putString (msg,"supp_key",suppkey)

       pds.putString (msg,"prid",probe)

       pds.putString (msg,"dev_id",devid)

       pds.putString (msg,"met_id",metid)

      

       -- Add raw alarm data

       udata = pds.create()

       pds.putInt    (udata,"level",severity)

       pds.putString (udata,"subsys",subsystem)

       pds.putString (udata,"message",message)

      

       pds.putPDS (msg,"udata",udata)

      

       -- Post the message to the hub-spooler

       t,rc = nimbus.request ("spooler","hubpost",msg)

     

       pds.delete (udata)

       pds.delete (msg)

       return rc,nimid

    end

     

    -- initialize the random generator

    math.randomseed(os.time())

     

    --rc,id = rawalarm ("193.71.55.210",3,"1.2.3","This is a simple test...")

    --printf ("rawalarm: %s, %d",id,rc)

     

    rc,id = rawalarm (a.source,a.level,a.sid,"RAW : "..a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid,a.dev_id,a.met_id,a.tz_offset,a.md5sum)

    --source,severity,subsystem,message,suppkey,domain,origin,robot,probe

    --rawalarm (a.source,a.pri,a.subsys,a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid)

    --rc = rawalarm (a.source,a.pri,a.subsys,a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid)

     

     

    printf ("rawalarm: %s, %d",id,rc)



  • 5.  Re: Create new alarm using Lua

    Posted Jun 28, 2016 04:22 AM

    Hello Rowam,

     

    Thank you very much.

     

    But how do you use this ?

    I tried running rawalarm ("mqilnxdvl",4,"Robot","Hello Robot") but i get an error :

    Error in line 16: attempt to call global 'rawalarm' (a nil value)

     

    Thanks,

    Amit



  • 6.  Re: Create new alarm using Lua

    Posted Dec 26, 2017 02:44 PM

    Hi!

     

    I am using the script below to generate new alarms
    But it generates a new alarm for a single alarm based on the profile

    How to modify it to generate a new alarm for any new alarm that hits the profile filter?

     

    Rowan Collis wrote:

     

    Hi Amit,

    Here is a script that I've used in the past to create a completely new alarm building it from the pds.

    Hope it helps!

    cheers

    Rowan

     

     

     

    local a = alarm.get()

     

    -- Generates a nimid

    function unique_id()

      

       key = ""

       base="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

       math.random();math.random()

      

     

    key = mid(base,math.random(1,26),1) .. mid(base,math.random(1,26),1) ..

    sprintf("%07d", math.random(1,100000000)) .. "-" ..

    sprintf("%05d",math.random(1,100000))

       return key

    end

     

    -----------------------------------------------------------------------------------------

    -- rawalarm (source,severity,subsystem,message ]]]])

    -- returns 0 - ok, rest error

    ---

    function rawalarm (source,severity,subsystem,message,suppkey,domain,origin,robot,probe,devid,metid,tzoffset,md5sum)

       -- expect following parameters

       if type(severity) ~= "number" then return 1 end

       if type(message) ~= "string" then return 1 end

       if type(subsystem) ~= "string" then return 1 end

       if type(source) ~= "string" then return 1 end

     

       -- set default values for optional parameters.

       if type(domain) ~= "string" then domain="lua-domain" end

       if type(origin) ~= "string" then origin="lua-origin" end

       if type(robot) ~= "string" then robot="lua-robot" end

       if type(probe) ~= "string" then probe="lua-probe" end

       if type(suppkey) ~= "string" then suppkey="lua-suppkey" end

     

       msg = pds.create ()

       nimid = unique_id()

      

       -- Create message header

       pds.putString (msg,"nimid",nimid)

       pds.putInt    (msg,"nimts",timestamp.now() )

       pds.putInt    (msg,"tz_offset",tzoffset)

       pds.putString (msg,"source",source)

       pds.putString (msg,"md5sum","")

       pds.putString (msg,"robot",robot)

       pds.putString (msg,"domain",domain)

       pds.putString (msg,"origin",origin)

       pds.putInt    (msg,"pri",severity)

       pds.putString (msg,"subject","alarm")

       pds.putString (msg,"suppression","y+000000000#" .. suppkey)

       pds.putString (msg,"supp_key",suppkey)

       pds.putString (msg,"prid",probe)

       pds.putString (msg,"dev_id",devid)

       pds.putString (msg,"met_id",metid)

      

       -- Add raw alarm data

       udata = pds.create()

       pds.putInt    (udata,"level",severity)

       pds.putString (udata,"subsys",subsystem)

       pds.putString (udata,"message",message)

      

       pds.putPDS (msg,"udata",udata)

      

       -- Post the message to the hub-spooler

       t,rc = nimbus.request ("spooler","hubpost",msg)

     

       pds.delete (udata)

       pds.delete (msg)

       return rc,nimid

    end

     

    -- initialize the random generator

    math.randomseed(os.time())

     

    --rc,id = rawalarm ("193.71.55.210",3,"1.2.3","This is a simple test...")

    --printf ("rawalarm: %s, %d",id,rc)

     

    rc,id = rawalarm (a.source,a.level,a.sid,"RAW : "..a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid,a.dev_id,a.met_id,a.tz_offset,a.md5sum)

    --source,severity,subsystem,message,suppkey,domain,origin,robot,probe

    --rawalarm (a.source,a.pri,a.subsys,a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid)

    --rc = rawalarm (a.source,a.pri,a.subsys,a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid)

     

     

    printf ("rawalarm: %s, %d",id,rc)



  • 7.  Re: Create new alarm using Lua

    Posted Dec 26, 2017 03:53 PM

    I believe you will have to replace the fixed variables with the environment variables that you reset by get alarm.



  • 8.  Re: Create new alarm using Lua

    Posted Dec 26, 2017 05:32 PM

    I believe you are correct, but I do not see fixed variables in the code



  • 9.  Re: Create new alarm using Lua

    Posted Dec 26, 2017 06:23 PM

    Say, what you want to do from start to finish. Do you really need this script?



  • 10.  Re: Create new alarm using Lua

    Posted Dec 26, 2017 06:37 PM

    Yes, I need

     

    I have critical and major alarms which need to be updated by the team every X minutes

    I thought about creating a new alarm from the old modifying part of the alarm message signaling that it is a renotification and deleting the old alarm

     

    Repost did not work in my tests because I need to modify part of the alarm to inform the team that is a re-notification

     

    Setting to send email from X to X minutes also does not work because it does not guarantee that it will be handled.



  • 11.  Re: Create new alarm using Lua
    Best Answer

    Broadcom Employee
    Posted Jul 15, 2016 09:32 AM

    Amit

    I've added a few extra default values, please give this a try now, it should work for you.

    You will need to populate the devid and metid for the alarms to show in usm properly (against the device).

     

    --local a = alarm.get()

    -- Generates a nimid

    function unique_id()

      

       key = ""

       base="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

       math.random();math.random()

    key = mid(base,math.random(1,26),1) .. mid(base,math.random(1,26),1) ..

    sprintf("%07d", math.random(1,100000000)) .. "-" ..

    sprintf("%05d",math.random(1,100000))

       return key

    end

     

    -----------------------------------------------------------------------------------------

    -- rawalarm (source,severity,subsystem,message ]]]])

    -- returns 0 - ok, rest error

    ---

    function rawalarm (source,severity,subsystem,message,suppkey,domain,origin,robot,probe,devid,metid,tzoffset,md5sum)

       -- expect following parameters

       if type(severity) ~= "number" then return 1 end

       if type(message) ~= "string" then return 1 end

       if type(subsystem) ~= "string" then return 1 end

       if type(source) ~= "string" then return 1 end

     

       -- set default values for optional parameters.

       if type(domain) ~= "string" then domain="rc82-dom" end

       if type(origin) ~= "string" then origin="customerA" end

       if type(robot) ~= "string" then robot="colro22-i147145" end

       if type(probe) ~= "string" then probe="nas-lua-script" end

       if type(suppkey) ~= "string" then suppkey="lua-suppkey" end

       if type(tzoffset) ~= "number" then tzoffset=0 end

       if type(devid) ~= "string" then devid="" end

       if type(metid) ~= "string" then metid="" end

     

     

     

       msg = pds.create ()

       nimid = unique_id()

      

       -- Create message header

       pds.putString (msg,"nimid",nimid)

       pds.putInt    (msg,"nimts",timestamp.now() )

       pds.putInt    (msg,"tz_offset",tzoffset)

       pds.putString (msg,"source",source)

       pds.putString (msg,"md5sum","")

       pds.putString (msg,"robot",robot)

       pds.putString (msg,"domain",domain)

       pds.putString (msg,"origin",origin)

       pds.putInt    (msg,"pri",severity)

       pds.putString (msg,"subject","alarm")

       pds.putString (msg,"suppression","y+000000000#" .. suppkey)

       pds.putString (msg,"supp_key",suppkey)

       pds.putString (msg,"prid",probe)

       pds.putString (msg,"dev_id",devid)

       pds.putString (msg,"met_id",metid)

      

       -- Add raw alarm data

       udata = pds.create()

       pds.putInt    (udata,"level",severity)

       pds.putString (udata,"subsys",subsystem)

       pds.putString (udata,"message",message)

      

       pds.putPDS (msg,"udata",udata)

      

       -- Post the message to the hub-spooler

       t,rc = nimbus.request ("spooler","hubpost",msg)

     

       pds.delete (udata)

       pds.delete (msg)

       return rc,nimid

    end

     

    -- initialize the random generator

    math.randomseed(os.time())

     

    rc,id = rawalarm ("10.131.60.70",3,"1.2.3"," RAW:  This is a simple test...")

    --printf ("rawalarm: %s, %d",id,rc)

     

    --rc,id = rawalarm (a.source,a.level,a.sid,"RAW : "..a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid,a.dev_id,a.met_id,a.tz_offset,a.md5sum)

    --source,severity,subsystem,message,suppkey,domain,origin,robot,probe

    --rawalarm (a.source,a.pri,a.subsys,a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid)

    --rc = rawalarm (a.source,a.pri,a.subsys,a.message,a.supp_key,"2e2",a.origin,a.robot,a.prid)

     

     

    printf ("rawalarm: %s, %d",id,rc)



  • 12.  Re: Create new alarm using Lua

    Posted Jul 18, 2016 07:37 AM

    Thank you !

     

    it works good !



  • 13.  Re: Create new alarm using Lua

    Posted Jul 18, 2018 09:14 AM

    Hi!

     

    I don't think I'm following this script quite right.

     

    When I enter an alarm ID into alarm.get I just get this result:

     

     

    I thought it was supposed to rebuild the original alarm with the details taken from the ID entered into the alarm.get command?

     

    Like this:

     

    local a = alarm.get("AK45541189-22022")

     

    What am I doing wrong?

     

    Thanks,



  • 14.  Re: Create new alarm using Lua

    Posted Jul 19, 2018 12:03 PM

    Think I've found a solution to this..

     

    --Gets alarm from AO

    a = alarm.get()

     

    --A business requirement of ours:

    --Scans message and removes ampersands from message to allow alert to be passed to XML file

    message1 = string.gsub(a.message, "%&","&amp;")

     

    --Call library

    require ("library/Create_alarm")

     

    --Declare variables

    alarm_domain = a.domain
    alarm_origin = a.origin
    robot_name = a.hostname
    robot_source = a.source
    probe_name = a.prid
    alarm_SID = a.sid
    alarm_severity = a.level
    message = a.message
    hub_name = a.hub

     

    --optional variables

    alarm_suppKey = supp_key

     

    --Create Alarm

    createAlarm (alarm_domain,alarm_origin,robot_name,robot_source,probe_name,alarm_SID,message1,alarm_severity,alarm_suppKey)



  • 15.  Re: Create new alarm using Lua

    Posted Feb 21, 2017 03:04 PM

    Hello,

    How do I add the field (user_tag1)?

    Thank you.



  • 16.  Re: Create new alarm using Lua

    Posted Feb 22, 2017 05:53 AM

    Hi,

     

    Note :  ( Hubpost, post, post_raw are pretty similar ). I recommand to use post_raw.

     

    If you take the code from Rowan it's : 

     

    pds.putString (msg,"user_tag_1","here")

    pds.putString (msg,"user_tag_2","here")

     

     

    Best Regards,

    Thomas



  • 17.  Re: Create new alarm using Lua

    Posted Feb 22, 2017 11:44 AM

    It worked...
    I had adapted, but that's a lot better.
    Thank you.



  • 18.  Re: Create new alarm using Lua

    Posted Jul 06, 2018 09:10 AM

    Hi!

     

    I'm struggling to rebuild an alarm after passing it through a LUA script.  The aim is to remove and ampersands from the alert text and then rebuild the original alert, but with the new text.

     

    If anyone could take a look I'd really appreciate it:

     

    Rebuild alarm after processing through LUA 

     

    Cheers,