[VS] Add duration in email and add missing href. (#7941) (#7937)

This commit is contained in:
Nicolo Maio 2023-10-24 10:57:37 +02:00
parent 78e6556990
commit 3072fa2e52
6 changed files with 67 additions and 29 deletions

View file

@ -49,17 +49,10 @@ local host_in_scanning_hash_key = "ntopng.prefs.host_to_scan.in_scanni
-- redis keys for periodic scan info
local host_periodic_scan_info = "ntopng.prefs.host_to_scan.periodicity_scan.info"
local host_periodic_scan_cve_num_key = "ntopng.prefs.host_to_scan.periodicity_scan.info.cve_num"
local host_periodic_scan_udp_ports_key = "ntopng.prefs.host_to_scan.periodicity_scan.info.udp_ports"
local host_periodic_scan_tcp_ports_key = "ntopng.prefs.host_to_scan.periodicity_scan.info.tcp_ports"
-- redis keys for scan all info
local host_scan_all_info = "ntopng.prefs.host_to_scan.scan_all.info"
local host_scan_all_cve_num_key = "ntopng.prefs.host_to_scan.scan_all.info.cve_num"
local host_scan_all_udp_ports_key = "ntopng.prefs.host_to_scan.scan_all.info.udp_ports"
local host_scan_all_tcp_ports_key = "ntopng.prefs.host_to_scan.scan_all.info.tcp_ports"
local json = require("dkjson")
local format_utils = require("format_utils")
local recipients = require("recipients")
@ -693,6 +686,11 @@ local function update_periodicity_or_all_scan_info(is_periodic, new_item)
end
end
if (info_json ~= {} and info_json.begin_epoch == nil) then
info_json.begin_epoch = os.time()
end
ntop.setCache(redis_info_key, json.encode(info_json))
end
@ -997,22 +995,29 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
local tcp_ports = tonumber(info_json.tcp_ports) or 0
local title = i18n("hosts_stats.page_scan_hosts.email.vulnerability_scan_report_title",{host = getHttpHost()})
local duration = 0
local duration_label = ''
if (info_json.begin_epoch ~= nil) then
local begin_epoch_t = tonumber(info_json.begin_epoch)
duration = os.time() - begin_epoch_t
duration_label = secondsToTime(duration)
end
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"
url = getHttpHost() .. ntop.getHttpPrefix() .. "/lua/pro/reportng.lua?report_template=vs_result",
duration = duration_label
})
elseif (periodicity and periodicity == "1week") then
notification_message = i18n("hosts_stats.page_scan_hosts.email.periodicity_scan_1_week_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"
url = getHttpHost() .. ntop.getHttpPrefix() .. "/lua/pro/reportng.lua?report_template=vs_result",
duration = duration_label
})
else
-- scan all case
@ -1020,7 +1025,8 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
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"
url = getHttpHost() .. ntop.getHttpPrefix() .. "/lua/pro/reportng.lua?report_template=vs_result",
duration = duration_label
})
end
@ -1031,7 +1037,8 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
ntop.setCache(info_redis_key,json.encode({
cves = 0,
udp_ports = 0,
tcp_ports = 0
tcp_ports = 0,
begin_epoch = 0
}))
@ -1446,7 +1453,8 @@ function vs_utils.schedule_all_hosts_scan()
ntop.setCache(host_scan_all_info,json.encode({
cves = 0,
udp_ports = 0,
tcp_ports = 0
tcp_ports = 0,
begin_epoch = os.time()
}))
return true
@ -1483,7 +1491,8 @@ function vs_utils.schedule_periodic_scan(periodicity)
ntop.setCache(host_periodic_scan_info , json.encode({
cves = 0,
udp_ports = 0,
tcp_ports = 0
tcp_ports = 0,
begin_epoch = os.time()
}))
end