Kapacitor - Alert on same measurement but different tag generating too many alerts

From Telegraf to Kapacitor, I have one measurement that sends the value of multiple alarms that i differentiate through a tag called “io_name”. Then alert ids are generated thanks to this tag.
I have this issue that whenever an alert() is triggered on one id and the other id is OK, the alert node will behave as if there was a change of state. Is it because the .stateChangeOnly() is just tied to the measurement and not the alert id ?
Here is my code, any idea of workaround ?

var id = '{{ index .Tags "io_name"}}'

var message = '{{ .Time }}: {{.Level }} alert has been triggered for {{index .Tags "io_name"}}'

stream
    |from()
        .database('kap_telegraf')
    |alert()
        .id(id)
        .message(message)
        .crit(lambda: "value" == 1)
        .stateChangesOnly()
        .log('C:/www/kapacitor/alerts.log')
        .idTag('id')
        .messageField('message')
        .levelTag('level')        
    |delete()
        .tag('io_name')
    |where(lambda: "id" != '') 
    |influxDBOut()
        .database('telegraf')
        .retentionPolicy('autogen')

I found a solution, after .database() I added the measurement name and used .groupBy().

.measurement('triggered_alarm')
.groupBy('io_name')

Hi bnjroos, I am trying to setup Telegraf to output to Kapacitor.

I tried using the Telegraf’s outputs.influxdb plugin and set it to the port Kapacitor API server is listening on (port 9092 by default), but it did not work.

[Telegraf’s log]
2019-04-03T06:13:48Z E! [outputs.influxdb] when writing to [[httplink]:9092]: Post [httplink]:9092/write?db=telegraf&rp=autogen: dial tcp 192.168.0.77:9092: connect: connection refused

[Kapacitor’s log]
ts=2019-04-03T14:52:29.786+08:00 lvl=error msg=“failed to connect to InfluxDB, retrying…” service=influxdb cluster=kapacitor err=“Get [httplink]:9092/ping: dial tcp 192.168.0.77:9092: connect: connection refused”


[telegraf.conf]
[[outputs.influxdb]]
urls = ["[httplink]:9092"]
database = “telegraf”
retention_policy = “autogen”

[kapacitor.conf]
[[influxdb]]
enabled = true
default = true
name = “kapacitor”
urls = ["[httplink]:9092"]
username = “”
password = “”
timeout = 0


[root@xxx kapacitor]# telegraf -version
Telegraf 1.10.1 (git: HEAD a6778f46)

[root@xxx kapacitor]# rpm -qa | grep kapacitor
kapacitor-1.5.2-1.x86_64


Can I know how did you manage to get it to work?

Thanks.

You have to output to Influxdb, not Kapacitor directly.