How to show all rows in details by email alert in tickscript?

kapacitor
#1

I use telegraf - logparser plugin to collect log information.
And I want to show all rows about “ERROR” or “CRITICAL” logs in email alert every file minutes.

dbrp "sandboxav"."sandboxav"
var name = 'logAlert'
var idVar = name
var message = '{{ index .Tags "host" }} : {{.ID}} - {{.Level}} - {{.Time}}'
var idTag = 'alertID'
var levelTag = 'level'
var messageField = 'message'
var durationField = 'duration'
var triggerType = 'threshold'

var details = '''<!DOCTYPE html>
<html>
<head>
<title>===== LogAlert =====</title>
</head>
<body>
<h1 style="color:red;"> {{.TaskName}} </h1>
<p> "ERROR/CRITICAL" log found. </p>
<h2>Tags</h2>
<p> host: {{ index .Tags "host" }} </p>
<p> path: {{ index .Tags "path" }} </p>
<h2>Fields</h2>
<p> total: {{ index .Fields "total" }} </p>
??? How to show all rows here ???
</body>
</html>'''

var every = 1m
var period = 1m

var crit = 0

var raw = batch
    |query('''
        select "asctime", "levelname", "name", "message"
        from "sandboxav"."sandboxav"."sandboxav_log"
        where levelname = 'ERROR' OR levelname = 'CRITICAL'
    ''')
        .every(every)
        .period(period)
        .groupBy('host', 'path')
        .align()
        .alignGroup()

var data = raw
    |count('message')
        .as('total')

var trigger = data
    |alert()
        .crit(lambda: "total" > crit)
        .message(message)
        .details(details)
        .id(idVar)
        .idTag(idTag)
        .levelTag(levelTag)
        .messageField(messageField)
        .durationField(durationField)

This what I want to show in details:

logAlert

"ERROR/CRITICAL" log found.

Tags

host: taf-controller

path: /opt/sandboxav/logs/appliance.log

Fields

total: 3

2018-08-13T02:56:19.538222202Z File:/usr/local/app/lib/sandbox/controller.py, Line:160, Exception:invalid host address

2018-08-13T02:56:19.538191269Z HTTPConnectionPool(host=‘127.0.0.1’, port=12351): Max retries exceeded with url: / (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f33c014ec10>: Failed to establish a new connection: [Errno 111] Connection refused’,))

2018-08-13T02:56:14.283464241Z HTTPConnectionPool(host=‘127.0.0.1’, port=12351): Max retries exceeded with url: / (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f33c014e1d0>: Failed to establish a new connection: [Errno 111] Connection refused’,))

Can someone help to implement this function?