Kapacitor Alerts to Discord

An example of how to send alerts to Discord with Kapacitor. Written by Craig, thanks Craig!

// Tickscript to-send cpu used (%) alerts to Discord// Databucket
var data = stream
|from()
.measurement('cpu')
.groupBy('host')
.where(lambda: "cpu" == 'cpu-total')
|eval(lambda: 100.0 - "usage_idle")
.as('used')
|window()
.period(10s)
.every(10s)
|mean('used')
.as('stat')// Thresholds
var alert = data
|alert()
.message('🔥 {{.Level}}: cpu % on host [{{ index .Tags "host"}}] = {{ index .Fields "stat" }}')
.crit(lambda: "stat" > 2)
.post()
.endpoint('discord')
.captureResponse()
# kapacitor.conf entry to-send alert messages
# to Discord endpoint webhook
[[httppost]]
  endpoint = "discord"
  url = "${DISCORD_WEBHOOK_URL}"
  headers = { "Content-Type" = "application/json" }
  alert-template = "{ \"username\": \"kapacitor\", \"content\": \"{{.Message}}\"}"

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.