mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 21:11:53 +00:00
feat(status): add --status flag (#3238)
This commit is contained in:
@@ -9,10 +9,10 @@ Execute Prowler in verbose mode (like in Version 2):
|
||||
```console
|
||||
prowler <provider> --verbose
|
||||
```
|
||||
## Show only Fails
|
||||
Prowler can only display the failed findings:
|
||||
## Filter findings by status
|
||||
Prowler can filter the findings by their status:
|
||||
```console
|
||||
prowler <provider> -q/--quiet
|
||||
prowler <provider> --status [PASS, FAIL, INFO]
|
||||
```
|
||||
## Disable Exit Code 3
|
||||
Prowler does not trigger exit code 3 with failed checks:
|
||||
|
||||
@@ -22,6 +22,8 @@ gcp_logo = "https://user-images.githubusercontent.com/38561120/235928332-eb4accd
|
||||
orange_color = "\033[38;5;208m"
|
||||
banner_color = "\033[1;92m"
|
||||
|
||||
finding_statuses = ["PASS", "FAIL", "INFO"]
|
||||
|
||||
# Compliance
|
||||
actual_directory = pathlib.Path(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
@@ -50,7 +52,6 @@ aws_services_json_file = "aws_regions_by_service.json"
|
||||
# gcp_zones_json_file = "gcp_zones.json"
|
||||
|
||||
default_output_directory = getcwd() + "/output"
|
||||
|
||||
output_file_timestamp = timestamp.strftime("%Y%m%d%H%M%S")
|
||||
timestamp_iso = timestamp.isoformat(sep=" ", timespec="seconds")
|
||||
csv_file_suffix = ".csv"
|
||||
|
||||
@@ -15,7 +15,7 @@ def print_banner(args):
|
||||
"""
|
||||
print(banner)
|
||||
|
||||
if args.verbose or args.quiet:
|
||||
if args.verbose:
|
||||
print(
|
||||
f"""
|
||||
Color code for results:
|
||||
|
||||
@@ -7,6 +7,7 @@ from prowler.config.config import (
|
||||
check_current_version,
|
||||
default_config_file_path,
|
||||
default_output_directory,
|
||||
finding_statuses,
|
||||
)
|
||||
from prowler.providers.common.arguments import (
|
||||
init_providers_parser,
|
||||
@@ -115,10 +116,10 @@ Detailed documentation at https://docs.prowler.cloud
|
||||
"Outputs"
|
||||
)
|
||||
common_outputs_parser.add_argument(
|
||||
"-q",
|
||||
"--quiet",
|
||||
action="store_true",
|
||||
help="Store or send only Prowler failed findings",
|
||||
"--status",
|
||||
nargs="+",
|
||||
help=f"Filter by the status of the findings {finding_statuses}",
|
||||
choices=finding_statuses,
|
||||
)
|
||||
common_outputs_parser.add_argument(
|
||||
"-M",
|
||||
|
||||
@@ -20,7 +20,7 @@ from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info
|
||||
from prowler.providers.azure.lib.audit_info.models import Azure_Audit_Info
|
||||
|
||||
|
||||
def stdout_report(finding, color, verbose, is_quiet):
|
||||
def stdout_report(finding, color, verbose, status):
|
||||
if finding.check_metadata.Provider == "aws":
|
||||
details = finding.region
|
||||
if finding.check_metadata.Provider == "azure":
|
||||
@@ -30,7 +30,7 @@ def stdout_report(finding, color, verbose, is_quiet):
|
||||
if finding.check_metadata.Provider == "kubernetes":
|
||||
details = finding.namespace.lower()
|
||||
|
||||
if verbose and not (is_quiet and finding.status != "FAIL"):
|
||||
if verbose and (not status or finding.status in status):
|
||||
print(
|
||||
f"\t{color}{finding.status}{Style.RESET_ALL} {details}: {finding.status_extended}"
|
||||
)
|
||||
@@ -62,12 +62,15 @@ def report(check_findings, output_options, audit_info):
|
||||
# Print findings by stdout
|
||||
color = set_report_color(finding.status)
|
||||
stdout_report(
|
||||
finding, color, output_options.verbose, output_options.is_quiet
|
||||
finding, color, output_options.verbose, output_options.status
|
||||
)
|
||||
|
||||
if file_descriptors:
|
||||
# Check if --quiet to only add fails to outputs
|
||||
if not (finding.status != "FAIL" and output_options.is_quiet):
|
||||
# Check if --status is enabled and if the filter applies
|
||||
if (
|
||||
not output_options.status
|
||||
or finding.status in output_options.status
|
||||
):
|
||||
input_compliance_frameworks = list(
|
||||
set(output_options.output_modes).intersection(
|
||||
available_compliance_frameworks
|
||||
|
||||
@@ -28,8 +28,8 @@ def prepare_security_hub_findings(
|
||||
if finding.region not in enabled_regions:
|
||||
continue
|
||||
|
||||
# Handle quiet mode
|
||||
if output_options.is_quiet and finding.status != "FAIL":
|
||||
# Handle status filters, if any
|
||||
if not output_options.status or finding.status in output_options.status:
|
||||
continue
|
||||
|
||||
# Get the finding region
|
||||
|
||||
@@ -46,7 +46,7 @@ def get_provider_output_model(audit_info_class_name):
|
||||
|
||||
@dataclass
|
||||
class Provider_Output_Options:
|
||||
is_quiet: bool
|
||||
status: bool
|
||||
output_modes: list
|
||||
output_directory: str
|
||||
mutelist_file: str
|
||||
@@ -57,7 +57,7 @@ class Provider_Output_Options:
|
||||
unix_timestamp: bool
|
||||
|
||||
def __init__(self, arguments, mutelist_file, bulk_checks_metadata):
|
||||
self.is_quiet = arguments.quiet
|
||||
self.status = arguments.status
|
||||
self.output_modes = arguments.output_modes
|
||||
self.output_directory = arguments.output_directory
|
||||
self.verbose = arguments.verbose
|
||||
|
||||
@@ -241,15 +241,10 @@ class Test_Parser:
|
||||
parsed = self.parser.parse(command)
|
||||
assert parsed.provider == "kubernetes"
|
||||
|
||||
def test_root_parser_quiet_short(self):
|
||||
command = [prowler_command, "-q"]
|
||||
def test_root_parser_status(self):
|
||||
command = [prowler_command, "--status"]
|
||||
parsed = self.parser.parse(command)
|
||||
assert parsed.quiet
|
||||
|
||||
def test_root_parser_quiet_long(self):
|
||||
command = [prowler_command, "--quiet"]
|
||||
parsed = self.parser.parse(command)
|
||||
assert parsed.quiet
|
||||
assert parsed.status
|
||||
|
||||
def test_root_parser_exit_code_3_short(self):
|
||||
command = [prowler_command, "-z"]
|
||||
|
||||
Reference in New Issue
Block a user