Hi!
I have the following FLUX Query running in a Task every minute!
When i run the query with |>yield() in “Explorer” it works as desired.
In a scheduled task i got the following error message:
“could not execute task run: runtime error @64:5-71:3: check: found column “_field” in the group key; experimental.to() expects pivoted data”
Can someone explaine this behaviour?
import "dict"
import "influxdata/influxdb/monitor"
option task = {name: "StatusTaskDict", every: 1m}
check = {
_check_id: "statusTask_00002",
_check_name: "StatusTask",
_type: "custom",
tags: {},
}
hysteresis = 10
defaultTH = 0.0
thCritDict = [
"t11": 200.0,
"t12": 200.0,
"t13": 200.0,
"t14": 200.0,
"t15": 200.0,
]
thAlarmDict = [
"t11": 100.0,
"t12": 100.0,
"t13": 100.0,
"t14": 100.0,
"t15": 100.0,
]
thWarnDict = [
"t11": 75.0,
"t12": 75.0,
"t13": 75.0,
"t14": 75.0,
"t15": 75.0,
]
statusData = from(bucket: "oceanTest-short")
|> range(start: 0)
|> tail(n: hysteresis, offset: 0)
|> 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")
crit = (r) =>
(r["critCount"] > hysteresis)
alarm = (r) =>
(r["alarmCount"] > hysteresis)
warn = (r) =>
(r["warnCount"] > hysteresis)
normal = (r) =>
(r["normalCount"] > hysteresis)
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")
statusData
|> monitor.check(
crit: crit,
warn: alarm,
info: warn,
ok: normal,
messageFn: messageFn,
data: check,
)