Skip to content

Instantly share code, notes, and snippets.

@kylebrandt
Created October 30, 2018 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylebrandt/85ab9ff0cb4f61394b7796e429ca25dc to your computer and use it in GitHub Desktop.
Save kylebrandt/85ab9ff0cb4f61394b7796e429ca25dc to your computer and use it in GitHub Desktop.
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