Add recipient_id in redis key, fix redis value check and add TODO comment. (#6240)

This commit is contained in:
Nicolo Maio 2023-07-21 10:58:22 +00:00
parent 9c3acf2f06
commit c1128f6dea
9 changed files with 14 additions and 13 deletions

View file

@ -915,7 +915,7 @@ end
-- ##############################################
function alert_utils.filter_notification(notification)
function alert_utils.filter_notification(notification, recipient_id)
local alert_info = json.decode(notification.alert)
local alert_key = alert_info.alert_id
local entity_id = alert_info.entity_id
@ -924,12 +924,12 @@ function alert_utils.filter_notification(notification)
local alert_id = alert_consts.getAlertType(alert_key, entity_id)
return alert_utils.check_alert_policy(entity_id, entity_val, alert_id, alert_info)
return alert_utils.check_alert_policy(entity_id, entity_val, alert_id, alert_info, recipient_id)
end
-- ##############################################
function alert_utils.check_alert_policy(entity_id, entity_val, alert_id, alert_info)
function alert_utils.check_alert_policy(entity_id, entity_val, alert_id, alert_info, recipient_id)
local alert_key = ""
local alert_key_fields = {}
if alert_consts.alert_types[alert_id].alert_retention_policy_key then
@ -952,10 +952,11 @@ function alert_utils.check_alert_policy(entity_id, entity_val, alert_id, alert_i
return true
end
local redis_key = string.format("ntopng.cache.alert.retention.%s.%s%s",entity_id, alert_id, alert_key)
local redis_res = ntop.getCache(redis_key) == ""
local redis_key = string.format("ntopng.cache.alert.retention.%s.%s.%s%s",recipient_id, entity_id, alert_id, alert_key)
local redis_res = isEmptyString(ntop.getCache(redis_key))
if redis_res then
-- TODO: 3600 must be update with a user preference
ntop.setCache(redis_key,"1", 3600)
end
return redis_res

View file

@ -138,7 +138,7 @@ function discord.dequeueRecipientAlerts(recipient, budget)
for i=1, max_alerts_per_request do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
end

View file

@ -144,7 +144,7 @@ function email.dequeueRecipientAlerts(recipient, budget)
for i = 1, MAX_ALERTS_PER_EMAIL do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
end
else

View file

@ -124,7 +124,7 @@ function mattermost.dequeueRecipientAlerts(recipient, budget)
for i=1, max_alerts_per_request do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
end

View file

@ -143,7 +143,7 @@ function shell.dequeueRecipientAlerts(recipient, budget)
for i = 1, MAX_ALERTS_PER_REQUEST do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
end

View file

@ -87,7 +87,7 @@ function slack.dequeueRecipientAlerts(recipient, budget)
for i = 1, budget do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
end

View file

@ -180,7 +180,7 @@ function syslog.dequeueRecipientAlerts(recipient, budget)
for i = 1, budget do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification
end

View file

@ -138,7 +138,7 @@ function telegram.dequeueRecipientAlerts(recipient, budget)
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
else
break

View file

@ -107,7 +107,7 @@ function webhook.dequeueRecipientAlerts(recipient, budget)
for i = 1, MAX_ALERTS_PER_REQUEST do
local notification = ntop.recipient_dequeue(recipient.recipient_id)
if notification then
if alert_utils.filter_notification(notification) then
if alert_utils.filter_notification(notification, recipient.recipient_id) then
notifications[#notifications + 1] = notification.alert
end