I created a simple alert in kapacitor, but this alert don't work

Hi,

I created a simple alert in kapacitor, but this alert don’t work.
I don’t find the error logs in kapacitor.

In my test, I created the alert using the chronograf interface.

ID Type Status Executing Databases and Retention Policies
chronograf-v1-7953f726-5e2c-40f5-9490-c9c7e3050775 stream enabled true [“chronograf”.“autogen”]
chronograf-v1-a4b7550a-7290-47fd-a3a0-2f460bfed025 stream enabled true [“telegraf”.“autogen”]

kapacitor show chronograf-v1-7953f726-5e2c-40f5-9490-c9c7e3050775
ID: chronograf-v1-7953f726-5e2c-40f5-9490-c9c7e3050775
Error:
Template:
Type: stream
Status: enabled
Executing: true
Created: 16 Dec 19 17:39 -0200
Modified: 16 Dec 19 17:42 -0200
LastEnabled: 16 Dec 19 17:42 -0200
Databases Retention Policies: [“chronograf”.“autogen”]
TICKscript:
var db = ‘chronograf’

var rp = ‘autogen’

var measurement = ‘m5’

var groupBy =

var whereFilter = lambda: TRUE

var name = ‘Untitled Rule’

var idVar = name

var message = ‘TTTTT’

var idTag = ‘alertID’

var levelTag = ‘level’

var messageField = ‘message’

var durationField = ‘duration’

var outputDB = ‘chronograf’

var outputRP = ‘autogen’

var outputMeasurement = ‘alerts’

var triggerType = ‘threshold’

var crit = 2000

var data = stream
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|eval(lambda: “value”)
.as(‘value’)

var trigger = data
|alert()
.crit(lambda: “value” >= crit)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.stateChangesOnly()
.slack()
.workspace(‘T’)

trigger
|eval(lambda: float(“value”))
.as(‘value’)
.keep()
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag(‘alertName’, name)
.tag(‘triggerType’, triggerType)

trigger
|httpOut(‘output’)

DOT:
digraph chronograf-v1-7953f726-5e2c-40f5-9490-c9c7e3050775 {
graph [throughput=“0.00 points/s”];

stream0 [avg_exec_time_ns=“0s” errors=“0” working_cardinality=“0” ];
stream0 -> from1 [processed=“0”];

from1 [avg_exec_time_ns=“0s” errors=“0” working_cardinality=“0” ];
from1 -> eval2 [processed=“0”];

eval2 [avg_exec_time_ns=“0s” errors=“0” working_cardinality=“0” ];
eval2 -> alert3 [processed=“0”];

alert3 [alerts_inhibited=“0” alerts_triggered=“0” avg_exec_time_ns=“0s” crits_triggered=“0” errors=“0” infos_triggered=“0” oks_triggered=“0” warns_triggered=“0” working_cardinality=“0” ];
alert3 -> http_out6 [processed=“0”];
alert3 -> eval4 [processed=“0”];

http_out6 [avg_exec_time_ns=“0s” errors=“0” working_cardinality=“0” ];

eval4 [avg_exec_time_ns=“0s” errors=“0” working_cardinality=“0” ];
eval4 -> influxdb_out5 [processed=“0”];

influxdb_out5 [avg_exec_time_ns=“0s” errors=“0” points_written=“0” working_cardinality=“0” write_errors=“0” ];
}

I using:

influxd version
InfluxDB v1.7.8 (git: 1.7 ff383cdc0420217e3460dabe17db54f8557d95b6)

kapacitor version
Kapacitor OSS 1.5.3 (git: HEAD e6bc51b8447de450c3f6fc0f6e47b6a0987ce5b6)

Hey @afonsorodrigues

It looks like your alert script is monitoring the chronograf database. This is usually where the alerts would be saved once generated, hence no data being processed in the DOT output.

If you edit your script and replace
var db = chronograf
with
var db = telegraf

Telegraf is the default database created by the telefgraf agent, so your metrics will be in there. You stream the data from the telegraf database, generate your alert which is then written back to the chronograf database.

If you have called your database something else then use that one :slight_smile:

Hope that helps

Hi @philb,
Thank’s for you update.

But I generate my metrics in database chronograf.
I create my rule using the interface.
I send the new script with the same behavior

var db = ‘chronograf’

var rp = ‘autogen’

var measurement = ‘m5’

var groupBy =

var whereFilter = lambda: TRUE

var name = ‘M5’

var idVar = name

var message = ‘Oi {{.ID}}’

var idTag = ‘alertID’

var levelTag = ‘level’

var messageField = ‘message’

var durationField = ‘duration’

var outputDB = ‘chronograf’

var outputRP = ‘autogen’

var outputMeasurement = ‘alerts’

var triggerType = ‘threshold’

var crit = 800

var data = stream
|from()
.database(db)
.retentionPolicy(rp)
.measurement(measurement)
.groupBy(groupBy)
.where(whereFilter)
|eval(lambda: “value”)
.as(‘value’)

var trigger = data
|alert()
.crit(lambda: “value” > crit)
.message(message)
.id(idVar)
.idTag(idTag)
.levelTag(levelTag)
.messageField(messageField)
.durationField(durationField)
.exec(‘echo’, ‘“Test”’, ‘>>’, ‘/tmp/log’)
.log(’/tmp/alerts.log’)
.slack()
.channel(’#automation’)
.username(‘afonsoaugustoventura’)

trigger
|eval(lambda: float(“value”))
.as(‘value’)
.keep()
|influxDBOut()
.create()
.database(outputDB)
.retentionPolicy(outputRP)
.measurement(outputMeasurement)
.tag(‘alertName’, name)
.tag(‘triggerType’, triggerType)

trigger
|httpOut(‘output’)