Newer
Older
var db string // database per service function chain, so db is named after sfc
var rp = 'autogen' // default value for the retention policy
var measurement string
var influxFunction string
var whereClause = 'TRUE' // default value is TRUE, hence no filtering of the query result
var messageValue = 'TRUE' // default value is TRUE, as this is what SFEMC expects as a notification for an event rule
var comparisonLambda lambda // comparison function e.g. "diff" > 40
var alertPeriod duration
var topicID string
var current = batch
|query('SELECT ' + influxFunction + '(' + field + ') AS value FROM "' + db + '"."' + rp + '"."' + measurement + '" WHERE ' + whereClause)
.period(alertPeriod)
.every(alertPeriod)
var past = current
.offset(alertPeriod)
| shift(alertPeriod)
past
.as('past', 'current')
| eval(lambda: float("current.value" - "past.value"))
.as('diff')
| alert()
.id(topicID)
.details('db=' + db + ',measurement=' + measurement)
.crit(comparisonLambda)
.message(messageValue)
.topic(topicID)
.noRecoveries()