Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --verbose option to sigma convert. #51

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions sigma/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading