@wmm A few things:
-
Your “Dict” variables aren’t dicionaries, they’re records. Use brackets to define a dict:
thWarnDict = [ "t996": 200.0, "t997": 200.0, "t998": 200.0, "t999": 200.0, "t1000": 200.0 ]
thAlarmDict = [ "t996": 100.0, "t997": 100.0, "t998": 100.0, "t999": 100.0, "t1000": 100.0 ]
thCritDict = [ "t996": 75.0, "t997": 75.0, "t998": 75.0, "t999": 75.0, "t1000": 75.0 ]
hysteresisDict = [ "t996": 10.0, "t997": 10.0, "t998": 10.0, "t999": 10.0, "t1000": 10.0 ]
-
In your stateCount()
functions, you aren’t calling dict.get()
correctly. They should be:
|> stateCount(fn: (r) => (r._value >= dict.get(dict: thCritDict , key: r._field, default: defaultTH)), column: "critCount")
|> stateCount(fn: (r) => (r._value >= dict.get(dict: thAlarmDict, key: r._field, default: defaultTH)), column: "alarmCount")
|> stateCount(fn: (r) => (r._value >= dict.get(dict: thWarnDict, key: r._field, default: defaultTH)), column: "warnCount")
|> stateCount(fn: (r) => (r._value < dict.get(dict: thWarnDict, key: r._field, default: defaultTH)), column: "normalCount")
-
double()
isn’t the correct function for converting values to a float. float()
is:
messageFn = (r) => (
if r._level == "crit" then "CRITICAL (${string(v: float(v: r._value))}%)"
else if r._level == "warn" then "ALARM (${string(v: float(v: r._value))}%)"
else if r._level == "info" then "WARNING (${string(v: float(v: r._value))}%)"
else if r._level == "ok" then "NORMAL (${string(v: float(v: r._value))}%)"
else "UNDEFINED"
)
This is what the full task should look like:
import "dict"
import "influxdata/influxdb/monitor"
option task = {
name: "StatusTask",
every: 1s,
offset: 0
}
thWarnDict = [ "t996": 200.0, "t997": 200.0, "t998": 200.0, "t999": 200.0, "t1000": 200.0 ]
thAlarmDict = [ "t996": 100.0, "t997": 100.0, "t998": 100.0, "t999": 100.0, "t1000": 100.0 ]
thCritDict = [ "t996": 75.0, "t997": 75.0, "t998": 75.0, "t999": 75.0, "t1000": 75.0 ]
hysteresisDict = [ "t996": 10.0, "t997": 10.0, "t998": 10.0, "t999": 10.0, "t1000": 10.0 ]
defaultTH = 9999999999
statusData =
from(bucket: "oceanTest")
|> range(start: -1m)
|> filter(fn: (r) => (r["_measurement"] == "trends"))
|> filter(fn: (r) => (r["ptId"] == "331"))
|> drop(columns: ["_start", "_stop"])
|> group(columns: ["_field", "ptid", "_measurement"])
|> stateCount(fn: (r) => (r._value >= dict.get(dict: thCritDict , key: r._field, default: defaultTH)), column: "critCount")
|> stateCount(fn: (r) => (r._value >= dict.get(dict: thAlarmDict, key: r._field, default: defaultTH)), column: "alarmCount")
|> stateCount(fn: (r) => (r._value >= dict.get(dict: thWarnDict, key: r._field, default: defaultTH)), column: "warnCount")
|> stateCount(fn: (r) => (r._value < dict.get(dict: thWarnDict, key: r._field, default: defaultTH)), column: "normalCount")
//|> yield(name: "status")
crit = (r) => (r["critCount"] > dict.get(dict: hysteresisDict, key: r._field, default: defaultTH))
alarm = (r) => (r["alarmCount"] > dict.get(dict: hysteresisDict, key: r._field, default: defaultTH))
warn = (r) => (r["warnCount"] > dict.get(dict: hysteresisDict, key: r._field, default: defaultTH))
normal = (r) => (r["normalCount"] > dict.get(dict: hysteresisDict, key: r._field, default: defaultTH))
messageFn = (r) => (
if r._level == "crit" then "CRITICAL (${string(v: float(v: r._value))}%)"
else if r._level == "warn" then "ALARM (${string(v: float(v: r._value))}%)"
else if r._level == "info" then "WARNING (${string(v: float(v: r._value))}%)"
else if r._level == "ok" then "NORMAL (${string(v: float(v: r._value))}%)"
else "UNDEFINED"
)
check = {
_check_id: "statusTask_00001",
_check_name: "StatusTask",
_type: "custom",
tags: {},
}
statusData
|> monitor.check(
crit: crit,
warn: alarm,
info: warn,
ok: normal,
messageFn: messageFn,
data: check
)