influxdata / influxdata/kapacitor

Unable to read the value from string template

Open
#2,293 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.4k
Forks
479
Avg merge
4d 16h
Merged PRs (30d)
4

Description

Hi, I've a tickscript. It works fine but I'd want to pass and read the string templates, those wrapped in the curly braces together when I execute the python script.

```
var message = 'ALERT! CHECK YOUR {{ index .Tags "hostname" }}
EXPECTED VALUE: {{ index .Fields "past.p" }} | CURRENT VALUE: {{ index .Fields "current.c" }} '

var current = batch
|query('SELECT non_negative_derivative(mean("ifHCInUcastPkts"), 5m) AS "c" FROM "router-test"."autogen"."interface" WHERE time > now() - 30m AND time < now() GROUP BY time(5m)')
.period(30m)
.every(5m)
.groupBy(time(5m), *)
.align()
|where(lambda: "hostname" == 'router1')

var past = batch
|query('SELECT non_negative_derivative(mean("ifHCInUcastPkts"), 5m) AS "p" FROM "router-test"."autogen"."interface" WHERE time > now() - 1h AND time < now() GROUP BY time(5m)')
.period(1h)
.every(5m)
.groupBy(time(5m), *)
.align()
|where(lambda: "hostname" == 'router1')

var trigger = past
|join(current)
.as('past', 'current')
|eval(lambda: float("current.c" - "past.p"))
.keep()
.as('value')
|alert()
.crit(lambda: "value" > 100)
.exec('/usr/bin/python', 'dosth.py', message)
```

**desired result**: message is sent to my python script and is able to display the text from python as
'ALERT! CHECK YOUR router1, EXPECTED VALUE: 200 | CURRENT VALUE: 400 '

**current result**: message is displayed as it is from python.
'ALERT! CHECK YOUR {{ index .Tags "hostname" }}
EXPECTED VALUE: {{ index .Fields "past.p" }} | CURRENT VALUE: {{ index .Fields "current.c" }} '

I'm new to this, please help. Thank you

Contributor guide

Open the contributing guide

Research direction

Start with the alert().exec('/usr/bin/python', 'dosth.py', message) call in the Tickscript and inspect how dosth.py receives its argument. Reproduce the alert with the shown message template, then verify that the script receives rendered tag and field values rather than the literal template text.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, python
Domain
observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.