REST API as import source won't work

Hello Icinga Community :grin:

I am totally stuck at the moment with the director import source for REST APIs.
Sadly there is no documentation about this import source and due I don’t know php, I don’t totally get the source code.

The API I am querying, provides some a JSON like this one (it’s a bit redacted):

{
    "took": 224,
    "timed_out": false,
    "_shards": {
        "total": 10,
        "successful": 10,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1418,
            "relation": "eq"
        },
        "max_score": 1.0,
        "hits": [
            {
                "_index": "some_index_name",
                "_type": "_doc",
                "_id": "some_id",
                "_score": 1.0,
                "_source": {
                    "hostname": "my-unique-host",
                    "ipv6_address": null,
                    "ip_address": "1.2.3.4",
                    "location": null
                    ......
                }
            },
            {
                "_index": "some_index_name",
                "_type": "_doc",
                "_id": "some_id",
                "_score": 1.0,
                "_source": {
                    "hostname": "my-unique-host",
                    "ipv6_address": null,
                    "ip_address": "123.123.123.123",
                    "location": null
                    ......
                }
                
            }
        ]
    }
}

Now I’ trying to get the the data like this into Icinga:

The query seems to work, because checking for changes works and import run also works:

But on the tab Preview no data are displayed:
image

I also tried to test other values in “Key column name”, like “_source.hostname” or just “_source”. Doesn’t work and also seems wrong to me. And for “Extract property” I also tried “hits.hits._source” but than I got an error:

Does anyone have any idea what I am doing wrong here?

My Versions:

  • Director version (System - About): 1.10.2
  • Icinga Web 2 version and modules (System - About): 1.10.2
  • Icinga 2 version (icinga2 --version): r2.14.0-1
  • Operating System and version: Ubuntu 22.04.2 LTS
  • Webserver, PHP versions: PHP 8.1

I’m not sure about the extract property but key column name needs to be something resembling _source.hostname or _id so a uniq value identifying the record/row of your imported data.

Hi, yes you are right. I now use the “_id” value.
But the problem was on the source side. First requests I made with curl delivered data, but later something broke and there wasn’t any entries in “hits.hits” anymore.

So now it is working after getting in touch with the guy who is providing it.

But thanks anyway :slight_smile:

1 Like