Receiving 2 email alerts for an event
I have setup an alert rule with a check on the cpu usage > 40% I am receiving 2 emails with different levels (CRITICAL when the threshold is crossed i.e. > 40%) and OK when the usage comes back to normal i.e. < 40%. What I really want is, receive a single email when the CPU usage crosses 40%. Please help me.
Tick Script generated using chronograf:
var db = 'sample'
var rp = 'default_rp'
var measurement = 'cpu'
var groupBy = []
var whereFilter = lambda: TRUE
var name = 'cpu_test'
var idVar = name
var message = ''
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 crit = 40
var data = stream |from() .database(db) .retentionPolicy(rp) .measurement(measurement) .groupBy(groupBy) .where(whereFilter) |eval(lambda: "usage_user") .as('value')
var trigger = data |alert() .crit(lambda: "value" > crit) .stateChangesOnly() .message(message) .id(idVar) .idTag(idTag) .levelTag(levelTag) .messageField(messageField) .durationField(durationField) .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')
Thank you for posting an issue. Please take a look at https://github.com/influxdata/kapacitor/issues/1567 , it seems the same.
You can also try to remove .stateChangesOnly() and modify var whereFilter = lambda: ("usage_user" > 40)
You can also try to remove
.stateChangesOnly()and modifyvar whereFilter = lambda: ("usage_user" > 40)
Hi, I tried this approach but in this case I just received a single alert when the usage crossed 40%. After sometime it came back to normal. But, the next time when it crossed 40%, there was no alert triggered. Can you figure out the reason behind this?
That would most likely indicate that stateChangesOnly() was not removed or it does not work as documented in https://docs.influxdata.com/kapacitor/v1.5/nodes/alert_node/#statechangesonly . Feel free to ask at https://community.influxdata.com/ .