NAS report: get alarms in period with original severity and message

Discussion created by carstein.seeberg on Sep 10, 2008
Latest reply on Sep 11, 2008 by keith_k
Here's a little snippet that prints a report containing the closed alarms the last n days, the user that acknowledged the alarm, the user it was assigned to (if any) and the original severity and message.
Please note that reason for using the alarm.query() function instead of the alarm.history() function is the need to map the original severity/message.

-- get_closed_alarms (3) => last 3 days
function get_closed_alarms (days)
   return alarm.query ("SELECT t1.time, t1.nimid, t1.closed, t1.hostname, t1.acknowledged_by, t1.assigned_to, t2.message, t2.level, t2.severity FROM NAS_TRANSACTION_SUMMARY t1, NAS_TRANSACTION_LOG t2 WHERE t2.type=1 AND NOT t1.closed IS NULL AND t1.time >= datetime('now','localtime','-"..days.." days') AND t1.nimid = t2.nimid")

h = get_closed_alarms(2)

for i,a in pairs(h) do
   if a.assigned_to == nil then
      printf("%s by %s, %-15s %-10s %s", a.closed, a.acknowledged_by, a.hostname, a.severity, a.message )
      printf("%s by %s, %-15s %-10s %s %s", a.closed, a.acknowledged_by, a.hostname, a.severity, a.message, a.assigned_to )