HTTP Action
HTTP action makes an HTTP request.
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: log-component-status
spec:
description: Post component name and status to webhook
components:
- types:
- KubernetesCluster
actions:
- name: Post a message to webhook
http:
url: https://webhook.site/9f1392a6-718a-4ef5-a8e2-bfb55b08afca
thresholdMillis: 5000
method: POST
body: |
{
"component": {
"name": "{{.component.name}}",
"status": "{{.component.status}}"
}
}
templateBody: true
headers:
- name: X-Postgres-User
value: admin@local
- name: X-Flanksource-Token
value: secret123
Field | Description | Scheme |
---|---|---|
method* | HTTP method to use. Defaults to |
|
name* | Step Name |
|
url* | Url to make the request to |
|
body | Request Body Contents |
|
connection | Connection name. e.g. connection://http/google | |
headers | Header fields to be used in the request | |
password | Password to authenticate with | |
templatedBody | When set to true the request body is templated |
|
username | Username to authenticate with | |
delay | A delay before running the action e.g. |
|
filter | Conditionally run an action | CEL with Playbook Context |
runsOn | Which runner (agent) to run the action on | |
templatesOn | Where templating (and secret management) of actions should occur |
|
timeout | Timeout on this action. |
Templating
CEL Expressions
The following variables can be used within the CEL expressions of filter
, if
, delays
and parameters.default
:
Field | Description | Schema |
---|---|---|
config | Config passed to the playbook | ConfigItem |
component | Component passed to the playbook | Component |
check | Canary Check passed to the playbook | Check |
playbook | Playbook passed to the playbook | Playbook |
run | Current run | Run |
params | User provided parameters to the playbook | map[string]any |
request | Webhook request | Webhook Request |
env | Environment variables defined on the playbook | map[string]any |
user.name | Name of the user who invoked the action | string |
user.email | Email of the user who invoked the action | string |
agent.id | ID of the agent the resource belongs to. | string |
agent.name | Name of the agent the resource belongs to. | string |
Conditionally Running Actions
Playbook actions can be selectively executed based on CEL expressions. These expressions must either return
- a boolean value (
true
indicating run the action & skip the action otherwise) - or a special function among the ones listed below
Function | Description |
---|---|
always() | run no matter what; even if the playbook is cancelled/fails |
failure() | run if any of the previous actions failed |
skip() | skip running this action |
success() | run only if all previous actions succeeded (default) |
timeout() | run only if any of the previous actions timed out |
delete-kubernetes-pod.yaml---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: notify-send-with-filter
spec:
parameters:
- name: message
label: The message for notification
default: '{{.config.name}}'
configs:
- types:
- Kubernetes::Pod
actions:
- name: Send notification
exec:
script: notify-send "{{.config.name}} was created"
- name: Bad script
exec:
script: deltaforce
- 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 Pod config was created"
Defaulting Parameters
delete-kubernetes-pod.yamlmission-control.flanksource.com/v1 kind: Playbook metadata: name: edit spec:
title: 'Edit Kustomize Resource' icon: flux parameters: //highligh-next-line
- default: 'chore: update $(.config.type)/$(.config.name)' name:
commit_message ```
</div>
</details>
### Go Templating
When templating `actions` with [Go Templates](/reference/scripting/gotemplate), the context variables are available as fields of the template's context object `.` eg `.config`, `.user.email`
<details summary="Templating Actions">
<div>
```yaml title="delete-kubernetes-pod.yaml"
file=../../../modules/mission-control/fixtures/playbooks/scale-deployment.yaml{' '}
{16}
Functions
Function | Description | Return |
---|---|---|
getLastAction() | Returns the result of the action that just run | Action Specific |
getAction({action}) | Return the result of a specific action | Action Specific |
Reusing Action Results
action-results.yamlfile=../../../modules/mission-control/fixtures/playbooks/action-result.yaml