mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
parent
9889c291cc
commit
0f5d76ca74
14 changed files with 284 additions and 31 deletions
44
scripts/lua/modules/email_utils.lua
Normal file
44
scripts/lua/modules/email_utils.lua
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
--
|
||||
-- (C) 2018 - ntop.org
|
||||
--
|
||||
|
||||
local email = {}
|
||||
|
||||
local function getEmailMessage(now_ts, from, to, subject, body)
|
||||
local now = os.date("%a, %d %b %Y %X", now_ts) -- E.g. "Tue, 3 Apr 2018 14:58:00"
|
||||
local msg_id = "<" .. now_ts .. "." .. os.clock() .. "@ntopng>"
|
||||
|
||||
local lines = {
|
||||
"From: " .. from,
|
||||
"To: " .. to,
|
||||
"Subject: " .. subject,
|
||||
"Date: " .. now,
|
||||
"Message-ID: " .. msg_id,
|
||||
}
|
||||
|
||||
return table.concat(lines, "\r\n") .. "\r\n\r\n" .. body .. "\r\n"
|
||||
end
|
||||
|
||||
function email.sendNotification(notif)
|
||||
if notif.action == "release" then
|
||||
-- Avoid sending release notifications
|
||||
return
|
||||
end
|
||||
|
||||
local email_address = ntop.getPref("ntopng.prefs.alerts.email_address")
|
||||
local smtp_server = ntop.getPref("ntopng.prefs.alerts.smtp_server")
|
||||
|
||||
if isEmptyString(email_address) or isEmptyString(smtp_server) then
|
||||
return false
|
||||
end
|
||||
|
||||
local product = ntop.getInfo(false).product
|
||||
local subject = product .. " [" .. string.upper(notif.severity) .. "]: " .. alertTypeLabel(alertType(notif.type), true)
|
||||
local message_body = unescapeHtmlEntities(noHtml(notif.message))
|
||||
local from_to = email_address
|
||||
local message = getEmailMessage(os.time(), from_to, from_to, subject, message_body)
|
||||
|
||||
return ntop.sendMail(from_to, from_to, message, smtp_server)
|
||||
end
|
||||
|
||||
return email
|
||||
Loading…
Add table
Add a link
Reference in a new issue