Skip to main content

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
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
FieldDescriptionScheme
name*

Step Name

string

http

HTTP Action

HTTP

delay

A delay before running the action e.g. 8h

Duration or CEL with Playbook Context

filter

Conditionally run an action

CEL with Playbook Context

runsOn

Which runner (agent) to run the action on

[]Agent

templatesOn

Where templating (and secret management) of actions should occur

host or agent

timeout

Timeout on this action.

Duration

HTTP​

FieldDescriptionScheme
url*

Url to make the request to

string

awsSigV4

Sign the request with AWS Signature Version 4

AWSSigV4

bearer

Bearer token to authenticate with

EnvVar

body

Request Body Contents

string

connection

Connection name. e.g. connection://http/google

Connection

digest

Use digest authentication

boolean

headers

Header fields to be used in the request

[]EnvVar

method

HTTP method to use. Defaults to GET

string

ntlm

Use NTLM authentication

boolean

ntlmv2

Use NTLMv2 authentication

boolean

oauth

Authenticate using the OAuth client credentials flow

OAuth

password

Password to authenticate with

EnvVar

templateBody

When set to true the request body is templated

boolean

tls

TLS settings for the request

TLS

username

Username to authenticate with

EnvVar

OAuth​

FieldDescriptionScheme
clientID

OAuth client ID

EnvVar

clientSecret

OAuth client secret

EnvVar

params

Additional parameters sent to the token endpoint

[map[string]string]

scope

Scopes to request

[]string

tokenURL

URL of the token endpoint

string

AWS SigV4​

Accepts every field of an AWSConnection, plus:

FieldDescriptionScheme
service

AWS service the request is signed for e.g. es, execute-api

string

TLS​

FieldDescriptionScheme
ca

PEM encoded certificate of the CA used to verify the server certificate

EnvVar

cert

PEM encoded client certificate

EnvVar

handshakeTimeout

TLS handshake timeout. Defaults to 10 seconds

Duration

insecureSkipVerify

Do not verify the server's certificate chain and host name

boolean

key

PEM encoded client private key

EnvVar

Output​

FieldDescriptionScheme
code

Response status code

integer

content

Response Body Contents

string

headers

Response headers

[map[string]string]

Templating​

CEL Expressions​

The following variables can be used within the CEL expressions of filter, if, delays and parameters.default:

FieldDescriptionSchema
configConfig passed to the playbookConfigItem
checkCanary Check passed to the playbookCheck
playbookPlaybook passed to the playbookPlaybook
runCurrent runRun
paramsUser provided parameters to the playbookmap[string]any
requestWebhook requestWebhook Request
envEnvironment variables defined on the playbookmap[string]any
user.nameName of the user who invoked the actionstring
user.emailEmail of the user who invoked the actionstring
agent.idID of the agent the resource belongs to.string
agent.nameName 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
FunctionDescription
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.yaml
apiVersion:
mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: edit
spec:
title: 'Edit Kustomize Resource'
icon: flux
parameters:
- default: 'chore: update $(.config.type)/$(.config.name)'
name: commit_message

Go Templating​

When templating actions with Go Templates, the context variables are available as fields of the template's context object . eg .config, .user.email

Templating Actions
delete-kubernetes-pod.yaml
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: scale-deployment
spec:
description: Scale Deployment
configs:
- types:
- Kubernetes::Deployment
parameters:
- name: replicas
label: The new desired number of replicas.
actions:
- name: kubectl scale
exec:
script: |
kubectl scale --replicas={{.params.replicas}} \
--namespace={{.config.tags.namespace}} \
deployment {{.config.name}}

Functions​

FunctionDescriptionReturn
getLastAction()Returns the result of the action that just runAction Specific
getAction({action})Return the result of a specific actionAction Specific
Printing out Results
Reusing Action Results
action-results.yaml
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: use-previous-action-result
spec:
description: Creates a file with the content of the config
configs:
- types:
- Kubernetes::Pod
actions:
- name: Fetch all changes
sql:
query: SELECT id FROM config_changes WHERE config_id = '{{.config.id}}'
driver: postgres
connection: connection://postgres/local
- name: Send notification
if: 'last_result().count > 0'
notification:
title: 'Changes summary for {{.config.name}}'
connection: connection://slack/flanksource
message: |
{{$rows:=index last_result "count"}}
Found {{$rows}} changes