I’ve written following TICK script which should alert if UPS External Temperature goes below or above threshold.
The script doesn’t produce any errors and I’ve verified that the measurement contains data.
What I’m doing wrong here?
Kapacitor OSS 1.5.3 (git: HEAD e6bc51b8447de450c3f6fc0f6e47b6a0987ce5b6)
> SELECT external.temperature FROM ups WHERE hostname='ups2' AND time > now() - 120s
name: ups
time external.temperature
---- --------------------
1571401760000000000 5
1571401770000000000 5
1571401780000000000 5
1571401790000000000 5
1571401800000000000 5
1571401810000000000 5
1571401820000000000 5
1571401830000000000 5
1571401840000000000 5
1571401850000000000 5
1571401860000000000 5
dbrp "telegraf"."autogen"
// Select ups external temperature
stream
|from()
.measurement('ups')
.groupBy('hostname')
|eval(lambda: "external.temperature" / 10)
.as('temperature')
|stateDuration(lambda: "temperature" < 8)
.unit(1m)
.as('warnDuration')
|stateDuration(lambda: "temperature" < 4)
.unit(1m)
.as('critDuration')
|stateDuration(lambda: "temperature" > 30)
.unit(1m)
.as('warnDuration')
|stateDuration(lambda: "temperature" > 35)
.unit(1m)
.as('critDuration')
|alert()
.pagerDuty2()
.routingKey('xxxxxxx')
.link('https://graphs.jus.si/d/000000001/ups?orgId=1&refresh=10s&fullscreen&panelId=11&from=now-1h&to=now', 'UPS Dashboard')
.warn(lambda: "warnDuration" > 1)
.crit(lambda: "critDuration" > 1)
.stateChangesOnly()
.message('{{ .Level }}: UPS {{ index .Tags "hostname" }} external temperature is {{ index .Fields "temperature" }}°C')
DOT:
digraph ups_external_temperature_alert {
graph [throughput="0.00 points/s"];
stream0 [avg_exec_time_ns="0s" errors="0" working_cardinality="0" ];
stream0 -> from1 [processed="20"];
from1 [avg_exec_time_ns="1.345µs" errors="0" working_cardinality="0" ];
from1 -> eval2 [processed="20"];
eval2 [avg_exec_time_ns="0s" errors="0" working_cardinality="2" ];
eval2 -> state_duration3 [processed="20"];
state_duration3 [avg_exec_time_ns="8.776µs" errors="0" working_cardinality="2" ];
state_duration3 -> state_duration4 [processed="20"];
state_duration4 [avg_exec_time_ns="2.167µs" errors="0" working_cardinality="2" ];
state_duration4 -> state_duration5 [processed="20"];
state_duration5 [avg_exec_time_ns="5.781µs" errors="0" working_cardinality="2" ];
state_duration5 -> state_duration6 [processed="20"];
state_duration6 [avg_exec_time_ns="5.47µs" errors="0" working_cardinality="2" ];
state_duration6 -> alert7 [processed="20"];
alert7 [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="2" ];
}
ID: main:ups_external_temperature_alert:alert7
Level: OK
Collected: 0
Handlers: []
Events:
Event Level Message Date