NAS Lua script to close inactive/idle alarms

Discussion created by keith_k on Sep 6, 2008
Latest reply on Sep 12, 2008 by nrtimm
You can create a NAS auto-operator profile that operates on messages that are over a certain age, which I believe is based on the arrival time.  I wanted to close alarms that had not been updated in over 30 days based on the received time in the alarm subconsole.  I did not see any way to do this in an AO profile, so I created the Lua script below to check it for me.

I discovered that there is no field in the alarm database for the received time, and I concluded that the received time listed in the alarm subconsole is based on either the arrival time or the suppression time.  I tested quite a bit, and I think my logic works out correctly.

Let me know if you have any questions.


-- Close any alarms that have not been updated recently

-- Number of days ago the last update to an alarm must have arrived
alarm_idle_days = 30

-- Start with empty list of alarms to close
close_list = ""
close_count = 0

-- Reference time for comparison with most recent update time
ref_time = os.time() - alarm_idle_days * 86400

-- All open alarms in a list
alarms = alarm.list()

if alarms ~= nil then
   for i = 1, #alarms do

      -- Determine alarm received time based on suppression time if available,
      -- otherwise the arrival time
      if alarms.supptime == nil or alarms.supptime == 0 then
         recv_time = alarms.arrival
         recv_time = alarms.supptime

      -- Check if alarm was received before reference time
      if recv_time < ref_time then
         close_count = close_count + 1
         close_list = close_list .. alarms.nimid .. ","

-- Close alarms without updates since the reference time
if close_list ~= "" then
   print("Closing " .. close_count .. " alarms: " .. close_list)