Main challenge was to access .tags and fields from template to create custom json body.
ANd with alert-template you cannot access fields outside {{.Message}}, atleast what I had noticed.
Check this out for more details:
or
Solution
Use |alert node & httpPost() node in your tickscript Batch/Stream it works with both:
Note you can also add custom tags… by using default() node.
|alert()
.details(‘details’)
.crit(lambda: “cpuusage” > crit)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(‘level’)
.messageField(messageField)
.durationField(durationField)
|default()
.tag(‘folder_name’, ‘new_sd343f’)
.tag(‘dashboard_name’, ‘cpu_ds’)
.tag(‘metric_name’, ‘cpuusage’)
|httpPost()
.endpoint(‘vnexttopulse’)
.captureResponse()
2)
Use this in your kapacitor.conf
Good News for accessing Level
In alert-template-file you can access it like this: "severity": {{ if eq (.Level | print) "WARNING" }}"4"{{else if eq (.Level | print) "CRITICAL"}}"1" {{else if eq (.Level | print) "OK"}}"5"{{ end }}
Using row-template (inline)
"severity":{{range .Values}} {{ if (eq .message "WARNING")}}"3"{{else if (eq .message "CRITICAL")}}"1"{{else if (eq .message "OK")}}"0" {{ end }}{{end}}
Here you would wonder, why i have used .message… well i assigned .Level to .Message.
From tickscript:
var message = ‘{{.Level}}’
The I used it under alert node
var trigger = data
|alert()
.details(instangetag)
.crit(lambda: “value” > crit)
.warn(lambda: “value” < crit)
.message(message)