Implemented clean host delete in VS

This commit is contained in:
Luca Deri 2023-08-17 18:52:06 +02:00
parent b98a100871
commit 75ccb84b31
2 changed files with 22 additions and 10 deletions

View file

@ -38,8 +38,8 @@ 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_scan_queue_key = "ntopng.vs_scan_queue"
local host_to_scan_key = "ntopng.prefs.host_to_scan"
local host_scan_queue_key = "ntopng.vs_scan_queue"
local scanned_hosts_changes_key = "ntopng.alerts.scanned_hosts_changes"
local json = require("dkjson")
@ -426,6 +426,25 @@ function vs_utils.delete_host_to_scan(host, scan_type, all)
local path_to_s_result = get_report_path(scan_type, host, false)
os.remove(path_to_s_result)
ntop.delHashCache(host_to_scan_key, host_hash_key)
-- Remove this host from active schedules
local elems = {}
while(true) do
local e = ntop.lpopCache(host_scan_queue_key)
if(e == nil) then
break
else
local r = json.decode(e)
if(not((r.scan_type == "cve") and (r.host == "127.0.0.1"))) then
table.insert(elems, e)
end
end
end
for _,i in pairs(elems) do
ntop.lpushCache(host_scan_queue_key, i)
end
end
return true