Hi There,
Hoping someone can help out. I have an API where I wish to only pull the last array using slice and convert the attribute within the array from a string to integer using lookup. Below is the code:
{ "prtg": { "result": [ { "channel": "Status" , "value": lookup($[-1:].state, "success") } ] } }
Unfortunately, I am getting an error within PRTG of the following:
Could no evaluate channel value of Status: expected type string for parameter 0 but got []interface {}.
Any assistance would be greatly appreciated!
Thanks, JT
Article Comments
Hi Dariusz,
Thanks for the reply, as per your request, please see below for the requested JSON response.
[ { "dag_id": "XXXXXXXX", "dag_run_url": "/admin/airflow/graph?dag_id=XXXXXXX", "execution_date": "2019-10-02T01:11:38.874792+00:00", "id": 3884, "run_id": "trig__2019-10-02T01:11:22.551921+00:00", "start_date": "2019-10-02T01:11:38.920380+00:00", "state": "failed" }, { "dag_id": "XXXXXXXX", "dag_run_url": "/admin/airflow/graph?dag_id=XXXXXXX", "execution_date": "2019-10-02T23:01:37.759540+00:00", "id": 3928, "run_id": "trig__2019-10-02T23:01:24.147478+00:00", "start_date": "2019-10-02T23:01:37.791189+00:00", "state": "success" }, { "dag_id": "XXXXXXXX", "dag_run_url": "/admin/airflow/graph?dag_id=XXXXXXX", "execution_date": "2019-10-04T01:01:30.553088+00:00", "id": 3968, "run_id": "trig__2019-10-04T01:01:16.519458+00:00", "start_date": "2019-10-04T01:01:30.585654+00:00", "state": "success" }, { "dag_id": "XXXXXXXX", "dag_run_url": "/admin/airflow/graph?dag_id=XXXXXXX", "execution_date": "2019-10-08T01:01:33.733049+00:00", "id": 4106, "run_id": "trig__2019-10-08T01:01:23.879060+00:00", "start_date": "2019-10-08T01:01:33.764672+00:00", "state": "success" }, { "dag_id": "XXXXXXXX", "dag_run_url": "/admin/airflow/graph?dag_id=XXXXXXX", "execution_date": "2019-10-08T01:01:35.518944+00:00", "id": 4107, "run_id": "trig__2019-10-08T01:01:23.733985+00:00", "start_date": "2019-10-08T01:01:35.550179+00:00", "state": "failed" } ]
As you can see, I am interested in only the last array in the extract and I would like to convert the "state" attribute to an integer. Although my example only has defined 1 (Success) I intend to populate this with 2 more attributes in which I want to revert back to text using lookups within the PRTG Portal.
Hope this help you to help me! Any assistance is appreciated.
Thanks, JT
Oct, 2019 - Permalink
Hi there,
It should be possible to convert the "state" attribute to an integer.
Please let us know if you're interested to convert the state attribute for the last dag_id or for all dag_ids.
Kind regards.
Oct, 2019 - Permalink
Hi Marijan,
I would like to only pull the state attribute from the last dag_id, as those dag_ids are historical data.
Thanks for the assistance!
JT
Oct, 2019 - Permalink
Hi there,
I always get an error when I try to use both:
Could no evaluate channel value of Status: expected type string for parameter 0 but got []interface {}. |
I will check this with our development and will update as soon as I am able to.
Best regards.
Oct, 2019 - Permalink
Hi,
The dot after $. was missing, the query should be:
{ "prtg": { "result": [ { "channel": "Status" , "value": lookup($.[-1:].state, "failed", "success") } ] } } But also :
lookup($.[-1:][state], "failed", "success") should be valid.
Then in his case 0 should be the channel value.
Kind regards,
Felix Saure, Tech Support Team
Oct, 2019 - Permalink
Hi there,
In order to test and debug this, it would be the best to also offer the requested JSON. Otherwise it is not really possible to see what you try to get.
You can use Pastebin for this (if the content is too big to be posted here): https://pastebin.com
Best regards.
Oct, 2019 - Permalink