ntopng/scripts/lua/modules/alert_endpoints/nagios.lua
emanuele-f a9d3c78587 Alerts changes
NOTE: database schema changed. Existing alerts will be lost.

- Unified engaged and closed tables
- Simplified hosts engaged alert counters handling: periodically set by lua
- Removed alert engine and replaced with alert periodicity
- Now engage is implicitly derived from the alert end timestamp and periodicity
- New alerts_api.lua to easily emit alerts
- Removed past alerts counter aggregation by hash
- Alert notifications for non-flow alerts are now removed from C and triggered by lua
2019-06-28 10:47:17 +02:00

46 lines
1.2 KiB
Lua

--
-- (C) 2018 - ntop.org
--
require("lua_utils")
local alerts = require("alerts_api")
local nagios = {}
nagios.EXPORT_FREQUENCY = 1
function nagios.dequeueAlerts(queue)
if not ntop.isPro() or not hasNagiosSupport() then
return {success=false, error_message="Nagios support is not available"}
end
while true do
local notifications = ntop.lrangeCache(queue, 0, 0)
if (not notifications) or (#notifications ~= 1) then
break
end
local notif = alertNotificationToObject(notifications[1])
local entity_value = notif.entity_value
local alert = alerts.parseNotification(notif)
local akey = alert:getId()
if notif.action == "engage" then
if not ntop.sendNagiosAlert(entity_value:gsub("@0", ""), akey, notif.message) then
return {success=false, error_message="Unable to send alert to nagios"}
end
elseif notif.action == "release" then
if not ntop.withdrawNagiosAlert(entity_value:gsub("@0", ""), akey, "Service OK.") then
return {success=false, error_message="Unable to withdraw nagios alert"}
end
end
-- Remove the notification from the queue
ntop.lpopCache(queue)
end
return {success=true}
end
return nagios