Skip to content

Add separate file output for converted rules with directory structure preservation#93

Merged
thomaspatzke merged 13 commits into
mainfrom
copilot/create-separate-files-for-converted-rules
Jul 7, 2026
Merged

Add separate file output for converted rules with directory structure preservation#93
thomaspatzke merged 13 commits into
mainfrom
copilot/create-separate-files-for-converted-rules

Conversation

Copilot AI commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Converting multiple Sigma rules currently outputs all results to a single file, making version control and selective deployment impractical. This adds support for writing each converted rule to a separate file with configurable naming and directory structure.

Changes

  • New --output-dir parameter: Specifies output directory for individual rule files (mutually exclusive with --output)
  • New --output-filename-template parameter: Controls output filenames using template variables:
    • {path}: Relative source directory path
    • {stem}: Source filename without extension
    • {index}: Query index for rules emitting multiple queries (1, 2, 3...)
  • Per-rule conversion: Rules are now converted individually when using --output-dir, allowing granular output control
  • Automatic directory creation: Output directories are created as needed based on template
  • Correlation rule validation: Added validation to prevent use of --output-dir with correlation rules, which reference other rules and must be converted as part of the full collection. Exits with clear error message directing users to use --output instead.
  • Filter support: Filters are fully supported with --output-dir as they are resolved at collection load time and baked into individual rule detections

Usage

# Flat structure - all converted files in one directory
sigma convert -t esql -p ecs_windows --output-dir translated/ rules/

# Preserve source directory structure
sigma convert -t esql -p ecs_windows \
  --output-dir translated/ \
  --output-filename-template "{path}/{stem}.esql" rules/

# Handle multi-query rules with indexed filenames
sigma convert -t esql -p ecs_windows \
  --output-dir translated/ \
  --output-filename-template "{stem}-{index}.esql" rules/

Given source structure:

rules/
├── windows/rule_1.yml
├── linux/rule_2.yml

Template {path}/{stem}.esql produces:

translated/
├── windows/rule_1.esql
├── linux/rule_2.esql

Limitations

  • Correlation rules are not supported with --output-dir. Correlation rules reference other rules by name and require the full collection context for conversion. Use --output to write correlation rules to a single file.
  • Filters work correctly with --output-dir and are applied to individual rules as expected.

Testing

  • Added comprehensive tests for correlation rule validation
  • Added tests for filter support with --output-dir
  • All existing tests pass

Copilot AI added 3 commits June 15, 2026 21:02
- Add --output-dir parameter to specify output directory
- Add --output-filename-template parameter with template variables
- Support template variables: {path}, {stem}, {index}
- Handle rules that emit multiple queries with index suffixes
- Create directories as needed for output
- Add comprehensive tests for new functionality
- Document --output-dir and --output-filename-template parameters
- Provide examples for flat and nested directory structures
- Explain template variables {path}, {stem}, {index}
- Change short option from -oT to -ot for consistency
- Improve error messages with actionable guidance
- Add context about expected formats in error messages
Copilot AI changed the title [WIP] Add option to create separate files for converted rules Add separate file output for converted rules with directory structure preservation Jun 15, 2026
Copilot AI requested a review from thomaspatzke June 15, 2026 21:07
Comment thread sigma/cli/convert.py Outdated
Copilot AI added 2 commits June 15, 2026 21:24
- Add validation to prevent use of --output-dir with correlation rules
- Correlation rules reference other rules and cannot be split individually
- Add comprehensive tests for correlation rules and filters
- Filters work correctly as they are resolved at collection load time
- Exit with clear error message if correlation rules are detected
- Replace type().__name__ with isinstance(rule, SigmaCorrelationRule)
- More Pythonic and handles inheritance correctly
- Import SigmaCorrelationRule from sigma.correlations
- Fix trailing whitespace in test file
Comment thread sigma/cli/convert.py Outdated
Copilot AI requested a review from thomaspatzke July 6, 2026 22:10
@thomaspatzke thomaspatzke marked this pull request as ready for review July 7, 2026 21:24
@thomaspatzke thomaspatzke merged commit c92a9f2 into main Jul 7, 2026
15 checks passed
@thomaspatzke thomaspatzke deleted the copilot/create-separate-files-for-converted-rules branch July 7, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants