[VA] Add charts page (#7783)

This commit is contained in:
Nicolo Maio 2023-08-31 18:27:31 +02:00
parent 4f3352b7e9
commit ad06c59a32
7 changed files with 81 additions and 39 deletions

View file

@ -39,6 +39,7 @@ package.path = dirs.installdir .. "/scripts/lua/modules/vulnerability_scan/?.lua
require "lua_utils" -- used by tprint (debug)
local host_to_scan_key = "ntopng.prefs.host_to_scan"
local host_scannned_count_key = "ntopng.prefs.host_to_scan.count_scanned"
local host_scan_queue_key = "ntopng.vs_scan_queue"
local scanned_hosts_changes_key = "ntopng.alerts.scanned_hosts_changes"
@ -404,10 +405,45 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
result = 2 --aleready_present
end
local counts = vs_utils.update_ts_counters()
--ntop.setCache(host_to_scan_key, json.encode(saved_hosts))
return result
end
function vs_utils.update_ts_counters()
local hosts_details = vs_utils.retrieve_hosts_to_scan()
local count_cve = 0
local hosts_scanned
local open_ports_count = 0
local hosts_count = 0
for _,item in ipairs(hosts_details) do
hosts_count = hosts_count + 1
open_ports_count = open_ports_count + item.num_open_ports
count_cve = count_cve + item.num_vulnerabilities_found
end
local count = ntop.getCache(host_scannned_count_key)
if (not isEmptyString(count)) then
hosts_scanned = tonumber(count)
end
local response = {
cve_count = count_cve,
scanned_hosts = hosts_scanned,
open_ports = open_ports_count,
hosts_count = hosts_count
}
return response
end
-- **********************************************************
-- Function to retrieve hosts list to scan
@ -590,6 +626,8 @@ function vs_utils.scan_host(scan_type, host, ports, scan_id)
if scan_result then
scan_result = vs_utils.scan_status.ok
ntop.incrCache(host_scannned_count_key)
end
if debug_print then
traceError(TRACE_NORMAL,TRACE_CONSOLE,"End scan Host ".. host .. ", result: " .. result .. "\n")