Add check to report periodic 5min script running out of time

This commit is contained in:
emanuele-f 2017-03-15 15:54:51 +01:00
parent 87fdd64f7d
commit 84b8499a23
2 changed files with 37 additions and 9 deletions

View file

@ -11,6 +11,12 @@ local callback_utils = {}
-- ########################################################
function callback_utils.print(file, line, message)
print("["..file.."]:["..line.."] "..message)
end
-- ########################################################
-- Iterates available interfaces, excluding PCAP interfaces.
-- Each valid interface is select-ed and passed to the callback.
function callback_utils.foreachInterface(ifnames, verbose, callback)
@ -21,16 +27,20 @@ function callback_utils.foreachInterface(ifnames, verbose, callback)
if(verbose) then print("\n["..__FILE__()..":"..__LINE__().."]===============================\n["..__FILE__()..":"..__LINE__().."] Processing interface " .. _ifname .. " ["..ifstats.id.."]\n") end
if((ifstats.type ~= "pcap dump") and (ifstats.type ~= "unknown")) then
callback(_ifname, ifstats, verbose)
if callback(_ifname, ifstats, verbose) == false then
return false
end
end
end
return true
end
-- ########################################################
-- Iterates each active host on the ifname interface.
-- Each host is passed to the callback with some more information.
function callback_utils.foreachHost(ifname, verbose, callback)
function callback_utils.foreachHost(ifname, verbose, callback, deadline)
local hostbase
interface.select(ifname)
@ -40,6 +50,11 @@ function callback_utils.foreachHost(ifname, verbose, callback)
for hostname, hoststats in pairs(hosts_stats) do
local host = interface.getHostInfo(hostname)
if ((deadline ~= nil) and (os.time() >= deadline)) then
-- Out of time
return false
end
if(host == nil) then
if(verbose) then print("\n["..__FILE__()..":"..__LINE__().."] NULL host "..hostname.." !!!!\n") end
else
@ -61,9 +76,13 @@ function callback_utils.foreachHost(ifname, verbose, callback)
hostbase = nil
end
callback(hostname--[[name of the host]], host--[[hostinfo]], hoststats, hostbase--[[base RRD host directory]], verbose)
if callback(hostname--[[name of the host]], host--[[hostinfo]], hoststats, hostbase--[[base RRD host directory]], verbose) == false then
return false
end
end
end
return true
end
-- ########################################################