Unifies alert_id and alert_key

This commit is contained in:
Simone Mainardi 2020-04-15 12:54:14 +02:00
parent 64ceaa5b89
commit 1eb02b2c2b
9 changed files with 39 additions and 39 deletions

View file

@ -28,15 +28,15 @@ print [[
<div class="row">
<div class="col col-md-4 offset-1">
<table class="table table-bordered table-sm">
<tr><th class='text-center'>]] print(i18n("plugins_overview.alert_id")) print[[</th><th>]] print(i18n("plugins_overview.alert_key")) print[[</th></tr>]]
<tr><th class='text-center'>]] print(i18n("plugins_overview.alert_key")) print[[</th><th>]] print(i18n("plugins_overview.alert_key")) print[[</th></tr>]]
local id_start = 0
local id_end = 63
for alert_id=id_start,id_end do
local alert_key = alert_consts.getAlertType(alert_id) or "-"
for alert_key=id_start,id_end do
local alert_key = alert_consts.getAlertType(alert_key) or "-"
print[[<tr><td class='text-center'>]] print(string.format("%s", alert_id)) print[[</td>]]
print[[<tr><td class='text-center'>]] print(string.format("%s", alert_key)) print[[</td>]]
print[[<td>]] print(alert_key) print[[</td></tr>]]
end

View file

@ -79,7 +79,7 @@ for entity_key, disabled_entities in pairsByKeys(entitites) do
for entity_value, disabled_alerts in pairsByKeys(disabled_entities) do
for _, alert in pairs(alert_consts.alert_types) do
if((alert.alert_id > 0) and ntop.bitmapIsSet(disabled_alerts, alert.alert_id)) then
if((alert.alert_key > 0) and ntop.bitmapIsSet(disabled_alerts, alert.alert_key)) then
totalRows = totalRows + 1
local idx = totalRows
@ -91,7 +91,7 @@ for entity_key, disabled_entities in pairsByKeys(entitites) do
}
if sortColumn == "column_type" then
sort_to_key[idx] = alert.alert_id
sort_to_key[idx] = alert.alert_key
else -- default
sort_to_key[idx] = data[idx].entity_formatted
end
@ -115,10 +115,10 @@ for key in pairsByValues(sort_to_key, sOrder) do
res[#res + 1] = {
column_entity_formatted = firstToUpper(alert_consts.formatAlertEntity(ifid, alert_consts.alertEntityRaw(item.entity_id), item.entity_value)),
column_type = alert_consts.alertTypeLabel(item.alert.alert_id),
column_type = alert_consts.alertTypeLabel(item.alert.alert_key),
column_entity_id = item.entity_id,
column_entity_val = item.entity_value,
column_type_id = item.alert.alert_id,
column_type_id = item.alert.alert_key,
}
end

View file

@ -242,7 +242,7 @@ function alert_consts.loadDefinition(def_script, mod_fname, script_path)
return(false)
end
def_script.alert_id = def_id
def_script.alert_key = def_id
alert_consts.alert_types[mod_fname] = def_script
alerts_by_id[def_id] = mod_fname
@ -253,10 +253,10 @@ end
-- ##############################################
function alert_consts.alertTypeLabel(v, nohtml)
local alert_id = alert_consts.alertTypeRaw(v)
local alert_key = alert_consts.alertTypeRaw(v)
if(alert_id) then
local type_info = alert_consts.alert_types[alert_id]
if(alert_key) then
local type_info = alert_consts.alert_types[alert_key]
local title = i18n(type_info.i18n_title) or type_info.i18n_title
if(nohtml) then
@ -276,13 +276,13 @@ function alert_consts.alertType(v)
tprint(debug.traceback())
end
return(alert_consts.alert_types[v].alert_id)
return(alert_consts.alert_types[v].alert_key)
end
-- ##############################################
function alert_consts.getAlertType(alert_id)
return(alerts_by_id[tonumber(alert_id)])
function alert_consts.getAlertType(alert_key)
return(alerts_by_id[tonumber(alert_key)])
end
-- ##############################################
@ -421,7 +421,7 @@ function alert_consts.alertTypeRaw(type_id)
type_id = tonumber(type_id)
for key, type_info in pairs(alert_consts.alert_types) do
if(type_info.alert_id == type_id) then
if(type_info.alert_key == type_id) then
return(key)
end
end

View file

@ -43,10 +43,10 @@ end
-- ##############################################
local function alertTypeDescription(v)
local alert_id = alert_consts.alertTypeRaw(v)
local alert_key = alert_consts.alertTypeRaw(v)
if(alert_id) then
return(alert_consts.alert_types[alert_id].i18n_description)
if(alert_key) then
return(alert_consts.alert_types[alert_key].i18n_description)
end
end
@ -1164,9 +1164,9 @@ function getCurrentStatus() {
return val;
}
function deleteAlertById(alert_id) {
function deleteAlertById(alert_key) {
var params = {};
params.id_to_delete = alert_id;
params.id_to_delete = alert_key;
params.status = getCurrentStatus();
params.csrf = "]] print(ntop.getRandomCSRFValue()) print[[";
@ -1462,7 +1462,7 @@ function toggleAlert(disable) {
datatableForEachRow("#]] print(t["div-id"]) print[[", function(row_id) {
var alert_key = $("td:nth(8)", this).html().split("|");
var alert_id = alert_key[0];
var alert_key = alert_key[0];
var data = table_data[row_id];
var explorer_url = data["column_explorer"];
@ -1482,7 +1482,7 @@ function toggleAlert(disable) {
datatableAddActionButtonCallback.bind(this)(10, "alert_to_release = "+ row_id +"; $('#release_single_alert').modal('show');", "]] print(i18n("show_alerts.release_alert_action")) print[[");
if(]] print(ternary(t["status"] ~= "engaged", "true", "false")) print[[) {
datatableAddDeleteButtonCallback.bind(this)(10, "delete_alert_id ='" + alert_id + "'; $('#delete_alert_dialog').modal('show');", "]] print(i18n('delete')) print[[");
datatableAddDeleteButtonCallback.bind(this)(10, "delete_alert_id ='" + alert_key + "'; $('#delete_alert_dialog').modal('show');", "]] print(i18n('delete')) print[[");
}
$("form", this).submit(function() {

View file

@ -48,7 +48,7 @@ local function get_alert_triggered_key(type_info)
tprint(debug.traceback())
end
return(string.format("%d@%s", type_info.alert_type.alert_id, type_info.alert_subtype or ""))
return(string.format("%d@%s", type_info.alert_type.alert_key, type_info.alert_subtype or ""))
end
-- ##############################################
@ -139,7 +139,7 @@ function alerts_api.store(entity_info, type_info, when)
return(false)
end
if alerts_api.isEntityAlertDisabled(ifid, entity_info.alert_entity.entity_id, entity_info.alert_entity_val, type_info.alert_type.alert_id) then
if alerts_api.isEntityAlertDisabled(ifid, entity_info.alert_entity.entity_id, entity_info.alert_entity_val, type_info.alert_type.alert_key) then
return(false)
end
@ -150,7 +150,7 @@ function alerts_api.store(entity_info, type_info, when)
local alert_to_store = {
ifid = ifid,
action = "store",
alert_type = type_info.alert_type.alert_id,
alert_type = type_info.alert_type.alert_key,
alert_subtype = subtype,
alert_granularity = granularity_sec,
alert_entity = entity_info.alert_entity.entity_id,
@ -163,7 +163,7 @@ function alerts_api.store(entity_info, type_info, when)
if(entity_info.alert_entity.entity_id == alert_consts.alertEntity("host")) then
-- NOTE: for engaged alerts this operation is performed during trigger in C
interface.incTotalHostAlerts(entity_info.alert_entity_val, type_info.alert_type.alert_id)
interface.incTotalHostAlerts(entity_info.alert_entity_val, type_info.alert_type.alert_key)
end
local alert_json = json.encode(alert_to_store)
@ -229,7 +229,7 @@ end
--! @note false is also returned if an existing alert is found and refreshed
function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
local ifid = interface.getId()
local is_disabled = alerts_api.isEntityAlertDisabled(ifid, entity_info.alert_entity.entity_id, entity_info.alert_entity_val, type_info.alert_type.alert_id)
local is_disabled = alerts_api.isEntityAlertDisabled(ifid, entity_info.alert_entity.entity_id, entity_info.alert_entity_val, type_info.alert_type.alert_key)
-- Check if the alerts has been disabled and, in case return, before checking already_triggered,
-- so that the alert will be automatically released during the next check.
@ -252,7 +252,7 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
local subtype = type_info.alert_subtype or ""
if(cur_alerts and already_triggered(cur_alerts, type_info.alert_severity.severity_id,
type_info.alert_type.alert_id, granularity_sec, subtype) == true) then
type_info.alert_type.alert_key, granularity_sec, subtype) == true) then
return(true)
end
@ -267,7 +267,7 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
local params = {
alert_key_name, granularity_id,
type_info.alert_severity.severity_id, type_info.alert_type.alert_id,
type_info.alert_severity.severity_id, type_info.alert_type.alert_key,
subtype, alert_json,
}
@ -318,7 +318,7 @@ function alerts_api.release(entity_info, type_info, when, cur_alerts)
local subtype = type_info.alert_subtype or ""
if(cur_alerts and (not already_triggered(cur_alerts, type_info.alert_severity.severity_id,
type_info.alert_type.alert_id, granularity_sec, subtype))) then
type_info.alert_type.alert_key, granularity_sec, subtype))) then
return(true)
end
@ -333,7 +333,7 @@ function alerts_api.release(entity_info, type_info, when, cur_alerts)
end
if(type_info.alert_severity == nil) then
alertErrorTraceback(string.format("Missing alert_severity [type=%s]", type_info.alert_type and type_info.alert_type.alert_id or ""))
alertErrorTraceback(string.format("Missing alert_severity [type=%s]", type_info.alert_type and type_info.alert_type.alert_key or ""))
return(false)
end
@ -1025,7 +1025,7 @@ end
local cache_disabled_by_entity_type = {}
-- @brief Check if the alert_type is disabled for the given entity
function alerts_api.isEntityAlertDisabled(ifid, entity_type, entity_val, alert_id)
function alerts_api.isEntityAlertDisabled(ifid, entity_type, entity_val, alert_key)
local entities_disabled = cache_disabled_by_entity_type[entity_type]
if(entities_disabled == nil) then
@ -1036,7 +1036,7 @@ function alerts_api.isEntityAlertDisabled(ifid, entity_type, entity_val, alert_i
local bitmap = entities_disabled[entity_val]
if((bitmap ~= nil) and ntop.bitmapIsSet(bitmap, alert_id)) then
if((bitmap ~= nil) and ntop.bitmapIsSet(bitmap, alert_key)) then
return(true)
end