mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-28 23:19:33 +00:00
Add tracing for alerts delivery
This commit is contained in:
parent
b7f21038fd
commit
bf9a3a720c
3 changed files with 128 additions and 99 deletions
|
|
@ -13,6 +13,7 @@ local alert_consts = require("alert_consts")
|
|||
local os_utils = require("os_utils")
|
||||
local recipients = require "recipients"
|
||||
local pools_alert_utils = require "pools_alert_utils"
|
||||
|
||||
local do_trace = false
|
||||
|
||||
local alerts_api = {}
|
||||
|
|
@ -31,11 +32,21 @@ local current_configset -- The configset used for the generation of this alert
|
|||
|
||||
-- ##############################################
|
||||
|
||||
local function debug_print(msg)
|
||||
if not do_trace then
|
||||
return
|
||||
end
|
||||
|
||||
traceError(TRACE_NORMAL, TRACE_CONSOLE, msg)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- Returns a string which identifies an alert
|
||||
function alerts_api.getAlertId(alert)
|
||||
return(string.format("%s_%s_%s_%s_%s", alert.alert_type,
|
||||
alert.subtype or "", alert.granularity or "",
|
||||
alert.entity_id, alert.entity_val))
|
||||
return(string.format("%s_%s_%s_%s_%s", alert.alert_type,
|
||||
alert.subtype or "", alert.granularity or "",
|
||||
alert.entity_id, alert.entity_val))
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -270,8 +281,8 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
|
|||
local alert_key_name = get_alert_triggered_key(type_info.alert_type.alert_key, subtype)
|
||||
|
||||
if not type_info.score then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Alert score is not set")
|
||||
type_info.score = 0
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Alert score is not set")
|
||||
type_info.score = 0
|
||||
end
|
||||
|
||||
local params = {
|
||||
|
|
@ -293,15 +304,10 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
|
|||
end
|
||||
|
||||
if(triggered == nil) then
|
||||
if(do_trace) then
|
||||
print("Alert not triggered (already triggered?) @ "..granularity_sec.."] "..
|
||||
entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
end
|
||||
--debug_print("Alert not triggered (already triggered?) @ "..granularity_sec.."] ".. entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
return(false)
|
||||
else
|
||||
if(do_trace) then
|
||||
print("Alert triggered @ "..granularity_sec.." ".. entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
end
|
||||
--debug_print("Alert triggered @ "..granularity_sec.." ".. entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
end
|
||||
|
||||
triggered.ifid = ifid
|
||||
|
|
@ -313,9 +319,15 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
|
|||
-- same 100 alerts will be triggered again as soon as ntopng is restarted, causing
|
||||
-- 100 trigger notifications to be emitted twice. This check is to prevent such behavior.
|
||||
if not is_trigger_notified(triggered) then
|
||||
addAlertPoolInfo(entity_info, triggered)
|
||||
recipients.dispatch_notification(triggered, current_script)
|
||||
mark_trigger_notified(triggered)
|
||||
|
||||
debug_print("Sending notification for alert " .. entity_info.entity_val)
|
||||
|
||||
addAlertPoolInfo(entity_info, triggered)
|
||||
recipients.dispatch_notification(triggered, current_script)
|
||||
mark_trigger_notified(triggered)
|
||||
|
||||
else
|
||||
debug_print("Alert already notified for " .. entity_info.entity_val)
|
||||
end
|
||||
|
||||
return(true)
|
||||
|
|
@ -371,15 +383,10 @@ function alerts_api.release(entity_info, type_info, when, cur_alerts)
|
|||
end
|
||||
|
||||
if(released == nil) then
|
||||
if(do_trace) then
|
||||
print("Alert not released (not triggered?) @ "..granularity_sec.." "..
|
||||
entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
end
|
||||
--debug_print("Alert not released (not triggered?) @ "..granularity_sec.." ".. entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
return(false)
|
||||
else
|
||||
if(do_trace) then
|
||||
print("Alert released @ "..granularity_sec.." ".. entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
end
|
||||
--debug_print("Alert released @ "..granularity_sec.." ".. entity_info.entity_val .."@"..type_info.alert_type.i18n_title..":".. subtype .. "\n")
|
||||
end
|
||||
|
||||
released.ifid = ifid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue