Skip to content

Commit 16bf7f0

Browse files
committed
Rule check command
1 parent bb9e950 commit 16bf7f0

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

sigma/cli/check.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1+
import pathlib
12
import click
23

4+
from sigma.collection import SigmaCollection
5+
from sigma.exceptions import SigmaError
6+
37
@click.command()
4-
def check():
8+
@click.option(
9+
"--file-pattern", "-P",
10+
default="*.yml",
11+
show_default=True,
12+
help="Pattern for file names to be included in recursion into directories.",
13+
)
14+
@click.argument(
15+
"input",
16+
nargs=-1,
17+
type=click.Path(exists=True, path_type=pathlib.Path),
18+
)
19+
def check(input, file_pattern):
520
"""Check Sigma rules for validity and best practices (not yet implemented)."""
6-
pass
21+
try:
22+
rule_collection = SigmaCollection.load_ruleset(
23+
input,
24+
recursion_pattern="**/" + file_pattern,
25+
collect_errors=True,
26+
)
27+
for rule in rule_collection.rules:
28+
for error in rule.errors:
29+
click.echo(error)
30+
except SigmaError as e:
31+
click.echo("Check error: " + str(e), err=True)

0 commit comments

Comments
 (0)