Nagios API not using Ansible URI 'body' options?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
walterkessler
Posts: 3
Joined: Tue Dec 01, 2020 2:24 pm

Nagios API not using Ansible URI 'body' options?

Post by walterkessler »

I have seen posts in the forum where people show using the 'body' parameter of the Ansible URI module. https://support.nagios.com/forum/viewto ... it=ansible

I have been trying to get host info as well as trying to add a test device, but the API call seems to ignore anything passed via 'body'.

For instance, this will just result in EVERY host being returned:

Code: Select all

  - name: get host config
    uri:
      url: https://SERVERNAME/nagiosxi/api/v1/config/host?apikey=APIKEY
      method: GET
      body: 'host_name=blah001'
      validate_certs: no
    register: get_host_results
If I move the body part up into the URL, it works and returns a single host:

Code: Select all

  - name: Get host config
    uri:
      url: https://SERVERNAME/nagiosxi/api/v1/config/host?apikey=APIKEY&host_name=blah001.domain.net
      method: GET
#      body: 'host_name=blah001.domain.net'
      validate_certs: no
    register: get_host_results
Not sure what I am missing.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios API not using Ansible URI 'body' options?

Post by ssax »

It wouldn't be part of the body, it's a part of the request which is why the URL change works.

Does this work?

Code: Select all

  - name: Get host config
    uri:
      url: https://SERVERNAME/nagiosxi/api/v1/config/host?apikey=APIKEY
      method: GET
      validate_certs: no
      deployment:
        host_name: blah001.domain.net
    register: get_host_results
walterkessler
Posts: 3
Joined: Tue Dec 01, 2020 2:24 pm

Re: Nagios API not using Ansible URI 'body' options?

Post by walterkessler »

Ah, so only a POST or PUT can use the body parameter?

What is the syntax to use the 'optional parameter' on the GET to filter results?
It works when using the OBJECTS api, but not when using the CONFIG api:

Works:

Code: Select all

url: "https://SERVER/nagiosxi/api/v1/objects/host?apikey=APIKEY&pretty=1&name=lk:{{ inventory_hostname }}"
This returns only "OK.", even when no host was found:

Code: Select all

url: "https://SERVER/nagiosxi/api/v1/config/host?apikey=APIKEY&pretty=1&host_name=lk:{{ inventory_hostname }}""
If i remove the "lk:" and do an exact name match, i will get a result.
Is there a way to do a search in CONFIG without the full/exact host name?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios API not using Ansible URI 'body' options?

Post by ssax »

When using a GET the body comes from the remote host.

Don't use the body for any of them, there's no need. But yes, essentially POST/PUT will only use the body but it's not required.

Code: Select all

If you want to read information, use GET.
If you want to update a host/service (writing information) use a PUT
If you want to create a new host/service use a POST
It doesn't look like the lk: functionality works for the config endpoint as you found, it doesn't work on mine either and I do not see the code in there that does it. Development would need to add it.

I can submit a feature request to development requesting they add that functionality if you'd like?
walterkessler
Posts: 3
Joined: Tue Dec 01, 2020 2:24 pm

Re: Nagios API not using Ansible URI 'body' options?

Post by walterkessler »

ssax wrote:It doesn't look like the lk: functionality works for the config endpoint as you found, it doesn't work on mine either and I do not see the code in there that does it. Development would need to add it.

I can submit a feature request to development requesting they add that functionality if you'd like?
I think that it would be useful considering that new hosts being added -- but not yet applied -- do not appear in 'object' API searches.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios API not using Ansible URI 'body' options?

Post by ssax »

That makes sense because the objects endpoints only deal with live objects and the CCM isn't live until after you apply. I've created the feature request for the config endpoint:

Code: Select all

FR: XI - API - Please add lk: (and other query limiting support that the objects endpoint has) to the config endpoint, it does not allow using lk: to build limited queries
Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.

Thank you!
Locked