mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Adds optional JSON syslog alert format
This commit is contained in:
parent
603bc2d31c
commit
a86239fac3
5 changed files with 61 additions and 8 deletions
|
|
@ -17,11 +17,16 @@ function syslog.dequeueAlerts(queue)
|
|||
return {success = true}
|
||||
end
|
||||
|
||||
local syslog_format = ntop.getPref("ntopng.prefs.syslog_alert_format")
|
||||
if isEmptyString(syslog_format) then
|
||||
syslog_format = "plaintext"
|
||||
end
|
||||
|
||||
-- Separate by severity and channel
|
||||
local alerts_by_types = {}
|
||||
|
||||
for _, json_message in ipairs(notifications) do
|
||||
local notif = alertNotificationToObject(json_message)
|
||||
local notif = alertNotificationToObject(json_message)
|
||||
|
||||
alerts_by_types[notif.entity_type] = alerts_by_types[notif.entity_type] or {}
|
||||
alerts_by_types[notif.entity_type][notif.severity] = alerts_by_types[notif.entity_type][notif.severity] or {}
|
||||
|
|
@ -32,12 +37,24 @@ function syslog.dequeueAlerts(queue)
|
|||
for severity, notifications in pairs(by_severity) do
|
||||
-- Most recent notifications first
|
||||
for _, notif in pairsByValues(notifications, notification_timestamp_rev) do
|
||||
local msg = formatAlertNotification(notif, {nohtml = true,
|
||||
show_severity = true,
|
||||
show_entity = true})
|
||||
|
||||
|
||||
local syslog_severity = alertLevelToSyslogLevel(notif.severity)
|
||||
|
||||
local msg
|
||||
|
||||
if syslog_format == "plaintext" then
|
||||
-- prepare a plaintext message
|
||||
msg = formatAlertNotification(notif, {nohtml = true,
|
||||
show_severity = true,
|
||||
show_entity = true})
|
||||
else -- syslog_format == "json" then
|
||||
-- send out the json message but prepare a nice
|
||||
-- message
|
||||
notif.message = formatAlertNotification(notif, {nohtml = true,
|
||||
show_severity = false,
|
||||
show_entity = false})
|
||||
msg = json.encode(notif)
|
||||
end
|
||||
|
||||
ntop.syslog(msg, syslog_severity)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue