Skip to content

Commit 837c65b

Browse files
authored
chore(securityhub): improve logging for Security Hub integration (#8608)
1 parent 035293b commit 837c65b

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

prowler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to the **Prowler SDK** are documented in this file.
1111
- Documentation for renaming checks [(#8717)](https://github.com/prowler-cloud/prowler/pull/8717)
1212
- Add explicit "name" field for each compliance framework and include "FRAMEWORK" and "NAME" in CSV output [(#7920)](https://github.com/prowler-cloud/prowler/pull/7920)
1313
- Equality validation for CheckID, filename and classname [(#8690)](https://github.com/prowler-cloud/prowler/pull/8690)
14+
- Improve logging for Security Hub integration [(#8608)](https://github.com/prowler-cloud/prowler/pull/8608)
1415

1516
### Changed
1617

prowler/__main__.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
html_file_suffix,
1414
json_asff_file_suffix,
1515
json_ocsf_file_suffix,
16+
orange_color,
1617
)
1718
from prowler.lib.banner import print_banner
1819
from prowler.lib.check.check import (
@@ -916,9 +917,14 @@ def streaming_callback(findings_batch):
916917
)
917918
# Send the findings to Security Hub
918919
findings_sent_to_security_hub = security_hub.batch_send_to_security_hub()
919-
print(
920-
f"{Style.BRIGHT}{Fore.GREEN}\n{findings_sent_to_security_hub} findings sent to AWS Security Hub!{Style.RESET_ALL}"
921-
)
920+
if findings_sent_to_security_hub == 0:
921+
print(
922+
f"{Style.BRIGHT}{orange_color}\nNo findings sent to AWS Security Hub.{Style.RESET_ALL}"
923+
)
924+
else:
925+
print(
926+
f"{Style.BRIGHT}{Fore.GREEN}\n{findings_sent_to_security_hub} findings sent to AWS Security Hub!{Style.RESET_ALL}"
927+
)
922928

923929
# Resolve previous fails of Security Hub
924930
if not args.skip_sh_update:
@@ -928,9 +934,14 @@ def streaming_callback(findings_batch):
928934
findings_archived_in_security_hub = (
929935
security_hub.archive_previous_findings()
930936
)
931-
print(
932-
f"{Style.BRIGHT}{Fore.GREEN}\n{findings_archived_in_security_hub} findings archived in AWS Security Hub!{Style.RESET_ALL}"
933-
)
937+
if findings_archived_in_security_hub == 0:
938+
print(
939+
f"{Style.BRIGHT}{orange_color}\nNo findings archived in AWS Security Hub.{Style.RESET_ALL}"
940+
)
941+
else:
942+
print(
943+
f"{Style.BRIGHT}{Fore.GREEN}\n{findings_archived_in_security_hub} findings archived in AWS Security Hub!{Style.RESET_ALL}"
944+
)
934945

935946
# Display summary table
936947
if not args.only_logs:

prowler/providers/aws/lib/security_hub/security_hub.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ def __init__(
165165
aws_account_id,
166166
aws_partition,
167167
)
168-
if findings and self._enabled_regions:
169-
self._findings_per_region = self.filter(findings, send_only_fails)
168+
if findings:
169+
if not self._enabled_regions:
170+
logger.error("No enabled regions found in Security Hub.")
171+
else:
172+
self._findings_per_region = self.filter(findings, send_only_fails)
170173

171174
def filter(
172175
self,
@@ -185,6 +188,7 @@ def filter(
185188
"""
186189

187190
findings_per_region = {}
191+
disabled_regions_logged = set()
188192
try:
189193
# Create a key per audited region
190194
for region in self._enabled_regions.keys():
@@ -193,6 +197,12 @@ def filter(
193197
for finding in findings:
194198
# We don't send findings to not enabled regions
195199
if finding.Resources[0].Region not in findings_per_region:
200+
# Only log once per disabled region
201+
if finding.Resources[0].Region not in disabled_regions_logged:
202+
logger.warning(
203+
f"Skipping findings in region {finding.Resources[0].Region} because it is not enabled in Security Hub."
204+
)
205+
disabled_regions_logged.add(finding.Resources[0].Region)
196206
continue
197207

198208
if (

0 commit comments

Comments
 (0)