Post-Processing and Finalization¶
Post-processing transformations operate on generated query strings, and finalizers operate on the complete set of queries.
Query Post-Processing¶
- class sigma.processing.postprocessing.QueryPostprocessingTransformation[source]¶
Bases:
TransformationQuery post processing transformation base class.
- processing_item: 'QueryPostprocessingItem' | None = None¶
- abstractmethod apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__()¶
- Return type:
None
- class sigma.processing.postprocessing.EmbedQueryTransformation[source]¶
Bases:
QueryPostprocessingTransformationEmbeds a query between a given prefix and suffix. Only applicable to string queries.
- prefix: str = ''¶
- suffix: str = ''¶
- apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__(prefix='', suffix='')¶
- Parameters:
prefix (str)
suffix (str)
- Return type:
None
- class sigma.processing.postprocessing.QuerySimpleTemplateTransformation[source]¶
Bases:
QueryPostprocessingTransformationReplace query with template that can refer to the following placeholders:
query: the postprocessed query.
rule: the Sigma rule including all its attributes like rule.title.
pipeline: the Sigma processing pipeline where this transformation is applied including all current state information in pipeline.state.
The Python format string syntax (str.format()) is used. Field lookups are sandboxed: access to underscore-prefixed attributes (e.g.
__globals__) is denied and format specifications with excessive widths or precisions are rejected.- template: str¶
- apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__(template)¶
- Parameters:
template (str)
- Return type:
None
- class sigma.processing.postprocessing.QueryTemplateTransformation[source]¶
Bases:
QueryPostprocessingTransformation,TemplateBaseApply Jinja2 template provided as template object variable to a query. The following variables are available in the context:
query: the postprocessed query.
rule: the Sigma rule including all its attributes like rule.title.
pipeline: the Sigma processing pipeline where this transformation is applied including all current state information in pipeline.state.
if path is given, template is considered as a relative path to a template file below the specified path. If it is not provided, the template is specified as plain string. autoescape controls the Jinja2 HTML/XML auto-escaping.
if vars is given, it should point to a Python file containing helper functions and variables to be made available in the Jinja2 template context. See TemplateBase for details on the format.
- apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__(template, path=None, autoescape=False, vars=None, policy=None, restrict_template_path=False)¶
- Parameters:
template (str)
path (str | None)
autoescape (bool)
vars (str | None)
policy (SigmaPolicy | None)
restrict_template_path (bool)
- Return type:
None
- class sigma.processing.postprocessing.EmbedQueryInJSONTransformation[source]¶
Bases:
QueryPostprocessingTransformationEmbeds a query into a JSON structure defined as string. the placeholder value %QUERY% is replaced with the query.
- json_template: str¶
- apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__(json_template)¶
- Parameters:
json_template (str)
- Return type:
None
- class sigma.processing.postprocessing.ReplaceQueryTransformation[source]¶
Bases:
QueryPostprocessingTransformationReplace query part specified by regular expression with a given string.
- pattern: str¶
- replacement: str¶
- apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__(pattern, replacement)¶
- Parameters:
pattern (str)
replacement (str)
- Return type:
None
- class sigma.processing.postprocessing.NestedQueryPostprocessingTransformation[source]¶
Bases:
QueryPostprocessingTransformationApplies a list of query postprocessing transformations to the query in a nested manner.
- items: list['QueryPostprocessingItem']¶
- apply(rule, query)[source]¶
Applies post-processing transformation to arbitrary typed query.
Record the processing item on the rule so later
processing_item_appliedconditions can match it.- Parameters:
pipeline (sigma.processing.pipeline.ProcessingPipeline) – Processing pipeline this transformation was contained.
rule (SigmaRule) – Sigma rule that is associated with the generated query.
query (Any) – Query that should be transformed.
- Returns:
Transformed query.
- Return type:
Any
- __init__(items)¶
- Parameters:
items (list['QueryPostprocessingItem'])
- Return type:
None
Finalizers¶
- class sigma.processing.finalization.Finalizer[source]¶
Bases:
objectConversion output transformation base class.
- set_pipeline(pipeline)[source]¶
- Parameters:
pipeline (ProcessingPipeline)
- Return type:
None
- abstractmethod apply(queries)[source]¶
Finalize output by applying a transformation to the list of generated and postprocessed queries.
- Parameters:
queries (list[Any]) – List of converted and postprocessed queries that should be finalized.
- Returns:
Output that can be used in further processing of the conversion result.
- Return type:
Any
- __init__()¶
- Return type:
None
- class sigma.processing.finalization.ConcatenateQueriesFinalizer[source]¶
Bases:
FinalizerConcatenate queries with a given separator and embed result within a prefix or suffix string.
- separator: str = '\n'¶
- prefix: str = ''¶
- suffix: str = ''¶
- apply(queries)[source]¶
Finalize output by applying a transformation to the list of generated and postprocessed queries.
- Parameters:
queries (list[Any]) – List of converted and postprocessed queries that should be finalized.
- Returns:
Output that can be used in further processing of the conversion result.
- Return type:
Any
- __init__(separator='\n', prefix='', suffix='')¶
- Parameters:
separator (str)
prefix (str)
suffix (str)
- Return type:
None
- class sigma.processing.finalization.JSONFinalizer[source]¶
Bases:
FinalizerJSONFinalizer(indent: ‘int | None’ = None)
- indent: int | None = None¶
- apply(queries)[source]¶
Finalize output by applying a transformation to the list of generated and postprocessed queries.
- Parameters:
queries (list[Any]) – List of converted and postprocessed queries that should be finalized.
- Returns:
Output that can be used in further processing of the conversion result.
- Return type:
Any
- __init__(indent=None)¶
- Parameters:
indent (int | None)
- Return type:
None
- class sigma.processing.finalization.YAMLFinalizer[source]¶
Bases:
FinalizerYAMLFinalizer(indent: ‘int | None’ = None)
- indent: int | None = None¶
- apply(queries)[source]¶
Finalize output by applying a transformation to the list of generated and postprocessed queries.
- Parameters:
queries (list[Any]) – List of converted and postprocessed queries that should be finalized.
- Returns:
Output that can be used in further processing of the conversion result.
- Return type:
Any
- __init__(indent=None)¶
- Parameters:
indent (int | None)
- Return type:
None
- class sigma.processing.finalization.TemplateFinalizer[source]¶
Bases:
Finalizer,TemplateBaseApply Jinja2 template provided as template object variable to the queries. The following variables are available in the context:
queries: all post-processed queries generated by the backend.
pipeline: the Sigma processing pipeline where this transformation is applied including all current state information in pipeline.state.
if path is given, template is considered as a relative path to a template file below the specified path. If it is not provided, the template is specified as plain string. autoescape controls the Jinja2 HTML/XML auto-escaping.
if vars is given, it should point to a Python file containing helper functions and variables to be made available in the Jinja2 template context. See TemplateBase for details on the format.
- apply(queries)[source]¶
Finalize output by applying a transformation to the list of generated and postprocessed queries.
- Parameters:
queries (list[Any]) – List of converted and postprocessed queries that should be finalized.
- Returns:
Output that can be used in further processing of the conversion result.
- Return type:
Any
- __init__(template, path=None, autoescape=False, vars=None, policy=None, restrict_template_path=False)¶
- Parameters:
template (str)
path (str | None)
autoescape (bool)
vars (str | None)
policy (SigmaPolicy | None)
restrict_template_path (bool)
- Return type:
None
- class sigma.processing.finalization.NestedFinalizer[source]¶
Bases:
FinalizerApply a list of finalizers to the queries in a nested fashion.
- classmethod from_dict(d, policy=None)[source]¶
- Parameters:
d (dict[str, Any])
policy (SigmaPolicy | None)
- Return type:
- apply(queries)[source]¶
Finalize output by applying a transformation to the list of generated and postprocessed queries.
- Parameters:
queries (list[Any]) – List of converted and postprocessed queries that should be finalized.
- Returns:
Output that can be used in further processing of the conversion result.
- Return type:
Any