more changes!
This commit is contained in:
1 parent
beb2f544d9
commit
66808d77f0
3 files changed
+64
-30
No files matched your search
@@ -973,21 +973,22 @@ def build_important_body(
|
||||
) -> str:
|
||||
"""Full CVE list for one important container, with fixable/unfixable counts."""
|
||||
entries = cve_entries(result, severity_rank(min_severity))
|
||||
total, fixable, unfixable = split_counts(entries)
|
||||
counts = severity_counts(entries)
|
||||
fixable_counts = {severity: 0 for severity in REPORTED_SEVERITIES}
|
||||
for entry in entries:
|
||||
if entry.fixable:
|
||||
fixable_counts[entry.severity] += 1
|
||||
total_fixable = sum(1 for entry in entries if entry.fixable)
|
||||
total_all = len(entries)
|
||||
|
||||
lines = [
|
||||
f"Image: {target.image}",
|
||||
f"Container: {container}",
|
||||
" | ".join(
|
||||
" ".join(
|
||||
f"{name[0]} {fixable_counts[name]}/{counts[name]}"
|
||||
for name in REPORTED_SEVERITIES
|
||||
),
|
||||
f"Total: {fixable}/{total} (fixable/total)",
|
||||
f"Total: {total_fixable}/{total_all}",
|
||||
"",
|
||||
"CVEs:",
|
||||
]
|
||||
@@ -1001,6 +1002,33 @@ def build_important_body(
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def build_important_summary_body(
|
||||
container: str, target: ScanTarget, result: ScanResult, min_severity: str
|
||||
) -> str:
|
||||
"""Summary for an important container with no findings above threshold."""
|
||||
entries = cve_entries(result, severity_rank(min_severity))
|
||||
counts = severity_counts(entries)
|
||||
fixable_counts = {severity: 0 for severity in REPORTED_SEVERITIES}
|
||||
for entry in entries:
|
||||
if entry.fixable:
|
||||
fixable_counts[entry.severity] += 1
|
||||
total_fixable = sum(1 for entry in entries if entry.fixable)
|
||||
total_all = len(entries)
|
||||
|
||||
lines = [
|
||||
f"Image: {target.image}",
|
||||
f"Container: {container}",
|
||||
" ".join(
|
||||
f"{name[0]} {fixable_counts[name]}/{counts[name]}"
|
||||
for name in REPORTED_SEVERITIES
|
||||
),
|
||||
f"Total: {total_fixable}/{total_all}",
|
||||
"",
|
||||
"No CVEs at or above the notification threshold.",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def build_other_containers_body(
|
||||
rows: list[tuple[str, str, int, int, int]],
|
||||
) -> str:
|
||||
@@ -1348,22 +1376,25 @@ def send_notifications(
|
||||
continue # scan failure; already reported by scan_image
|
||||
|
||||
entries = cve_entries(result, settings.notify_rank)
|
||||
if not entries:
|
||||
report_path = os.path.join(settings.report_dir, f"{report_slug(image)}.json")
|
||||
if entries:
|
||||
body = build_important_body(
|
||||
name, target, result, report_path, settings.notify_min_severity
|
||||
)
|
||||
else:
|
||||
log(
|
||||
"DEBUG",
|
||||
f"Important container {name} ({image}) has no findings at or above "
|
||||
f"{settings.notify_min_severity}",
|
||||
)
|
||||
continue
|
||||
report_path = os.path.join(settings.report_dir, f"{report_slug(image)}.json")
|
||||
body = build_important_body(
|
||||
name, target, result, report_path, settings.notify_min_severity
|
||||
)
|
||||
body = build_important_summary_body(
|
||||
name, target, result, settings.notify_min_severity
|
||||
)
|
||||
title = f"{settings.apprise_title_prefix}: {name} ({image})"
|
||||
log(
|
||||
"DEBUG",
|
||||
f"Preparing important-container notification for {name}: "
|
||||
f"{len(entries)} CVE(s)",
|
||||
f"{len(entries)} CVE(s) at or above threshold",
|
||||
)
|
||||
send_notification_parts(settings, stats, title, body)
|
||||
|
||||
|
||||
Reference in new issue
Block a user