Skip to content

Instantly share code, notes, and snippets.

@regel
Created December 4, 2018 15:27
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 regel/b098a6326b3bda82a05cc0718a7295b8 to your computer and use it in GitHub Desktop.
Save regel/b098a6326b3bda82a05cc0718a7295b8 to your computer and use it in GitHub Desktop.
A basic TICK script that reads anomalies and sends notifications to the default Slack channel
var model
var from_measurement
var out_db
var retention_policy
var out_measurement
var data = stream
|from()
.measurement(from_measurement)
|eval(lambda: model)
.as('model')
.keep()
var saved = data
|influxDBOut()
.database(out_db)
.retentionPolicy(retention_policy)
.measurement(out_measurement)
var pos = data
|stateCount(lambda: "is_anomaly" == TRUE)
|alert()
// Warn after 1 point
.warn(lambda: "state_count" >= 1)
// Critical after 5 points
.crit(lambda: "state_count" >= 5 AND "score" > 90.0)
.message('{{ .Time }}: Hey, unexpected situation detected by model={{ index .Fields "model" }} state=ongoing score={{ index .Fields "score" | printf "%0.3f" }}.')
.slack()
var neg = data
|stateCount(lambda: "is_anomaly" == FALSE)
|alert()
.info(lambda: "state_count" == 1)
.message('{{ .Time }}: situation back to normal model={{ index .Fields "model" }} state=finished score={{ index .Fields "score" | printf "%0.3f" }}.')
.slack()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment