I set up an alert using the Chronograph UI, but I only want to send it between 5PM and 10PM. I understand this is not possible with the UI, but how can I achieve it with the Tickscript? This is what Chronograph automatically created. Where do I have to define the times? In the where filter?
var db = 'DBNAME'
var rp = 'autogen'
var measurement = 'device_frmpayload_data_co2_ppm'
var groupBy = ['device_name']
var whereFilter = lambda: ("dev_eui" != 'SERIAL' OR "dev_eui" != 'SERIAL' OR "dev_eui" != 'SERIAL')
var name = 'ppm > 800'
var idVar = name + '-{{.Group}}'
var message = 'Alert {{ index .Tags "device_name" }} - CO2 is {{.Level}}'
var idTag = 'alertID'
var levelTag = 'level'
var messageField = 'message'
var durationField = 'duration'
var outputDB = 'chronograf'
var outputRP = 'autogen'
var outputMeasurement = 'alerts'
var triggerType = 'threshold'
var details = 'HTML data'
var crit = 800
var data = stream
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|eval(lambda: "value")
.as('value')
var trigger = data
|alert()
.crit(lambda: "value" > crit)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.details(details)
.email()
.to('EMAIL')
trigger
|eval(lambda: float("value"))
.as('value')
.keep()
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag('alertName', name)
.tag('triggerType', triggerType)
trigger
|httpOut('output')
have you tried a similar lambda expression with the time filter in the .critReset() or the .info() properties of alert ?
I use this code snippit to alert based on different thresholds for different times of day. So I can have different ok,warn,crit thresholds for standard times and exception times. This means I can tune the alerts per time of day.
Starttime_of_standard_alerting and endtime_of_standard_alerting are integer values representing hours eg. 9 and 17 to alert during the day.
|alert()
.crit(lambda: ("value" >= standard_critical_threshold AND (hour("time") >= starttime_of_standard_alerting AND hour("time") < endtime_of_standard_alerting)) OR
("value" >= exception_critical_threshold AND (hour("time") < starttime_of_standard_alerting OR hour("time") >= endtime_of_standard_alerting)))
.warn(lambda: ("value" >= standard_warning_threshold AND (hour("time") >= starttime_of_standard_alerting AND hour("time") < endtime_of_standard_alerting)) OR
("value" >= exception_warning_threshold AND (hour("time") < starttime_of_standard_alerting OR hour("time") >= endtime_of_standard_alerting)))
.warnReset(lambda: ("value" < standard_warning_threshold AND (hour("time") >= starttime_of_standard_alerting AND hour("time") < endtime_of_standard_alerting)) OR
("value" < exception_warning_threshold AND (hour("time") < starttime_of_standard_alerting OR hour("time") >= endtime_of_standard_alerting)))