[VS] Add start date and end date of scan all or periodic scan for report. (#7951)

This commit is contained in:
Nicolo Maio 2023-10-26 17:19:50 +02:00
parent db49dede5a
commit e5bc5293fe
3 changed files with 51 additions and 15 deletions

View file

@ -47,6 +47,9 @@ local host_scan_queue_key = "ntopng.vs_scan_queue"
local scanned_hosts_changes_key = "ntopng.alerts.scanned_hosts_changes"
local host_in_scanning_hash_key = "ntopng.prefs.host_to_scan.in_scanning"
-- redis key for last scan report dates
local hosts_scan_last_report_dates = "ntopng.prefs.host_to_scan.report_dates"
-- redis keys for periodic scan info
local host_periodic_scan_info = "ntopng.prefs.host_to_scan.periodicity_scan.info"
@ -992,19 +995,28 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
local title = i18n("hosts_stats.page_scan_hosts.email.vulnerability_scan_report_title",{host = getHttpHost()})
local duration = 0
local duration_label = ''
local begin_epoch_t = tonumber(info_json.begin_epoch)
local end_epoch_t = os.time()
if (info_json.begin_epoch ~= nil) then
local begin_epoch_t = tonumber(info_json.begin_epoch)
duration = os.time() - begin_epoch_t
duration = end_epoch_t - begin_epoch_t
duration_label = secondsToTime(duration)
end
local start_date_formatted = formatEpoch(begin_epoch_t)
local end_date_formatted = formatEpoch(end_epoch_t)
ntop.setCache(hosts_scan_last_report_dates, json.encode({start_date = start_date_formatted, end_date = end_date_formatted}))
if (periodicity and periodicity == "1day") then
notification_message = i18n("hosts_stats.page_scan_hosts.email.periodicity_scan_1_day_ended", {
cves = format_num_for_email(cve_num,0),
udp_ports = format_num_for_email(udp_ports,1),
tcp_ports = format_num_for_email(tcp_ports,2),
url = getHttpHost() .. ntop.getHttpPrefix() .. "/lua/pro/reportng.lua?report_template=vs_result",
duration = duration_label
duration = duration_label,
start_date = start_date_formatted,
end_date = end_date_formatted
})
elseif (periodicity and periodicity == "1week") then
notification_message = i18n("hosts_stats.page_scan_hosts.email.periodicity_scan_1_week_ended", {
@ -1012,7 +1024,9 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
udp_ports = format_num_for_email(udp_ports,1),
tcp_ports = format_num_for_email(tcp_ports,2),
url = getHttpHost() .. ntop.getHttpPrefix() .. "/lua/pro/reportng.lua?report_template=vs_result",
duration = duration_label
duration = duration_label,
start_date = start_date_formatted,
end_date = end_date_formatted
})
else
-- scan all case
@ -1021,12 +1035,12 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
udp_ports = format_num_for_email(udp_ports,1),
tcp_ports = format_num_for_email(tcp_ports,2),
url = getHttpHost() .. ntop.getHttpPrefix() .. "/lua/pro/reportng.lua?report_template=vs_result",
duration = duration_label
duration = duration_label,
start_date = start_date_formatted,
end_date = end_date_formatted
})
end
recipients.sendMessageByNotificationType({periodicity = periodicity, success=true, message = notification_message, title = title}, "vulnerability_scans")
ntop.setCache(info_redis_key,json.encode({
@ -1035,11 +1049,18 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
tcp_ports = 0,
begin_epoch = 0
}))
end
-- **********************************************************
-- Function to retrieve dates of scan all or periodic scan
function vs_utils.get_scan_all_dates()
return ntop.getCache(hosts_scan_last_report_dates)
end
-- **********************************************************
-- Function to verify if periodic scan is ended