influxdata / influxdata/kapacitor

Tag values not visible from Kapacitor Template

Open
#1,882 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

Hi,

We are using Template and YAML file to create alerts. Alerts are working fine but messages is missing information related to tags.
Following is the template that I have created

```
// /usr/share/kapacitor/templates/database_template.tick

var measurement string
var where_filter = lambda: TRUE
var groups = [*]
var field string
var warn lambda
var crit lambda
var period_val duration
var every_val duration
var email_id string
var message_val = '{{.Level}}: {{.TaskName}} at {{ index .Fields "mean" }} - Host: {{ index .Tags "host" }}'
var details_val = 'Alert Level - {{.Level}}
Alert Name - {{.TaskName}}
Current Value - {{ index .Fields "mean" }}
Tags - {{.Group}}
Host - {{ index .Tags "host" }}'

stream
|from()
.measurement(measurement)
.where(where_filter)
.groupBy(groups)
|window()
.period(period_val)
.every(every_val)
|mean(field)
|alert()
.warn(warn)
.crit(crit)
.message('{{ index .Tags "host" }}')
.details(details_val)
.email(email_id)
```

Following is the YAML file

```
# /usr/share/kapacitor/tasks/asm_test_alert.tick
dbrps:
- { db: "telegraf", rp: "autogen"}
template-id: database_template
vars:
measurement:
type: string
value: AsmSpaceUtilization
groups:
type: list
value:
- type: string
value: db_name
- type: string
value: dg_name
period_val:
type: duration
value: 10s
every_val:
type: duration
value: 10s
field:
type: string
value : used_pct
warn:
type: lambda
value: "\"mean\" > 40.0"
crit:
type: lambda
value: "\"mean\" > 50.0"
email_id:
type: string
value: "advaitvdeo@yahoo.com"
```

When I get email alert, I see following in subject

OK: asm_test_alert at 32 - Host:

Its not printing host value when I am using following reference in message - {{ index .Tags "host" }}

Email body shows following

Alert Level - OK
Alert Name - asm_test_alert
Current Value - 32
Tags - db_name=orcl,dg_name=ORCL_DG
Host -

Here also host value is not getting printed.
Am I referring the host tag correctly? or we have a different way to refer host tag?
Same thing works when I directly write TICK script instead of using template.

Regards

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with /usr/share/kapacitor/templates/database_template.tick and /usr/share/kapacitor/tasks/asm_test_alert.tick, then compare their alert rendering with the direct TICK script that works. Trace how template alerts populate .Tags and verify the rendered subject and body include the host tag; done means the template produces the expected host value.

Written by the indexing model from the issue text.

Assessment

Tech stack
yaml
Domain
observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.