Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Bosun -> Slack Template
slack = `
{{- $attachments := makeSlice -}}
{{- /* Set some slack properties on the attachment */ -}}
{{- $fallback := printf "Alert on %v" .Alert.Vars.url_host -}}
{{- $title := printf "%v: HTTPUnit Check for %v returned error(s)" .Last.Status .Alert.Vars.url_host -}}
{{- $ts := .LastAbnormalTime.Unix -}}
{{- $color := "good" -}}
{{- if .Last.Status.IsWarning -}}
{{- $color = "warning" -}}
{{- else if .Last.Status.IsCritical -}}
{{- $color = "danger" -}}
{{- end -}}
{{- $fields := makeSlice -}}
{{- /* General Error Field */ -}}
{{- $generalErrorValue := "False" -}}
{{- $generalError := .Eval .Alert.Vars.got_expected_code -}}
{{- if $generalError -}} {{- $generalErrorValue = "True" -}} {{- end -}}
{{- $fields := append $fields (makeMap "title" "General Rollup Error" "value" $generalErrorValue) -}}
{{- /* Field for Getting Expected Response Code */ -}}
{{- $gotCodeValue := "False" -}}
{{- $gotCode := .Eval .Alert.Vars.got_expected_code -}}
{{- if not $gotCode -}} {{- $gotCodeValue = "True" -}} {{- end -}}
{{- $fields := append $fields (makeMap "title" "Got Expected HTTP Reponse Code" "value" $gotCodeValue) -}}
{{- $actions := makeSlice -}}
{{- /* Response Time Graph Link */ -}}
{{- $actions := append $actions (makeMap "type" "button" "text" "Response Time Graph" "url" (.GraphLink .Alert.Vars.total_time)) -}}
{{- /* Rule Editor Link */ -}}
{{- $actions := append $actions (makeMap "type" "button" "text" "Alert Configuration" "url" .Rule) -}}
{{- $text := printf "%v" .Alert.Vars.slackNotes -}}
{{- if .Alert.Vars.additionalSlackNotes -}}
{{- $text = printf "%v %v" .Alert.Vars.additionalSlackNotes $text -}}
{{- end -}}
{{- /* Build attachment based on previous defined variables */ -}}
{{- $attachment := makeMap "fallback" $fallback "title" $title "text" $text "ts" $ts "color" $color "fields" $fields "actions" $actions -}}
{{- $attachments := append $attachments $attachment -}}
{{- makeMap "attachments" $attachments | json -}}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.