Hi @Anaisdg ,
Thanks for the reply! i have tried using the code you have sent, so this is my steps taken:
I have already implemented your code and tried it, so these are the error i got.
First, when i enter the code into a script editor, i get this error back and not quite sure why this is happening even though yours works.
Internal error has errored - check server logs
Secondly , i run the code as a task and sometimes it works and sometimes it doesn’t. It is not very consistent in sending message to my telegram , even though my value is more than 0.
I am also trying to use this script as a task , but as you can see from the Task logs , you can see that there is also an error I’m not quite sure myself too as from the pictures below.
Would appreciate it if you can guide me along, Thank you!
import “contrib/sranka/telegram”
import “array”
option v = {field: “humidity”, timeRangeStart: -1h, timeRangeStop: now(), windowPeriod: 10000ms}
option task = {name: “name-assigned”, every: 5s}
data =
from(bucket: “My bucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “Mymeasurement”)
|> filter(fn: (r) => r["_field"] == “Myfield”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)
|> last()
Alert =
data
|> map(
fn: (r) =>
({r with level:
if r._value > 0 then
“critical”
else
“normal”,
}),
)
|> yield(name: “alert”)
Alertextract =
Alert
|> findRecord(fn: (key) => true, idx: 0)
if Alertextract.level == “critical” then
telegram.message(
url: “https://api.telegram.org/bot”,
token: “Mytoken”,
channel: “MyChannel”,
text: “CRIT”,
parseMode: “MarkdownV2”,
disableWebPagePreview: false,
silent: true,
)
else
0
array.from(rows: [{foo: 0}])
|> to(bucket: “Mybucket”, org: “MyOrganization”)