DX Unified Infrastructure Management

  • 1.  LUA script to count open alarms from Dirscan and alert if too few

    Posted Aug 02, 2016 12:54 PM


    Hi all,

     

    I've looking into a way of counting open alarms on the alarm console and alerting if there are too few.

    I found this script which apparently does the job, but I'm struggling to amend it to do what I'm looking for..The script runs without errors but doesnt send the alert.

     

    list = alarm.list()

    local match_count = {}

    local current_count = 0

     

    for i=1, #list do

       alm = list[i]

       hub = alm.hub

     

      

       match = regexp( alm.message, "/Average/")

       match = (match and regexp (hub, "/^HubName-/"))

      

       if match == true then

         

         

          if match_count[hub] == nil then

             current_count = 0

          else

             current_count = match_count[hub]

          end

     

          current_count = current_count +1

          match_count[hub] = current_count

       end

    end

     

    for hub, alarm_count in pairs(match_count) do

       suppression_key = "snmpagent-"..hub

       if alarm_count <=20 then

          message = "Excessive number of snmp agents not responding on " .. hub .. " with a total of " .. alarm_count .. " alarms"

          print (message)

     

          nimbus.alarm (4, message , suppression_key)

       end   

    end



  • 2.  Re: LUA script to count open alarms from Dirscan and alert if too few

    Broadcom Employee
    Posted Aug 02, 2016 01:24 PM

    I would add print() message after each line and display value you are checking or expecting

    This will put the information in the nas log.

    This is about the only good way to trouble shoot a script

    example

     

    print("line 1")

    print("hub:"..hub)



  • 3.  Re: LUA script to count open alarms from Dirscan and alert if too few

    Posted Aug 03, 2016 06:21 AM

    2 possibilities:

    - you string "/^HubName-/" is not matching a hub name

    - you have more than 20 matching messages

    Like Gene said, if you add after: if match == true a line like:

      print("hub: "..hub.." count: "..current_count.." msg: "..alm.message)

    you will see in your nas script execute window a print for each matchine message



  • 4.  Re: LUA script to count open alarms from Dirscan and alert if too few

    Posted Aug 03, 2016 09:27 AM

    Thanks all,

     

    Like this? I'm still not getting anything in the execute window

     

    list = alarm.list()

    local match_count = {}

    local current_count = 0

     

     

    for i=1, #list do

       alm = list[i]

       hub = alm.hub

     

     

      

       match = regexp(alm.message, "/Average/")

       match = regexp (hub, "/^mdswust1-/")

      

       if match == true then

         

    print("hub: "..hub.." count: "..current_count.." msg: "..alm.message)

         

          if match_count[hub] == nil then

             current_count = 0

          else

             current_count = match_count[hub]

          end

     

     

          current_count = current_count +1

          match_count[hub] = current_count

       end

    end

     

     

    for hub, alarm_count in pairs(match_count) do

       if alarm_count <=20 then

          message = "Excessive number of snmp agents not responding on " .. hub .. " with a total of " .. alarm_count .. " alarms"

          print (message)

     

     

          nimbus.alarm (2, message , suppression_key)

       end   

    end



  • 5.  Re: LUA script to count open alarms from Dirscan and alert if too few

    Posted Aug 03, 2016 09:34 AM

    Do you have at the moment you run the script messages containing: Average in your console?

    (I tested your script with another wordstring and another hubname and this worked fine.)

    Note: if you put the print line 2 lines higher you will see all console messages he is processing.



  • 6.  Re: LUA script to count open alarms from Dirscan and alert if too few

    Posted Aug 03, 2016 10:30 AM

    Thanks Luc,

     

    I've raised the line by two and yes it does display the alerts, but they all appear to have  count of 0, even though in the alarm console they most of them have a count of more than 0.

     

    I've changed the expected value from >20 to <20 but neither send an alarm..



  • 7.  Re: LUA script to count open alarms from Dirscan and alert if too few

    Posted Aug 03, 2016 10:31 AM

    Would you mind posting your working example here?



  • 8.  Re: LUA script to count open alarms from Dirscan and alert if too few
    Best Answer

    Posted Aug 03, 2016 10:37 AM

    My working script is exactly yours. 

    But if the count in the print stays 0 this means that you don't have a match in the regular expression tests.

    You can make it a little bit easier by changing the line:

    match = regexp (hub, "/^mdswust1-/")

    into

    --match = regexp (hub, "/^mdswust1-/")

    (so that line is in comment)

    When you execute now your script it will only match (count) alarms messages that contain Average