Usage of variable in deadman.details() method

kapacitor
#1

Hello,
I want to send alert email that indicates what environment I am in. I would like to use variable in html template.

From the description of details node I found I can access variable using Tags or Fields. Now I set the variable in tags using default() . tag(,) variable. I am able to access the variable in alert Node but not in the deadman node. Can anyone help me with that?

Below is my working tickscript

dbrp “telegraf”.“autogen”

var info=70

var warn =80

var crit =10

var period =20s

var every =20s

var landscape= ‘Sandbox’

var data=stream

|from()

    .measurement('cpu')

    .groupBy('host')

    .where(lambda: "cpu" == 'cpu-total' AND isPresent("usage_idle") )

data

|eval(lambda:100.0 - "usage_idle")

    .as('used')

|window()

    .period(period)

    .every(every)

|mean(‘used’)

    .as('stat')

|default()

.tag('landscapeTag',landscape)

|log()

|alert()

    .warn(lambda: "stat" > warn)

    .crit(lambda: "stat" > crit)

    .id('{{ index .Tags "host" }}')

    .message('Landscape - {{index .Tags "landscapeTag"}} :: HOST - {{.ID}} :: CPU USAGE is at {{.Level}} level.')

    .details('''

    <h2>CPU USAGE ALERT </h2>

    <div>HOST - {{.ID}} </br>

    Landscape - {{index .Tags "landscapeTag"}} </br>

     CPU USAGE is <b> {{ index .Fields "stat"}} </b> which is at <b> {{.Level}} </b> level.</div>

    ''')

    .stateChangesOnly(5m)

// Send alerts to the cpu topic

    .topic('cpu')

----------Output: alert in email --------

CPU USAGE ALERT
HOST - ip-172-31-87-132
Landscape - Sandbox
CPU USAGE is 0.7000000006519258 which is at OK level.

Below is not working tickscript:

dbrp “telegraf”.“autogen”

var threshold = 1.0

var interval =30s

var landscape= ‘Sandbox’

var data=stream

|from()

    .measurement('cpu')

    .groupBy('host')

    .where(lambda: "cpu" == 'cpu-total' AND isPresent("usage_idle") )

data

|default()

    .tag('xyz',landscape)

|log()

var log = data

|deadman(threshold,interval)

    .id('{{ index .Tags "host" }}')

    .message('Landscape - {{ index .Tags "xyz" }} :: Host - {{ .ID }} :: Telegraf Agent  is {{ if eq .Level "OK" }}ONLINE {{ else }}OFFLINE{{ end }} ')

    .details('''

    <h2>TELEGRAF AGENT STATUS ALERT </h2>

      Landscape - {{ index .Tags "xyz" }}

     </br>Telegraf Agent on HOST: <b> {{.ID}} </b>

    </br> <b>

    {{ if eq .Level "OK" }} Info: Telegraf available  {{ else }} Error: Telegraf disabled or defective.  {{ end }}  </b>
    ''')

     .topic('cpu')

.log(’/var/log/kapacitor/alerts.log’)

// .stateChangesOnly(2m)

------------Output : alert in email--------

TELEGRAF AGENT STATUS ALERT
Landscape -
Telegraf Agent on HOST: ip-172-31-87-132
Error: Telegraf disabled or defective.

Kindly let me know if you need more clarification. Thank You!

Regards,
Sagar Mehta