Update in progress status handling. (#7782)

This commit is contained in:
Nicolo Maio 2023-08-24 15:27:11 +02:00
parent bf3c94e254
commit d51acbd325
8 changed files with 103 additions and 49 deletions

View file

@ -56,6 +56,15 @@ end
-- **********************************************************
vs_utils.scan_status = {
error = 0,
ok = 1,
in_progress = 2,
not_scanned = 3
}
-- **********************************************************
function vs_utils.is_nmap_installed()
local path = {
"/usr/bin/nmap",
@ -259,7 +268,7 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
-- In case the alert needs to be triggered, save the differences in order to lessen
-- the info dropped on redis
-- if is_ok_last_scan is nil then no prior scan was done, so do not trigger the alert
if trigger_alert and old_data and old_data.is_ok_last_scan then
if trigger_alert and old_data and (old_data.is_ok_last_scan == vs_utils.scan_status.ok) then
local host_info_to_cache = check_differences(host, host_name,
scan_type,
{
@ -286,6 +295,9 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
epoch_id = id
end
if (isEmptyString(is_ok_last_scan)) then
is_ok_last_scan = vs_utils.scan_status.not_scanned
end
local new_item = {
host = host,
host_name = host_name,
@ -294,7 +306,8 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
num_open_ports = num_open_ports,
num_vulnerabilities_found = num_vulnerabilities_found,
cve = cve,
id = epoch_id
id = epoch_id,
is_ok_last_scan = is_ok_last_scan
}
if last_scan_time or last_duration then
@ -311,9 +324,11 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
duration = last_duration
}
if is_ok_last_scan then
new_item.is_ok_last_scan = is_ok_last_scan
if is_ok_last_scan == vs_utils.scan_status.ok then
new_item.is_ok_last_scan = vs_utils.scan_status.ok
end
end
if not isEmptyString(scan_frequency) then
@ -374,7 +389,8 @@ end
function vs_utils.check_in_progress_status()
local hash_keys = ntop.getHashKeysCache(host_to_scan_key)
local total_in_progress = 0
local total = 0
if hash_keys then
for k in pairs(hash_keys) do
local hash_value_string = ntop.getHashCache(host_to_scan_key, k)
@ -382,14 +398,15 @@ function vs_utils.check_in_progress_status()
if (not isEmptyString(hash_value_string)) then
local hash_value = json.decode(hash_value_string)
-- Check IN PROGRESS --> FIX ME with enums
if hash_value and hash_value.is_ok_last_scan == 4 then
return true
if hash_value and hash_value.is_ok_last_scan == vs_utils.scan_status.in_progress then
total_in_progress = total_in_progress + 1
end
total = total + 1
end
end
end
return false
return total, total_in_progress
end
-- **********************************************************
@ -526,6 +543,9 @@ function vs_utils.scan_host(scan_type, host, ports, scan_id)
local scan_module = vs_utils.load_module(scan_type)
local result,duration,scan_result,num_open_ports,num_vulnerabilities_found, cve = scan_module:scan_host(host, ports)
if scan_result then
scan_result = vs_utils.scan_status.ok
end
if debug_print then
traceError(TRACE_NORMAL,TRACE_CONSOLE,"End scan Host ".. host .. ", result: " .. result .. "\n")
end
@ -547,7 +567,7 @@ function vs_utils.set_status_scan(scan_type, host, ports, id)
local host_hash_value = json.decode(host_hash_value_string)
host_hash_value.is_ok_last_scan = 4
host_hash_value.is_ok_last_scan = vs_utils.scan_status.in_progress
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(host_hash_value))
end