Kapacitor: Include field in message


I use the following tick script. Alerting works fine, but I want to include a field “info” which is part of the triggering data point in the measurement. It’s filled with some text and it’s not printed in my alert message, it’s always empty. Seems like I can only include fields and tags which are part of the query. I thought I can access it with {{ index .Fields “info” }}, but it does not work.

How can I include fields in my message details which belong to the datapoint?

var db = 'influx_db'

var rp = 'autogen'

var measurement = 'monitoring'

var groupBy = ['myid', 'environment']

var whereFilter = lambda: TRUE

var name = 'monitoring_email'

var idVar = name + '-{{.Group}}'

var message = '*** {{.Level}} ***  -  {{ index .Tags "mylocation" }}-{{ index .Tags "environment" }}-{{ index .Tags "myid" }}'

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 = '
<p>*** <b>{{.Level}}</b> *** </p>

<p> Info: {{ index .Fields "info" }} </p>

    <td>{{ index .Tags "myid" }}</td>
    <td>{{ index .Fields "mylocation" }}</td>
    <td>{{ index .Tags "environment" }}</td>

<p> Time: {{ .Time.Local.Format "Mon, Jan 2 2006 at 15:04:05 UTC" }} </p>

var crit = 0

var data = stream
    |eval(lambda: "result_code")

var trigger = data
        .crit(lambda: "value" > crit)

    |eval(lambda: float("value"))
        .tag('alertName', name)
        .tag('triggerType', triggerType)


If ‘info’ appears in your measurement you might need to evaluate it first.

 |eval(lambda: "result_code")


 |eval(lambda: "result_code",
       lambda: "info")

That did the trick. Thank you!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.