Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
db2aa45
v1
korolenkowork Apr 19, 2025
9dfe5f5
Update iohandler.py
korolenkowork Apr 19, 2025
434148b
Update iohandler.py
korolenkowork Apr 19, 2025
ee381d7
fix
korolenkowork Apr 19, 2025
1cc0d29
Done
korolenkowork Apr 19, 2025
e00dd59
Update iohandler.py
korolenkowork Apr 19, 2025
255ec99
Docs
korolenkowork Apr 19, 2025
d11b74c
Update overview.mdx
korolenkowork Apr 19, 2025
04d8f61
Remove useless
korolenkowork Apr 19, 2025
73eee00
Fix
korolenkowork Apr 19, 2025
5ff14ff
catch template syntax error
korolenkowork Apr 19, 2025
31541a8
Fix dependencies
korolenkowork Apr 19, 2025
4e41b40
Update poetry.lock
korolenkowork Apr 19, 2025
41a0ce2
Fix global missing keys
korolenkowork Apr 19, 2025
2ab9717
Return quote func :D
korolenkowork Apr 19, 2025
586c332
Fix
korolenkowork Apr 19, 2025
ff8befb
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 19, 2025
0910b1f
Keep trailing new line jinja
korolenkowork Apr 20, 2025
da3ef36
IOHandeler mustache and jinja2 both support
korolenkowork Apr 20, 2025
75a2176
Fix for ruff lint :D
korolenkowork Apr 20, 2025
cd3b1ed
Workflow parse templating
korolenkowork Apr 20, 2025
97aac08
Update iohandler.py
korolenkowork Apr 21, 2025
f38c903
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 21, 2025
b656cfe
fix jinja tests
korolenkowork Apr 21, 2025
df6fd52
Merge branch 'feature/Jinja-template-engine-in-workflow-templates' of…
korolenkowork Apr 21, 2025
f4394a4
test jinja default templating engine
korolenkowork Apr 21, 2025
c67e7b0
test for syntax validator
korolenkowork Apr 21, 2025
d9f40c4
Docs
korolenkowork Apr 21, 2025
e9a8fbe
Parser tests
korolenkowork Apr 21, 2025
f1d6224
Test workflow
korolenkowork Apr 21, 2025
63d8eb3
minor
korolenkowork Apr 21, 2025
7860eba
More test in honor of the God of Tests
korolenkowork Apr 21, 2025
59428ee
test fix
korolenkowork Apr 21, 2025
ae35db9
Minor revert
korolenkowork Apr 21, 2025
813fad7
Workflow test
korolenkowork Apr 21, 2025
f6aafc8
fix
korolenkowork Apr 21, 2025
98ee2da
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 22, 2025
219de65
minor
korolenkowork Apr 22, 2025
223debd
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
shahargl Apr 28, 2025
23ec014
IOValidatorMixin
korolenkowork Apr 28, 2025
0044d96
Separate IOHandler
korolenkowork Apr 28, 2025
60c9225
Rewrite render recursively
korolenkowork Apr 28, 2025
0921f60
Change workflow iohandler definition
korolenkowork Apr 28, 2025
669f4ce
fix tests
korolenkowork Apr 28, 2025
cc2cbd4
fix iohanler tests
korolenkowork Apr 28, 2025
9d4959f
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 28, 2025
0738c48
fix
korolenkowork Apr 28, 2025
744d0f6
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 28, 2025
9d5fa47
fix
korolenkowork Apr 28, 2025
c5d9ca4
minor
korolenkowork Apr 28, 2025
0117994
minor
korolenkowork Apr 28, 2025
0654283
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 28, 2025
c5c7aab
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 28, 2025
97e5bfa
Update poetry.lock
korolenkowork Apr 28, 2025
7de5227
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 29, 2025
40e6c8e
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
skynetigor Apr 29, 2025
9b7950d
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 29, 2025
c2cd70c
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Apr 30, 2025
1d06dfd
Update templating.mdx
korolenkowork May 1, 2025
ef38522
Update mint.json
korolenkowork May 1, 2025
1ae9614
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 1, 2025
fe36005
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 2, 2025
ccdc67a
Post rev changes
korolenkowork May 4, 2025
c0bdb22
Simplify IOValidatorMixin
korolenkowork May 6, 2025
686b9fd
More tests in honor of God of Tests
korolenkowork May 6, 2025
5152b23
Remove Jinja2 comments logic
korolenkowork May 6, 2025
5435fa5
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 6, 2025
9e3a99a
Update poetry lock
korolenkowork May 6, 2025
9645a28
test
korolenkowork May 6, 2025
9a5f3df
fix
korolenkowork May 6, 2025
fc80e28
fix test
korolenkowork May 6, 2025
9195cc8
fix
korolenkowork May 6, 2025
10e49f5
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
talboren May 10, 2025
267af1b
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 16, 2025
67ceb08
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 19, 2025
eefd491
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 20, 2025
1471025
Update test_iohandler.py
korolenkowork May 29, 2025
98cebc9
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork May 29, 2025
08e4b8f
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
korolenkowork Jun 14, 2025
225d43c
Update poetry.lock
korolenkowork Jun 16, 2025
58f0d0a
Merge branch 'main' into feature/Jinja-template-engine-in-workflow-te…
shahargl Jul 3, 2025
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
3 changes: 2 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"workflows/syntax/context",
"workflows/syntax/providers",
"workflows/syntax/foreach",
"workflows/syntax/enrichment"
"workflows/syntax/enrichment",
"workflows/syntax/templating"
]
},
{
Expand Down
8 changes: 8 additions & 0 deletions docs/workflows/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The general structure of a workflow is:
workflow:
id: aks-example
description: aks-example
templating: mustache or jinja2
triggers:
# list of triggers
- type: manual
Expand Down Expand Up @@ -56,6 +57,7 @@ Let's dive into building workflows:
- [Variables](#variables)
- [Foreach Loops](#foreach-loops)
- [Alert Enrichment](#alert-enrichment)
- [Templating](#templating)


### Triggers
Expand Down Expand Up @@ -105,3 +107,9 @@ Iterate over a list of results from a step to perform repeated actions for each
Add context to alerts, like customer details or ticket metadata, using enrichment mechanisms in steps or actions.

[See syntax](/workflows/syntax/enrichment)

### Templating

Keep supports both Jinja2 and Mustache templating for dynamic values throughout workflows. Users can manually select the templating engine, with Mustache syntax set as the default.

[See syntax](/workflows/syntax/templating)
164 changes: 164 additions & 0 deletions docs/workflows/syntax/templating.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
title: Templating
---

Keep supports two templating engines for dynamic values inside workflow YAML definitions:

- Jinja2 β€” powerful and Pythonic
- Mustache β€” simple and logic-less

You can select the templating engine by setting the templating parameter in your YAML workflow. By default, Keep uses Mustache.

## πŸ”€ Switching Between Engines

Set the templating mode at the top of your workflow:

- Default (no need to specify): mustache
- To use Jinja2: add templating: jinja2

Example:

```yaml
workflows:
- id: jiraonprem-investigate
name: Create investigation
templating: mustache
actions:
...
```

or

```yaml
workflows:
- id: jiraonprem-investigate
name: Create investigation
templating: jinja2
actions:
...
```

---

## Mustache Syntax (Default)

Mustache uses double curly braces for variable interpolation and does not support logic like if/else.

### Variables
```mustache
{{ alert.alertname }}
{{ alert.annotations.summary }}
{{ alert.generatorURL }}
```

### Sections (conditionally rendered if value exists)
```mustache
{{#alert.channel}}
*Channel:* {{ alert.channel }}
{{/alert.channel}}
```

### Inverted Sections (rendered if value is missing or false)
```mustache
{{^alert.alertgroup}}
*Alertgroup:* None
{{/alert.alertgroup}}
```

[See more in the docs](https://github.com/noahmorrison/chevron)

## 🧠 Jinja2 Syntax

Jinja2 provides more advanced capabilities including conditionals, filters, and logic.

Set:
```yaml
templating: jinja2
```

### Variables
```jinja2
{{ alert.alertname }}
{{ alert.annotations.summary }}
```

### Conditionals
```jinja2
{% if alert.channel %}
*Channel:* {{ alert.channel }}
{% endif %}
```

### Default Values
```jinja2
{{ alert.alertgroup or 'None' }}
```

### Filters
```jinja2
{{ alert.labels | join(', ') }}
{{ alert.cluster | default('Unknown Cluster') }}
```

[See more in the docs](https://jinja.palletsprojects.com/en/stable/)

## πŸ“¦ Example: JiraOnPrem with Mustache (Default)

```yaml
workflows:
- id: jiraonprem-investigate
name: Create investigation
templating: mustache
actions:
- name: jiraonprem-action
provider:
type: jiraonprem
config: "{{ providers.jiraOnPrem }}"
with:
description: |
*Alertname:* {{ alert.alertname }}
*Summary:* {{ alert.annotations.summary }}
{{#alert.channel}}
*Channel:* {{ alert.channel }}
{{/alert.channel}}
{{#alert.annotations.runbook_url}}
Runbook: [Runbook|{{ alert.annotations.runbook_url }}]
{{/alert.annotations.runbook_url}}
```



## πŸ“¦ Example: JiraOnPrem with Jinja2

```yaml
templating: jinja2

workflows:
- id: jiraonprem-investigate
name: Create investigation
templating: jinja2
actions:
- name: jiraonprem-action
provider:
type: jiraonprem
config: "{{ providers.jiraOnPrem }}"
with:
description: |
*Alertname:* {{ alert.alertname }}
*Summary:* {{ alert.annotations.summary }}
{% if alert.channel %}
*Channel:* {{ alert.channel }}
{% endif %}
{% if alert.annotations.runbook_url %}
Runbook: [Runbook|{{ alert.annotations.runbook_url }}]
{% endif %}
```


## βœ… Best Practices

- Use mustache for simple output formatting.
- Use jinja2 if you need conditions, defaults, or filters.
- Always wrap multiline strings with quotes and indent properly in YAML.
- In Jinja2, use `{% if %}` to check for presence of values.
- In Mustache, use `{{#section}}` and `{{^section}}` for presence/absence.
4 changes: 2 additions & 2 deletions keep/conditions/base_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from keep.contextmanager.contextmanager import ContextManager
from keep.iohandler.iohandler import IOHandler
from keep.iohandler.iohandler import MustacheIOHandler


class BaseCondition(metaclass=abc.ABCMeta):
Expand All @@ -28,7 +28,7 @@ def __init__(
self.condition_type = condition_type
self.condition_config = condition_config
self.condition_name = condition_name
self.io_handler = IOHandler(context_manager)
self.io_handler = MustacheIOHandler(context_manager)
self.context_manager = context_manager
self.condition_context = {}
self.condition_alias = condition_config.get("alias") or condition_name
Expand Down
Loading
Loading