Workflows
Filters, templates and pulling data
How to read case fields, artifacts, custom attributes, alert payloads and earlier step results in sochub workflow filters and templates.
Workflows read data with Jinja, a small template language. There are two ways to use it, and it matters which one a field expects.
Expressions and text templates
Expressions are bare Jinja expressions, written without {{ }}. They return a value: true/false, a list, an object.
| Where | Example |
|---|---|
| Trigger filter | 'phishing' in case.tags |
| Condition node, Expression | steps.lookup.output.status == 200 |
| For each node, Items | case.attributes_all.get('ip', []) |
| Create alert node, Payload | loop.item |
Text templates are every other text field: notes, Slack messages, URLs, headers, HTTP bodies, titles. Put values inside {{ }}; you can also use {% if %} and {% for %} blocks.
Case #{{ case.id }}: {{ case.title }} ({{ case.severity }})
Two details:
- A field that contains only one
{{ ... }}keeps the value’s type.{{ case.id }}in a JSON body gives the number7, not the string"7", and{{ steps.lookup.output.body.users }}gives a list. - In Slack message fields, inserted values are escaped for Slack, so case or alert data can’t add links or
@channelmentions. Markup you type yourself, such as<https://wiki.example/runbook|runbook>, is kept.
Strict by default
A name or field that does not exist is an error, not an empty string:
- in a step, the step fails;
- in a trigger filter, the filter counts as false and no run is created.
So when a field may be missing, use .get(), is defined, or default(). Each section below shows the safe form.
What templates can read
| Name | What it is |
|---|---|
case |
The run’s case, read fresh before each step. Empty (none) when the run has no case yet, for example in an Alert ingested run before Promote alert. |
alert |
The run’s alert: id, source, external_id, title, severity, status, payload, case_id. For case and manual runs, it is the newest alert promoted into the case, or none. |
trigger |
The event: event, case_id, alert_id, changes (case updated), fired_at / since / since_ms (schedule), user_id (manual), inputs / started_by (started by Run workflow). |
steps.<id>.output |
Output of a step that already ran in this run. steps.<id>.status is its status. Steps inside a loop also see the steps of the main run. |
loop.item, loop.index |
Inside a For each box only: the current item and its position (from 0). |
dry_run |
true in a dry run. |
secrets.NAME |
A secret, in HTTP request URL, headers, body and auth only. See Secrets. |
In a trigger filter only case, alert and trigger are available, and alert is only set for Alert ingested workflows. (Email received filters read the message as email, for example 'soc+phishing' in email.to_joined; in its steps it is trigger.email.)
Pulling fields from a case
| Field | Example value | Use |
|---|---|---|
case.id |
42 |
{{ case.id }} |
case.title |
Suspicious login |
{{ case.title }} |
case.description |
text | {{ case.description }} |
case.status |
new, open, in_progress, pending, resolved, closed |
case.status == 'open' |
case.severity |
critical, high, medium, low, info |
case.severity in ['critical', 'high'] |
case.tags |
['phishing', 'vip'] |
'vip' in case.tags |
case.owner_id |
user id or none |
case.owner_id is none |
case.source |
where it came from | {{ case.source }} |
case.group_key |
grouping key set by Promote alert | {{ case.group_key }} |
case.created_at |
ISO timestamp | {{ case.created_at }} |
case.artifacts |
list of {type, value} |
see below |
case.attributes |
first value per artifact type | see below |
case.attributes_all |
every value per artifact type | see below |
Tags as text:
Tags: {{ case.tags | join(', ') }}
Custom attributes
Every artifact on a case is also available by its type key, which makes custom artifact types (defined by admins in Settings → Artifact types) easy to read. Built-in types work the same way (ip, domain, url, file_hash, email, hostname, username, other).
Suppose the case has a custom artifact type with key user_email:
{{ case.attributes.user_email }}
First value. The step fails if the case has none.
{{ case.attributes.get('user_email', '') }}
First value, or an empty string if there is none.
{{ case.attributes_all.get('user_email', []) | join(', ') }}
Every value, comma-separated.
Custom types marked private are hidden in the interface but still visible to workflows.
When an alert is promoted, values from the alert payload are copied onto the case as custom artifacts if the type has a payload key, so case.attributes.<key> works right after Promote alert.
Pulling artifacts from a case
case.artifacts is a list in the order the artifacts were added:
[{"type": "ip", "value": "203.0.113.7"}, {"type": "domain", "value": "bad.example"}, ...]
The first IP, or an empty string:
{{ case.attributes.get('ip', '') }}
The same with filters, which you can adapt to any condition:
{{ case.artifacts | selectattr('type', 'equalto', 'ip') | map(attribute='value') | first | default('') }}
All domains, comma-separated:
{{ case.attributes_all.get('domain', []) | join(', ') }}
How many hashes:
{{ case.attributes_all.get('file_hash', []) | length }}
Does the case have any URL (as an expression, for a condition):
case.artifacts | selectattr('type', 'equalto', 'url') | list | length > 0
Several types at once:
case.artifacts | selectattr('type', 'in', ['ip', 'domain']) | map(attribute='value') | list
Looping over artifacts
To run steps once per artifact, set the For each node’s Items to an expression that returns a list:
case.attributes_all.get('ip', [])
or, with filters (end with | list; a filter chain without it is not a list and the step fails):
case.artifacts | selectattr('type', 'equalto', 'ip') | map(attribute='value') | list
Inside the loop, {{ loop.item }} is the current IP. If you loop over case.artifacts itself, loop.item.type and loop.item.value are available. See example 3.
Pulling fields from an alert payload
alert.payload is the JSON the alert arrived with. Read nested fields with dots:
{{ alert.payload.host }}
{{ alert.payload.user.email }}
{{ alert.payload.process.parent.name }}
List items by index:
{{ alert.payload.users[0] }}
Other alert fields: alert.source (for webhook alerts, the webhook’s name), alert.title, alert.severity, alert.external_id.
Optional and missing fields
Strict mode means alert.payload.user.email fails if user is missing. Safer forms:
| Goal | Expression |
|---|---|
| Field may be missing | alert.payload.get('host', '') |
| Nested field may be missing | (alert.payload.get('user') or {}).get('email', '') |
| Check before comparing | alert.payload.severity is defined and alert.payload.severity >= 7 |
| Treat missing or null as 0 | (alert.payload.get('severity') or 0) >= 7 |
| Default for display | {{ alert.payload.get('country', 'unknown') }} |
Comparing a missing or null value with a number is an error, which is why the is defined or or 0 form matters in filters.
Using earlier step outputs
Every step’s output is available to the steps after it as steps.<node id>.output. Output shapes are listed in Workflow nodes.
HTTP {{ steps.lookup.output.status }}
{{ steps.lookup.output.body.data.verdict }}
{{ steps.ask.output.response }}
{{ 'new case' if steps.promote.output.created else 'existing case' }}
An HTTP request body is parsed as JSON when possible. If the API might answer with something else, check it first:
{{ steps.lookup.output.body.get('verdict', 'unknown') if steps.lookup.output.body is mapping else 'not JSON' }}
A Condition node outputs {result: true} or {result: false}.
After a For each loop, steps.<loop id>.output has succeeded, failed and results: one entry per item with index, status and steps (each inner step’s output by node id):
{{ steps.each_ip.output.succeeded }} of {{ steps.each_ip.output.results | length }} lookups succeeded
Filter recipes
Trigger filters are expressions. Leave the filter empty to run on every event.
Case created
'phishing' in case.tags
case.severity == 'critical'
case.severity in ['critical', 'high'] and 'vip' in case.tags
'invoice' in case.title | lower
Case updated
Severity became critical:
'severity' in trigger.changes and trigger.changes.severity.to == 'critical'
Severity went up from low or medium to high or critical:
'severity' in trigger.changes and trigger.changes.severity.from in ['low', 'medium'] and trigger.changes.severity.to in ['high', 'critical']
A tag was added:
'tags' in trigger.changes and 'ransomware' in trigger.changes.tags.added
Case was closed:
'status' in trigger.changes and trigger.changes.status.to == 'closed'
Owner changed:
'assignee' in trigger.changes
Alert ingested
From one source:
alert.source == 'EDR'
alert.source in ['crowdstrike', 'sentinelone']
By severity:
alert.severity in ['critical', 'high']
On a payload field:
alert.source == 'EDR' and (alert.payload.get('severity') or 0) >= 7
(alert.payload.get('user') or {}).get('email', '') != ''
'admin' in alert.payload.get('roles', [])
Handy filters and tests
Standard Jinja filters and tests are available. These are used throughout the built-in templates:
| Filter | Example |
|---|---|
default |
{{ x | default('n/a') }} |
join |
{{ case.tags | join(', ') }} |
first, last, length |
{{ items | length }} |
selectattr, map(attribute=...) |
case.artifacts | selectattr('type', 'equalto', 'ip') | map(attribute='value') | list |
select |
drops empty values from a list |
list |
turns a filter chain into a list |
lower, upper, trim |
{{ alert.payload.get('user_name', '') | lower }} |
truncate |
{{ case.title | truncate(100) }} |
urlencode |
?since={{ trigger.since | urlencode }} |
tojson |
{{ alert.payload | tojson }} |
int |
{{ alert.payload.score | int }} |
Tests: is defined, is none, is mapping. Operators: ==, !=, <, >=, in, not in, and, or, not, ~ (join as text), and inline x if cond else y.
Templates can’t change data (for example case.tags.append(...) fails) and can’t reach Python internals.
Limits
Each template and filter is bounded so one workflow can’t slow the shared worker. Going over a limit fails the step (or makes a filter count as false):
- at most 1 second and 100,000 operations per render;
range()up to 10,000 items;- any single value, and the rendered result, up to 1,000,000 characters or items;
lipsumandstr.translateare not available.
A For each expression must return a list of at most max_items (100 by default, 500 at most); more fails the step.
Found a mistake? Edit this page or open an issue on GitHub.