Skip to main content

Webhook notification

Consul Release Controller supports Webhooks for notifications, currently Discord and Slack are supported with default and custom messages.

States

Webhooks are called when Consul Release Controller enters the following states:

StateResultsDescription
state_configureevent_fail, event_configuredFired when a new release is created
state_deployevent_fail, event_completeFired when a new deployment is created
state_monitorevent_fail, event_unhealthy, event_healthyFired when monitoring a deployment
state_scaleevent_fail, event_scaledFired when scaling a deployment
state_promoteevent_fail, event_promotedFired when promoting a candidate to the primary
state_rollbackevent_fail, event_completeFired when rolling back a failed deployment
state_destroyevent_fail, event_completeFired when removing a previously configured release

These states can be used to filter webhooks using the status parameter to reduce ChatOps noise.

Slack Webhooks​

The following example shows how to configure a webhook that can post to Slack channels.

  webhooks:
- name: "slack"
pluginName: "slack"
config:
url: "https://hooks.slack.com/services/T9JT4868N/34340Q02/h9N1ry9x29quExF3434f7J"
- name: "slack_custom"
pluginName: "slack"
config:
url: "https://hooks.slack.com/services/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"
status:
- state_deploy
- state_scale
template: |
Custom template message: State has changed to "{{ .State }}" for
the release "{{ .Name }}" in the namespace "{{ .Namespace }}".

The outcome was "{{ .Outcome }}"

Parameters​

NameTypeRequiredDescription
urlstringYesThe Slack Webhook URL
templatestringNoOptional template to replace default Webhook message
status[]stringNoList of statuses to send Webhook message, omitting this parameter calls the webhook for all statuses

Discord Webhooks​

The following example shows how to configure

  webhooks:
- name: "discord_custom"
pluginName: "discord"
config:
id: "94700915179898981"
token: "-OoJOZtJJoAjLBhREuuTtTxlP4q3J219SOGIF5X4O1rro34344wdfwfIPk8CPzPWXnSxBj"
template: |
Custom template message: State has changed to "{{ .State }}" for
the release "{{ .Name }}" in the namespace "{{ .Namespace }}".

The outcome was "{{ .Outcome }}"
status:
- state_deploy
- state_scale
- name: "discord"
pluginName: "discord"
config:
id: "947009151231496821"
token: "-OoJOZtJJoAjLBhREuuTtTxlP4q3J21gaeIPk8CPzPWXnSxBj"

Parameters​

NameTypeRequiredDescription
idstringYesThe Discord Webhook ID
tokenstringYesThe Discord Webhook token
templatestringNoOptional template to replace default Webhook message
status[]stringNoList of statuses to send Webhook message, omitting this parameter calls the webhook for all statuses

Custom Messages​

Rather than have the Webhook send the default messages you can configure a template to be used instead.

Templates are written using Go Template, you can reference the Template Variables or use any of the flow control and default functions.

Consul Release Controller state has changed to "{{ .State }}" for
the release "{{ .Name }}" in the namespace "{{ .Namespace }}".

Primary traffic: {{ .PrimaryTraffic }}
Candidate traffic: {{ .CandidateTraffic }}

{{ if ne .Error "" }}
An error occurred when processing: {{ .Error }}
{{ else }}
The outcome is "{{ .Outcome }}"
{{ end }}

Template Variables​

NameTypeDescription
TitlestringThe Title for the Webhook message
NamestringThe Name of the release
StatestringCurrent state of the release
OutcomestringThe outcome of the status, success, fail, etc. See States table above
PrimaryTrafficintPercentage of Traffic distributed to the Primary instance 0-100
CandidateTrafficintPercentage of Traffic distributed to the Candidate instance 0-100
ErrorstringAn error message if the status failed