I created the attached TickScript, which is streaming incoming data with an interval of 1m and evaluating the field myField in order to create an info, warn and crit alert.
As I said, it is triggering the INFO,WARN and CRIT alerts and OK from state recovering correctly, but I need to get the current status and not only when the status is changed or an alert has triggered.
With the following TickScript, the output is:
The results:
Log is empty until an alert is triggered/recovered
Threshold alert httpOut is “empty” with the following message until an alert is triggered/recovered: {"series":null}
Note: I played with stateChangesOnly(), stateChangesOnly(period) without success
//TICKSCRIPT:
//================
var data = stream
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|window()
.period(period)
.every(every)
.align()
|log()
//Generates an alert, later we can handle it
var trigger = data
|alert()
//Different thresholds:
.info(lambda: field > if("threshold" == '1', info_th1, info_th2))
.warn(lambda: field > if ("threshold" == '1', warn_th1, warn_th2))
.crit(lambda: field > if ("threshold" == '1', crit_th1, crit_th2))
.message(message)
.details(details)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.log('/tmp/threshold_alert.log')
trigger
|httpOut('threshold_alert')