mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
Implements a lua endpoint to send alerts to syslog
Implements #1973 Implements #1954
This commit is contained in:
parent
b1d54fc1a9
commit
8a055b39c5
10 changed files with 157 additions and 80 deletions
|
|
@ -553,11 +553,26 @@ end
|
|||
|
||||
function noHtml(s)
|
||||
if s == nil then return nil end
|
||||
|
||||
local gsub, char = string.gsub, string.char
|
||||
local entityMap = {lt = "<", gt = ">" , amp = "&", quot ='"', apos = "'"}
|
||||
local entitySwap = function(orig, n, s)
|
||||
return (n == '' and entityMap[s])
|
||||
or (n == "#" and tonumber(s)) and string.char(s)
|
||||
or (n == "#x" and tonumber(s,16)) and string.char(tonumber(s,16))
|
||||
or orig
|
||||
end
|
||||
|
||||
local function unescape(str)
|
||||
return (gsub( str, '(&(#?x?)([%d%a]+);)', entitySwap ))
|
||||
end
|
||||
|
||||
local cleaned = s:gsub("<[aA].->(.-)</[aA]>","%1")
|
||||
:gsub("%s*<[iI].->(.-)</[iI]>","%1")
|
||||
:gsub("<.->(.-)</.->","%1") -- note: this does not handle nested tags
|
||||
:gsub("^%s*(.-)%s*$", "%1")
|
||||
return cleaned
|
||||
|
||||
return unescape(cleaned)
|
||||
end
|
||||
|
||||
function alertSeverityLabel(v, nohtml)
|
||||
|
|
@ -625,6 +640,15 @@ function alertLevel(v)
|
|||
return(_handleArray(leveltable, v))
|
||||
end
|
||||
|
||||
function alertLevelToSyslogLevel(v)
|
||||
local leveltable = {}
|
||||
|
||||
for i, t in ipairs(alert_consts.alert_severity_keys) do
|
||||
leveltable[#leveltable + 1] = {t[4], t[3]}
|
||||
end
|
||||
return(_handleArray(leveltable, v))
|
||||
end
|
||||
|
||||
function alertTypeRaw(alert_idx)
|
||||
if(alert_idx == nil) then return nil end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue