From a8e50a605112114ffab5e876bde9290e23105acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milio=F0=9F=98=8EGonzalez?= Date: Tue, 2 Jul 2024 11:36:03 -0400 Subject: [PATCH] Add a `--verbose` option to `sigma convert`. This allows easier debugging, as the error in the backend will be in the resulting stack trace. Finding the source of the error without this is not a fun experience :) --- sigma/cli/convert.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sigma/cli/convert.py b/sigma/cli/convert.py index 3741084..21cdbe7 100644 --- a/sigma/cli/convert.py +++ b/sigma/cli/convert.py @@ -4,6 +4,8 @@ from typing import Sequence import click + +from sigma.cli.rules import load_rules from sigma.conversion.base import Backend from sigma.exceptions import ( SigmaError, @@ -12,8 +14,6 @@ ) from sigma.plugins import InstalledSigmaPlugins -from sigma.cli.rules import load_rules - plugins = InstalledSigmaPlugins.autodiscover() backends = plugins.backends pipelines = plugins.pipelines @@ -163,6 +163,14 @@ def fail(self, message: str, param, ctx): required=True, type=click.Path(exists=True, allow_dash=True, path_type=pathlib.Path), ) +@click.option( + "--verbose", + required=False, + is_flag=True, + default=False, + type=click.BOOL, + help="Verbose output.", +) def convert( target, pipeline, @@ -178,6 +186,7 @@ def convert( backend_option, input, file_pattern, + verbose, ): """ Convert Sigma rules into queries. INPUT can be multiple files or directories. This command automatically recurses @@ -321,9 +330,17 @@ def convert( f"Backend returned unexpected format {str(type(result))}" ) except SigmaError as e: - raise click.ClickException("Error while conversion: " + str(e)) + if verbose: + click.echo('Error while converting') + raise e + else: + raise click.ClickException("Error while converting: " + str(e)) except NotImplementedError as e: - raise click.ClickException("Feature required for conversion of Sigma rule is not supported by backend: " + str(e)) + if verbose: + click.echo('Feature required for conversion of Sigma rule is not supported by backend') + raise e + else: + raise click.ClickException("Feature required for conversion of Sigma rule is not supported by backend: " + str(e)) if len(backend.errors) > 0: click.echo("\nIgnored errors:", err=True)