# Generated checks fail when checking data

**URL:** <https://community.influxdata.com/t/generated-checks-fail-when-checking-data/27726>\
**Category:** Checks & Notifications\
**Tags:** influxdb, python, checks, tasks\
**Created:** [December 13, 2022, 8:17pm UTC](https://community.influxdata.com/t/generated-checks-fail-when-checking-data/27726 "2022-12-13T20:17:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_OD](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/_od/32/11143_2.png) [@\_OD](https://community.influxdata.com/u/_OD)\
**Post date:** [December 13, 2022, 8:17pm UTC](https://community.influxdata.com/t/generated-checks-fail-when-checking-data/27726/1 "2022-12-13T20:17:22Z")

</div>

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](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/3/33eacd063c581f9cace57dc8f163bc3d63aa18a4.png)

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

![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/b/bab58d44f43a6d850046ea3a754e084c747d4d85.png)

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/aad83a5b069e8cbff43090d96e91e179ea08fe28.png)

Picture of my query:  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/1/1abe653786899c42a945ff2c08c2315a1dc4ad4e.png)

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)

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/5/59b1dcb8aa689d5ae65d9f5b3009135d1be590ab.png)

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.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/d/dbf193d23ef89a319d66d78146b7c52ce162101c.png)

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.

---

<div class="post-metadata">

**Author:** ![\_OD](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/_od/32/11143_2.png) [@\_OD](https://community.influxdata.com/u/_OD)\
**Post date:** [December 16, 2022, 7:41pm UTC](https://community.influxdata.com/t/generated-checks-fail-when-checking-data/27726/2 "2022-12-16T19:41:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [December 21, 2022, 8:19pm UTC](https://community.influxdata.com/t/generated-checks-fail-when-checking-data/27726/3 "2022-12-21T20:19:34Z")

</div>

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

```auto
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"

}'

```

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [December 21, 2022, 8:22pm UTC](https://community.influxdata.com/t/generated-checks-fail-when-checking-data/27726/4 "2022-12-21T20:22:56Z")

</div>

> [@\_OD](#):
>
> QueryEditMode.BUILDER

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

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