Add AS alert entity. Fix AS threshold crossed.

This commit is contained in:
Alfredo Cardigliano 2025-08-25 14:45:22 +02:00
parent fa35d9183a
commit ba382f7316
13 changed files with 174 additions and 17 deletions

View file

@ -82,6 +82,14 @@ local pages = {{
page = "network"
}),
hidden = is_system_interface,
}, {
active = page == "as",
page_name = "as",
label = i18n(alert_entities.as.i18n_label),
url = getPageUrl(base_url, {
page = "as"
}),
hidden = is_system_interface,
}, {
active = page == "snmp_device",
page_name = "snmp_device",

View file

@ -22,8 +22,7 @@ alert_asn_rule_threshold_crossed.meta = {
i18n_title = "show_alerts.host_pool_rule_threshold_cross",
icon = "fas fa-fw fa-exclamation-triangle",
entities = {
alert_entities.system,
alert_entities.interface,
alert_entities.as,
},
}

View file

@ -47,13 +47,17 @@ local alert_entities = {
entity_id = 9,
i18n_label = "alert_entities.system",
alert_store_name = "system",
}, domain = {
entity_id = 12,
i18n_label = "alert_entities.domain",
}, mitre = {
entity_id = 13,
i18n_label = "alert_entities.mitre",
alert_store_name = "mitre",
}, as = {
entity_id = 10,
i18n_label = "alert_entities.as",
alert_store_name = "as",
--}, domain = {
-- entity_id = 12,
-- i18n_label = "alert_entities.domain",
--}, mitre = {
-- entity_id = 13,
-- i18n_label = "alert_entities.mitre",
-- alert_store_name = "mitre",
}, other = {
entity_id = 15,
i18n_label = "alert_entities.other",

View file

@ -693,7 +693,14 @@ function alert_store:eval_alert_cond(alert, cond)
end
end
return tag_utils.eval_op(alert[cond.field], cond.op, cond.value)
local field_value = alert[cond.field]
if field_value == nil then
local alert_json = json.decode(alert["json"]) or {}
field_value = alert_json[cond.field]
end
return tag_utils.eval_op(field_value, cond.op, cond.value)
end
-- ##############################################
@ -851,6 +858,7 @@ end
-- @param value_type The value type (e.g. 'number')
-- @return True if set is successful, false otherwise
function alert_store:add_filter_condition_list(field, values, values_type, value_to_use)
if not values or isEmptyString(values) then
return false
end

View file

@ -307,6 +307,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 json = require("dkjson")
if (not areAlertsEnabled()) then
return (false)
end

View file

@ -2045,7 +2045,7 @@ local known_parameters = {
["out_of_order"] = validateListOfTypeInline(validateFilters(validateNumber)),
["lost"] = validateListOfTypeInline(validateFilters(validateNumber)),
["asn"] = validateNumber, -- An ASN number
["asn"] = validateFilters(validateNumber), -- An ASN number
["country_id"] = validateNumber, -- A Country Code
["module"] = validateTopModule, -- A top script module
["step"] = validateNumber, -- A step value

View file

@ -589,7 +589,7 @@ page_utils.menu_entries = {
alert_exclusions_domains = {
key = "alert_exclusions",
subkey = "domains",
i18n_title = alert_entities.domain.i18n_label,
i18n_title = "domain",
section = "alert_exclusions",
help_link = "https://www.ntop.org/guides/ntopng/user_interface/shared/alerts/others/available_alerts.html"
},

View file

@ -1064,6 +1064,14 @@ function tag_utils.eval_op(v1, op, v2)
end
end
-- Convert numbers
if type(v1) == 'number' and type(v2) ~= 'number' then
v2 = tonumber(v2)
end
if type(v2) == 'number' and type(v1) ~= 'number' then
v1 = tonumber(v1)
end
if not v1 or not v2 then
return default_verdict
end