Skip to main content

Expressions

Playbook event filters use Common Expression Language (CEL).

The Common Expression Language (CEL) is a non-Turing complete language designed for simplicity, speed, safety, and portability. CEL's C-like syntax is similar to expressions in C++, Go, Java, and TypeScript.

Examples:

notify-with-filter.yaml
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: notify-with-filter
spec:
on:
config:
- event: created
configs:
- type: Kubernetes::Pod
actions:
- name: Send notification
exec:
script: notify-send "{{.config.name}} was created"
- name: Bad script to create a failing action
exec:
script: non-existing-command
- name: Send all success notification
if: success() # this filter practically skips this action as the second action above always fails
exec:
script: notify-send "Everything went successfully"
- name: Send notification regardless
if: always()
exec:
script: notify-send "a config was created"

Conditionally running actions

Playbook actions can be conditionally executed using CEL expressions. These expressions must return a bool value (return false to skip the action).

Expressions support the following functions in addition to the standard CEL functions.

FunctionDescription
always()Execute regardless of playbook state (cancelled/failed)
failure()Execute if any previous actions failed
skip()Skip execution of this action
success()Execute only if all previous actions succeeded (default)
timeout()Execute only if any previous actions timed out

Examples

  • if: config.deleted_at ? true: false
  • if: always()

Context

Expressions have access to the following variables and functions:

FieldDescriptionSchema
configConfiguration object passed to the playbookConfigItem
componentComponent object passed to the playbookComponent
checkCanary Check object passed to the playbookCheck
paramsUser-provided parameters for the playbookmap[string]string
user.idUnique identifier of the user who triggered the actionstring
user.nameFull name of the user who triggered the actionstring
user.emailEmail address of the user who triggered the actionstring
action.nameName of the current actionstring
action.statusCurrent status of the action (scheduled, running, succeeded, failed, skipped, or cancelled)string
action.scheduled_timeTimestamp when the action was scheduledstring
action.start_timeTimestamp when the action execution beganstring

For playbooks triggered via webhooks, the following additional fields are available:

FieldDescriptionScheme
request.content

Content sent on the webhook request

string

request.headers

Headers sent on the webhook request

map[string]string

request.json

JSON content if the webhook content is JSON

map[string]any

request.params

Query parameters sent on the webhook request

map[string]string

request.url

Endpoint of the webhook. Example /playbook/webhook/test-webhook

string