influxdata / influxdata/kapacitor

cannot evaluate {{ .ID}} when httppost custom template

Open
#2,149 3 comments 2 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, im fresh new to use TICK , and got this problem

description:
when use httpPostNode , config with [[httppost]] row-template,
i cannot get it works

verison (docker)

Telegraf 1.7.5-alpine
influxDB 1.7.2-alpine
Chronograf 1.7.5-alpine
Kapacitor 1.5.2

TICKScript

```
var data = stream
|from()
.database('telegraf')
.retentionPolicy('autogen')
.measurement('cpu')
.groupBy('host')
.where(lambda: "cpu" == 'cpu-total')
|eval(lambda: 100.0 - "usage_idle")
.as('used')

// Thresholds
var alert = data
|alert()
.id('{{ index .Tags "host"}}/cpu_used')
.message('{{ .ID }}:{{ index .Fields "stat" }}')
.crit(lambda: "used" > 50 )

// httpPost ---- this part goes wrong
alert
|httpPost()
.endpoint('test1')
// log ---- this log works fine
alert
.log('/tmp/cpu_alert_log.txt')
```

part of kapacitor.conf , all other keep default

```
[[httppost]]
endpoint = "test1"
url = "http://my.server.ip:port"
headers = { content-type = "application/json" }
row-template = "{{.ID}}"
```

log show error like this

```
ts=2019-01-17T10:05:21.377Z lvl=error msg="failed to POST data" service=kapacitor task_master=main task=chronograf-v1-1328cf35-90fb-41ec-a24b-bc5caf496e27 node=http_post4 err="failed to execute template: template: body:1:2: executing \"body\" at <.ID>: can't evaluate field ID in type *kapacitor.mappedRow"
```

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

Reproduce the failure with the supplied TICKScript and the [[httppost]] row-template configuration. Start at the httpPostNode template handling and the mappedRow error, then verify the expected .ID behavior by checking the resulting POST output; done means the supplied template no longer fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.