[VS] Remove duplicated unreachable hosts in report. (#8069)

This commit is contained in:
Nicolo Maio 2023-11-30 16:13:23 +01:00
parent 573afd0044
commit 4d47e300cb
5 changed files with 44 additions and 6 deletions

View file

@ -1439,6 +1439,41 @@ local function retrieve_email_info(exec_type)
return email_info
end
-- **********************************************************
-- Function to check if an host is already present into
-- the hosts list to save on db for report
local function is_already_present_host_in_no_duplicated_result(result_no_duplicated, host)
if (next(result_no_duplicated)) then
for _,item in ipairs(result_no_duplicated) do
if (item.host == host) then
return true
end
end
end
return false
end
-- **********************************************************
-- Function to remove duplicated of down hosts
local function remove_duplicated_host_down(host_scanned_info)
local result_no_duplicated = {}
for _,item in ipairs(host_scanned_info) do
if (item.is_down) then
if (not is_already_present_host_in_no_duplicated_result(result_no_duplicated, item.host)) then
result_no_duplicated[#result_no_duplicated+1] = item
end
else
result_no_duplicated[#result_no_duplicated+1] = item
end
end
return result_no_duplicated
end
-- **********************************************************
-- Function to retrieves report info
local function retrieve_report_info(date)
local host_scanned_info = vs_utils.retrieve_hosts_to_scan()
@ -1473,7 +1508,7 @@ local function retrieve_report_info(date)
local info_date_formatted = tostring(formatEpoch(info.date))
info.name = "Report of "..info_date_formatted
info.all_data_details = host_scanned_info
info.all_data_details = remove_duplicated_host_down(host_scanned_info)
return info
end