chore: print OCSF import result in the CLI (#10229)

This commit is contained in:
Pepe Fagoaga
2026-03-03 10:17:04 +01:00
committed by GitHub
parent efcbbf63c2
commit fa93cabc0b
2 changed files with 25 additions and 15 deletions
+21 -14
View File
@@ -546,27 +546,34 @@ def prowler():
try: try:
response = send_ocsf_to_api(ocsf_output.file_path) response = send_ocsf_to_api(ocsf_output.file_path)
except ValueError: except ValueError:
logger.warning( print(
"OCSF export skipped: no API key configured. " f"{Style.BRIGHT}{Fore.YELLOW}\nOCSF export skipped: no API key configured. "
"Set the PROWLER_API_KEY environment variable to enable it. " "Set the PROWLER_API_KEY environment variable to enable it. "
f"Scan results were saved to {ocsf_output.file_path}" f"Scan results were saved to {ocsf_output.file_path}{Style.RESET_ALL}"
) )
except requests.ConnectionError: except requests.ConnectionError:
logger.warning( print(
"OCSF export skipped: could not reach the Prowler Cloud API at " f"{Style.BRIGHT}{Fore.RED}\nOCSF export failed: could not reach the Prowler Cloud API at "
f"{cloud_api_base_url}. Check the URL and your network connection. " f"{cloud_api_base_url}. Check the URL and your network connection. "
f"Scan results were saved to {ocsf_output.file_path}" f"Scan results were saved to {ocsf_output.file_path}{Style.RESET_ALL}"
) )
except requests.HTTPError as http_err: except requests.HTTPError as http_err:
logger.warning( if http_err.response.status_code == 402:
f"OCSF export failed: the API returned HTTP {http_err.response.status_code}. " print(
"Verify your API key is valid and has the right permissions. " f"{Style.BRIGHT}{Fore.RED}\nOCSF export failed: "
f"Scan results were saved to {ocsf_output.file_path}" "this feature is only available with a Prowler Cloud subscription. "
) f"Scan results were saved to {ocsf_output.file_path}{Style.RESET_ALL}"
)
else:
print(
f"{Style.BRIGHT}{Fore.RED}\nOCSF export failed: the API returned HTTP {http_err.response.status_code}. "
"Verify your API key is valid and has the right permissions. "
f"Scan results were saved to {ocsf_output.file_path}{Style.RESET_ALL}"
)
except Exception as error: except Exception as error:
logger.warning( print(
f"OCSF export failed unexpectedly: {error}. " f"{Style.BRIGHT}{Fore.RED}\nOCSF export failed unexpectedly: {error}. "
f"Scan results were saved to {ocsf_output.file_path}" f"Scan results were saved to {ocsf_output.file_path}{Style.RESET_ALL}"
) )
else: else:
job_id = response.get("data", {}).get("id") if response else None job_id = response.get("data", {}).get("id") if response else None
+4 -1
View File
@@ -18,7 +18,10 @@ def print_banner(legend: bool = False):
| '_ \| '__/ _ \ \ /\ / / |/ _ \ '__| | '_ \| '__/ _ \ \ /\ / / |/ _ \ '__|
| |_) | | | (_) \ V V /| | __/ | | |_) | | | (_) \ V V /| | __/ |
| .__/|_| \___/ \_/\_/ |_|\___|_|v{prowler_version} | .__/|_| \___/ \_/\_/ |_|\___|_|v{prowler_version}
|_|{Fore.BLUE} the handy multi-cloud security tool |_|{Fore.BLUE} Get the most at https://cloud.prowler.com {Style.RESET_ALL}
{Fore.GREEN}New! Send findings from Prowler CLI to Prowler Cloud{Style.RESET_ALL}
{Fore.GREEN}More details here: goto.prowler.com/import-findings{Style.RESET_ALL}
{Fore.YELLOW}Date: {timestamp.strftime("%Y-%m-%d %H:%M:%S")}{Style.RESET_ALL} {Fore.YELLOW}Date: {timestamp.strftime("%Y-%m-%d %H:%M:%S")}{Style.RESET_ALL}
""" """