Implements internet resources misuse script with exception list

Implements #4984
This commit is contained in:
Matteo Biscosi 2021-02-04 15:00:17 +01:00
parent 31a52787ee
commit d3853aaf90
5 changed files with 89 additions and 43 deletions

View file

@ -17,8 +17,8 @@ local script = {
is_alert = true,
default_value = {
operator = "gt",
threshold = 5,
items = {},
default_contacts = 5,
severity = alert_severities.error,
},
@ -28,11 +28,11 @@ local script = {
gui = {
i18n_title = "alerts_thresholds_config.dns_contacts_title",
i18n_description = "alerts_thresholds_config.dns_contacts_description",
i18n_field_unit = user_scripts.field_units.contacts,
input_builder = "threshold_cross",
field_min = 1,
field_operator = "gt";
input_builder = "items_list",
item_list_type = "ip_address",
input_title = i18n("input_item_list.dns_input_list_title"),
input_description = i18n("input_item_list.dns_input_list_description"),
}
}
@ -40,21 +40,33 @@ local script = {
function script.hooks.min(params)
local value = host.getContactsStats() or nil
local host_ip = params.entity_info.ip or ""
local ok = 0
if not value then
return
end
if value.server_contacts then
value = value.server_contacts.dns or 0
else
value = 0
for _, dns_ip in pairs(params.user_script_config) do
if host_ip == dns_ip then
ok = 1
break
end
end
local value = alerts_api.host_delta_val(script.key, params.granularity, value)
if ok == 0 then
if value.server_contacts then
value = value.server_contacts.dns or 0
else
value = 0
end
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
local value = alerts_api.host_delta_val(script.key, params.granularity, value)
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
end
end
-- #################################################################

View file

@ -17,8 +17,8 @@ local script = {
is_alert = true,
default_value = {
operator = "gt",
threshold = 5,
items = {},
default_contacts = 5,
severity = alert_severities.error,
},
@ -28,11 +28,11 @@ local script = {
gui = {
i18n_title = "alerts_thresholds_config.ntp_contacts_title",
i18n_description = "alerts_thresholds_config.ntp_contacts_description",
i18n_field_unit = user_scripts.field_units.contacts,
input_builder = "threshold_cross",
field_min = 1,
field_operator = "gt";
input_builder = "items_list",
item_list_type = "ip_address",
input_title = i18n("input_item_list.ntp_input_list_title"),
input_description = i18n("input_item_list.ntp_input_list_description"),
}
}
@ -40,21 +40,33 @@ local script = {
function script.hooks.min(params)
local value = host.getContactsStats() or nil
local host_ip = params.entity_info.ip or ""
local ok = 0
if not value then
return
end
if value.server_contacts then
value = value.server_contacts.ntp or 0
else
value = 0
for _, ntp_ip in pairs(params.user_script_config) do
if host_ip == ntp_ip then
ok = 1
break
end
end
local value = alerts_api.host_delta_val(script.key, params.granularity, value)
if ok == 0 then
if value.server_contacts then
value = value.server_contacts.ntp or 0
else
value = 0
end
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
local value = alerts_api.host_delta_val(script.key, params.granularity, value)
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
end
end
-- #################################################################

View file

@ -17,8 +17,8 @@ local script = {
is_alert = true,
default_value = {
operator = "gt",
threshold = 5,
items = {},
default_contacts = 5,
severity = alert_severities.error,
},
@ -28,11 +28,11 @@ local script = {
gui = {
i18n_title = "alerts_thresholds_config.smtp_contacts_title",
i18n_description = "alerts_thresholds_config.smtp_contacts_description",
i18n_field_unit = user_scripts.field_units.contacts,
input_builder = "threshold_cross",
field_min = 1,
field_operator = "gt";
input_builder = "items_list",
item_list_type = "ip_address",
input_title = i18n("input_item_list.smtp_input_list_title"),
input_description = i18n("input_item_list.smtp_input_list_description"),
}
}
@ -40,21 +40,34 @@ local script = {
function script.hooks.min(params)
local value = host.getContactsStats() or nil
local host_ip = params.entity_info.ip or ""
local ok = 0
if not value then
return
end
if value.server_contacts then
value = value.server_contacts.smtp or 0
else
value = 0
for _, smtp_ip in pairs(params.user_script_config) do
if host_ip == smtp_ip then
ok = 1
break
end
end
local value = alerts_api.host_delta_val(script.key, params.granularity, value)
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
if ok == 0 then
if value.server_contacts then
value = value.server_contacts.smtp or 0
else
value = 0
end
local value = alerts_api.host_delta_val(script.key, params.granularity, value)
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
end
end
-- #################################################################