Skip to content

Commit 5a1e625

Browse files
committed
Fix result fetching in monthly-report script
The result fetching in the monthly-report script is adjusted in the following ways: - The selected hosts now also include ones that were last updated after the requested month. Otherwise they would be missing even if they were also updated in the requested month. - The number of results for a host is no longer limited by the "Rows per page" setting. - Instead of counting all results, only the distinct vulnerabilities (VTs) are counted. The new counting method also considers only the latest occurrence of a vulnerability in case the severity level has changed in the meantime. Overall, this should make the script behave more as expected. The new result counts by distinct VT should be more informative than the previous number that could be influenced by how many times a host was scanned.
1 parent 1f27f64 commit 5a1e625

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

scripts/monthly-report-gos24.10.gmp.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def check_args(args: Namespace) -> None:
3636
def print_reports(gmp: Gmp, from_date: date, to_date: date) -> None:
3737
host_filter = (
3838
f"rows=-1 and modified>{from_date.isoformat()} "
39-
f"and modified<{to_date.isoformat()}"
39+
f"and created<{to_date.isoformat()}"
4040
)
4141

4242
hosts_xml = gmp.get_hosts(filter_string=host_filter)
@@ -62,21 +62,37 @@ def print_reports(gmp: Gmp, from_date: date, to_date: date) -> None:
6262
hostname = hostnames[0]
6363

6464
results = gmp.get_results(
65-
details=False, filter_string=f"host={ip} and severity>0.0"
65+
details=False,
66+
filter_string=(
67+
f"rows=-1 host={ip} and severity>0.0"
68+
f" and modified>{from_date.isoformat()}"
69+
f" and modified<{to_date.isoformat()}"
70+
),
6671
)
6772

68-
low = int(results.xpath('count(//result/threat[text()="Low"])'))
69-
sum_low += low
73+
unique_vt_results = results.xpath(
74+
"result["
75+
" not (./nvt/@oid = preceding-sibling::result/nvt/@oid)"
76+
"]"
77+
)
78+
if len(unique_vt_results) == 0:
79+
continue
7080

71-
medium = int(results.xpath('count(//result/threat[text()="Medium"])'))
72-
sum_medium += medium
81+
low = medium = high = critical = 0
82+
for result in unique_vt_results:
83+
threat = result.findtext("threat")
84+
if threat == "Critical":
85+
critical += 1
86+
elif threat == "High":
87+
high += 1
88+
elif threat == "Medium":
89+
medium += 1
90+
elif threat == "Low":
91+
low += 1
7392

74-
high = int(results.xpath('count(//result/threat[text()="High"])'))
93+
sum_low += low
94+
sum_medium += medium
7595
sum_high += high
76-
77-
critical = int(
78-
results.xpath('count(//result/threat[text()="Critical"])')
79-
)
8096
sum_critical += critical
8197

8298
best_os_cpe_report_id = host.xpath(

0 commit comments

Comments
 (0)