Message customisation based on level

Hello.

I’m trying to make generated messages more human friendly and understandable.
It is possible to customise email body based on level?
For example:

var details = '
<table border="1" bgcolor="{{color}}">
  <tr><td>Name</td><td>{{.ID}}</td></tr>
  ....
</table>'

var data = batch
    |query('''SELECT mean(used_percent) AS stat FROM "telegraf"."autogen"."disk" WHERE path = '/home' ''')
        .period(period)
        .every(every)
        .groupBy('host')
  • if level is warning - set bgcolor to yellow for details
  • if level is critical - set bgcolor to red for details

I saw there is a conditional ‘if’ function, but I can’t figure out how to apply it.

Thank you in advance.

UPD: actually I was thinking maybe there IS ready-to-use templates publicly available? I’m pretty sure very small amount of ppl just stick with default JSON body.

Us can use go templating language to alter the details. I do the following for message() but should be the same "{{if eq .Level “}}” would be the functionality you need.

.message(string(alert_header) + '
        Host \'{{ index .Tags "host" }}\'
        Normalized \'load5\' is at an average of {{ index .Fields "_value_normalized" | printf "%0.2f" }} over a window of ' +string(system_load5_window_period)+ '
        Expecting < {{ if eq .Level "CRITICAL" }}' + string(system_load5_critical_level) + '{{ else }}' + string(system_load5_warn_level) + '{{ end }}
        Raw load5 average is {{ index .Fields "_mean" | printf "%0.2f" }} over {{ index .Fields "_n_cpus"}} cpus
        <' + string(system_load5_graph_url) + '|Grafana>')