What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

REST API Template using Slice and Lookup

Votes:

0

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

api prtg rest

Created on Oct 4, 2019 8:20:52 AM



Best Answer

Accepted Answer

Votes:

0

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

Created on Oct 18, 2019 6:52:42 AM by  Felix Saure [Paessler Support]



6 Replies

Votes:

0

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.

Created on Oct 4, 2019 8:32:36 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

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

Created on Oct 8, 2019 3:58:29 AM



Votes:

0

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.

Created on Oct 8, 2019 11:16:08 AM by  Marijan Horsky [Paessler Support]



Votes:

0

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

Created on Oct 10, 2019 3:09:04 AM



Votes:

0

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.

Created on Oct 14, 2019 8:55:23 AM by  Dariusz Gorka [Paessler Support]



Accepted Answer

Votes:

0

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

Created on Oct 18, 2019 6:52:42 AM by  Felix Saure [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.