Generated checks fail when checking data

Hello,

I have a python script which generates influx(v2.4.0) checks. When these checks receive data to check, their last run status switches to failed:

image

When opening the failed check for editing, 2 messages are shown, but I’m quite sure those criteria are fulfilled:

image

Picture of my query:
image

I tried resolving the second error by using those range parameters, but none worked:

  • |> range(start: -5s)*
  • |> range(start: -5s, stop: -0s)*
  • |> range(start: v.timeRangeStart, stop: v.timeRangeStop)*

I have also created the same check manually and compared their code(as tasks) and besides check_name & check_id it is identical.

This is the generated check as a task(edit mode)

I don’t think it is relevant to include, but here is a part of my python script which creates the check to be written.

Also, Last run status switches to “Task run successfully!” when not recieving data, which is quite misleading.

Am I missing anything? A big thanks in advance.

Could you also please include an example of writing the check from python with the query parameter edit mode on: QueryEditMode.BUILDER? Thank you.

Hello @_OD,
I would use the requests library to create a task with python.
Perhaps an easier example is just using cURL.

https://www.influxdata.com/blog/getting-started-influxdb-2-0-api-postman/
curl --location --request POST 'https://us-west-2-1.aws.cloud2.influxdata.com/api/v2/tasks' \

--header 'Authorization: Token Bxxxxxx==' \

--header 'Content-Type: application/json' \

--data-raw '{

"orgID": "04xxxxx0",

"status": "active",

"flux": "option task = {name: \"mytask\", every: 10m, offset: 1m}\n from(bucket: \"system\")\n |> range(start: -task.every)\n |> filter(fn: (r) => r[\"_measurement\"] == \"cpu\")\n |> filter(fn: (r) => r[\"_field\"] == \"usage_user\")\n |> filter(fn: (r) => r[\"cpu\"] == \"cpu-total\")\n |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)\n |> to(bucket: \"test\")\n",

"description": "downsamples total cpu usage_user data into 5m averages every 10m"

}'

I don’t see this option anywhere in the API
https://docs.influxdata.com/influxdb/v2.0/api/#operation/PostTasks

Can you point me to what you’re talking about?
Thank you