Hi,
I have two alert nodes in one script, one which checks CPU over 10 minutes and another that sends an alert if no data is receveived. I’d like to assign a variable based on which alert is sent and use this in the alert message to alter the text depending on the alert.
The alerts are fired as:
Critical = CPU > 90% for 10 minutes
Warn = Deadman no througput for 2 minutes
Then the OK state when everything is back to normal. I’m using the
{{if eq .Level "CRIT}} {{ELSE IF ex .Level “WARN”}} {{ELSE}}
template syntax to customise the message based on whether it is a critical alert or not.
These both alert fine, but there is no distinguishing between whether the OK message was related to the deadman or the critical alert. I would like to assign a variable to each alert node so that when the alert is fired and comes back to the OK state i can change the text in the message to reflect this.
var trigger = data
|alert()
.crit(lambda: "state_duration" >= 10)
.stateChangesOnly()
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.details(details)
**var type = "general"**
var deadman = data
|stats(2m)
.align()
|derivative('emitted')
.unit(2m)
.nonNegative()
// |stateCount(lambda: "emitted" <= 0.0)
// .as('DeadCount')
|alert()
.warn(lambda: "emitted" <= 0.0)
.stateChangesOnly()
.details(details)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
**var type = "deadman"**
where the variable “type” is sent only when that node sends an alert.
Then in the alert message in the {{ eq .Level “OK” }} i can use the variable to work out what text to show.
I did try to do this but i get the error:
invalid TICKscript: name "type" is undefined. Names in scope: stream,db,measurement,idVar,time,rp,groupBy,whereFilter,name
I know assigning the variable at the top of my script will fix that error but I need to define it further down the script. Is this possible? Am i over complicating things?
Thanks
PhilB