Fixes hourly ASN retention not correctly used

This commit is contained in:
Matteo Biscosi 2025-11-12 11:08:20 +01:00
parent bd41a01954
commit e75451e823
3 changed files with 43 additions and 33 deletions

View file

@ -1,67 +1,78 @@
--
-- (C) 2014-24 - ntop.org
--
local DEFAULT_DATA_RETENTION_DAYS = 30
local DEFAULT_AGGREGATED_ASN_DATA_RETENTION_DAYS = 30
local DEFAULT_AGGREGATED_ASN_DATA_RETENTION_DAYS = 60
local DEFAULT_AGGREGATED_FLOWS_DATA_RETENTION_DAYS = 60
local DEFAULT_DATA_RETENTION_DAYS_KEY = "ntopng.prefs.data_retention_days"
local FLOWS_AND_ALERTS_DATA_RETENTION_DAYS_KEY = "ntopng.prefs.flows_and_alerts_data_retention_days"
local AGGREGATED_FLOWS_DATA_RETENTION_DAYS_KEY = "ntopng.prefs.aggregated_flows_data_retention_days"
local AGGREGATED_ASN_DATA_RETENTION_DAYS_KEY = "ntopng.prefs.aggregated_asn_data_retention_days"
local TS_AND_STATS_DATA_RETENTION_DAYS_KEY = "ntopng.prefs.ts_and_stats_data_retention_days"
local FLOWS_AND_ALERTS_DATA_RETENTION_DAYS_KEY =
"ntopng.prefs.flows_and_alerts_data_retention_days"
local AGGREGATED_FLOWS_DATA_RETENTION_DAYS_KEY =
"ntopng.prefs.aggregated_flows_data_retention_days"
local AGGREGATED_ASN_DATA_RETENTION_DAYS_KEY =
"ntopng.prefs.aggregated_asn_data_retention_days"
local TS_AND_STATS_DATA_RETENTION_DAYS_KEY =
"ntopng.prefs.ts_and_stats_data_retention_days"
local data_retention_utils = {}
-- ########################################################
function data_retention_utils.getDefaultRetention()
return DEFAULT_DATA_RETENTION_DAYS
return DEFAULT_DATA_RETENTION_DAYS
end
-- ########################################################
function data_retention_utils.getAggregatedFlowsDataRetention()
return DEFAULT_AGGREGATED_FLOWS_DATA_RETENTION_DAYS
return DEFAULT_AGGREGATED_FLOWS_DATA_RETENTION_DAYS
end
-- ########################################################
function data_retention_utils.getAggregatedAsnDataRetention()
return DEFAULT_AGGREGATED_ASN_DATA_RETENTION_DAYS
return DEFAULT_AGGREGATED_ASN_DATA_RETENTION_DAYS
end
-- ########################################################
function data_retention_utils.getFlowsAndAlertsDataRetentionDays()
local data_retention = ntop.getCache(FLOWS_AND_ALERTS_DATA_RETENTION_DAYS_KEY) or ntop.getCache(DEFAULT_DATA_RETENTION_DAYS_KEY)
local data_retention = ntop.getCache(
FLOWS_AND_ALERTS_DATA_RETENTION_DAYS_KEY) or
ntop.getCache(DEFAULT_DATA_RETENTION_DAYS_KEY)
return tonumber(data_retention) or data_retention_utils.getDefaultRetention()
return tonumber(data_retention) or
data_retention_utils.getDefaultRetention()
end
-- ########################################################
function data_retention_utils.getAggregatedFlowsRetentionDays()
local data_retention = ntop.getCache(AGGREGATED_FLOWS_DATA_RETENTION_DAYS_KEY)
-- aggregated data is at least one day more that non-aggregated data
return tonumber(data_retention) or (data_retention_utils.getDefaultRetention() + 1)
local data_retention = ntop.getCache(
AGGREGATED_FLOWS_DATA_RETENTION_DAYS_KEY)
-- aggregated data is at least one day more that non-aggregated data
return tonumber(data_retention) or
(data_retention_utils.getAggregatedFlowsDataRetention() + 1)
end
-- ########################################################
function data_retention_utils.getAggregatedAsnRetentionDays()
local data_retention = ntop.getCache(AGGREGATED_ASN_DATA_RETENTION_DAYS_KEY)
tprint(data_retention)
-- aggregated data is at least one day more that non-aggregated data
return tonumber(data_retention) or (data_retention_utils.getDefaultRetention() + 1)
local data_retention = ntop.getCache(AGGREGATED_ASN_DATA_RETENTION_DAYS_KEY)
-- aggregated data is at least one day more that non-aggregated data
return tonumber(data_retention) or
(data_retention_utils.getAggregatedAsnDataRetention() + 1)
end
-- ########################################################
function data_retention_utils.getTSAndStatsDataRetentionDays()
local data_retention = ntop.getCache(TS_AND_STATS_DATA_RETENTION_DAYS_KEY) or ntop.getCache(DEFAULT_DATA_RETENTION_DAYS_KEY)
local data_retention =
ntop.getCache(TS_AND_STATS_DATA_RETENTION_DAYS_KEY) or
ntop.getCache(DEFAULT_DATA_RETENTION_DAYS_KEY)
return tonumber(data_retention) or data_retention_utils.getDefaultRetention()
return tonumber(data_retention) or
data_retention_utils.getDefaultRetention()
end
-- ########################################################