Hi all,
I found this LUA script somewhere, but I cant remember where..
It doesnt error but doesnt deliver any emails either..
Could someone take a look at see if they can tell why?
----------------------------------------------------------------------------------------------
-- Script to dump alarms that happened within a time-period e.g during last night/evening
--
recipient = "sam.g@mdscem.com"
timezone_ofs = 0
-- Uncomment for manual timezone ofset override.
-- timezone_ofs = -7200 -- GMT+2
-- This function checks if the alarm has arrived within a predefined period
-- E.g check_alarm (a,18,8) -- will return true if alarm arrived last night
-- check_alarm (1,21,06,false) -- will return true if alarm arrived in timewindow regardless.
--
function check_alarm(a,t1,t2,last_night)
local d,midnight,pstart,pend
if t1==nil then t1=0 end
if t2==nil then t2=6 end
if last_night==nil then last_night=true end
if last_night then
d = math.floor (timestamp.now() / 86400)
else
d = math.floor (a.arrival / 86400)
end
midnight = d*86400 + timezone_ofs -- compute 'last' midnight for alarm (adjusted with timezone)
if t1 > t2 then
pstart = midnight + (t1 * 3600)
pend = midnight + 3600*24 + (t2 * 3600) -- adjust till "todays" midnight
else
pstart = midnight + (t1 * 3600)
pend = midnight + (t2 * 3600)
end
if a.arrival >= pstart and a.arrival <= pend then
return true
end
return false
end
-- Get active alarms
al = alarm.list()
buf = ""
for i,a in pairs(al) do
-- auto timezone: use the first alarm with tz_offset as the timezone_ofs
if timezone_ofs == 0 and a.tz_offset ~= nil then
timezone_ofs = a.tz_offset
end
if a.level > NIML_CLEAR then
-- check alarms between 22 and 06, last night
if check_alarm(a,22,06) then
buf = buf .. sprintf ("\n%s - %s %s %s %s",timestamp.format(a.arrival),a.nimid, a.hostname, a.severity, a.message)
end
end
end
if buf ~= "" then
action.email (recipient,"Nightly Alarm Report",buf)
end