mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Addresses #3720 Alerts Refactor: alert_utils as module Alerts Refactor: notify_ntopng_start and notify_ntopng_stop Alerts Refactor: processAlertNotifications Alerts Refactor: checkStoreAlertsFromC Alerts Refactor: formatAlertNotification Alerts Refactor: notification_timestamp_rev Alerts Refactor: formatAlertMessage Alerts Refactor: getConfigsetAlertLink Alerts Refactor: alertNotificationActionToLabel Alerts Refactor: flushAlertsData Alerts Refactor: disableAlertsGeneration Alerts Refactor: newAlertsWorkingStatus and other Alerts Refactor: drawAlerts Alerts Refactor: drawAlertTables Alerts Refactor: printAlertTables Alerts Refactor: checkDeleteStoredAlerts Alerts Refactor: getUnpagedAlertOptions Alerts Refactor: getTabParameters Alerts Refactor: getAlerts Alerts Refactor: getNumAlerts Alerts Refactor: performAlertsQuery Alerts Refactor: sec2granularity Alerts Refactor: granularity2id Alerts Refactor: granularity2sec Alerts Refactor: alertEngineLabel Alerts Refactor: alertEngine Alerts Refactor: alertEngineRaw Alerts Refactor: alertTypeDescription Alerts Refactor: alertType Alerts Refactor: alertTypeLabel Alerts Refactor: alertTypeRaw Alerts Refactor: alertSeverity Alerts Refactor: alertSeverityLabel Alerts Refactor: alertSeverityRaw Alerts Refactor: get_make_room_keys Alerts Refactor: enterprise_alert_utils
85 lines
2.2 KiB
Lua
85 lines
2.2 KiB
Lua
--
|
|
-- (C) 2013-20 - ntop.org
|
|
--
|
|
|
|
dirs = ntop.getDirs()
|
|
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
|
|
|
require "lua_utils"
|
|
local alert_utils = require "alert_utils"
|
|
require "flow_utils"
|
|
local alert_consts = require "alert_consts"
|
|
local format_utils = require "format_utils"
|
|
local json = require "dkjson"
|
|
|
|
sendHTTPHeader('application/json')
|
|
|
|
local ifid = _GET["ifid"]
|
|
local status = _GET["status"]
|
|
|
|
local if_name = nil
|
|
if not isEmptyString(ifid) then
|
|
if_name = getInterfaceName(ifid)
|
|
end
|
|
|
|
interface.select(if_name)
|
|
|
|
local engaged = false
|
|
if status == "engaged" then
|
|
engaged = true
|
|
end
|
|
|
|
interface.select(ifname)
|
|
|
|
local alert_options = _GET
|
|
local alerts = alert_utils.getAlerts(status, alert_options)
|
|
|
|
if alerts == nil then alerts = {} end
|
|
|
|
local result = {}
|
|
|
|
for _key,_value in ipairs(alerts) do
|
|
local record = {}
|
|
local alert_entity
|
|
local alert_entity_val
|
|
|
|
if _value["alert_entity"] ~= nil then
|
|
alert_entity = alert_consts.alertEntityLabel(_value["alert_entity"], true)
|
|
else
|
|
alert_entity = "flow" -- flow alerts page doesn't have an entity
|
|
end
|
|
|
|
if _value["alert_entity_val"] ~= nil then
|
|
alert_entity_val = _value["alert_entity_val"]
|
|
else
|
|
alert_entity_val = ""
|
|
end
|
|
|
|
local column_duration
|
|
if engaged == true then
|
|
column_duration = os.time() - tonumber(_value["alert_tstamp"])
|
|
elseif tonumber(_value["alert_tstamp_end"]) ~= nil then
|
|
column_duration = tonumber(_value["alert_tstamp_end"]) - tonumber(_value["alert_tstamp"])
|
|
end
|
|
|
|
local column_severity = alert_consts.alertSeverityLabel(tonumber(_value["alert_severity"]), true)
|
|
local column_type = alert_consts.alertTypeLabel(tonumber(_value["alert_type"]), true)
|
|
local column_msg = alert_utils.formatAlertMessage(ifid, _value)
|
|
local column_id = tostring(_value["rowid"])
|
|
local column_date = _value["alert_tstamp"]
|
|
|
|
record["key"] = column_id
|
|
record["date"] = column_date
|
|
record["duration"] = column_duration
|
|
record["severity"] = column_severity
|
|
record["type"] = column_type
|
|
record["msg"] = column_msg
|
|
record["entity"] = alert_entity
|
|
record["entity_val"] = alert_entity_val
|
|
|
|
result[#result + 1] = record
|
|
|
|
end -- for
|
|
|
|
print(json.encode(result))
|
|
|