Nagios REST API's

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
paul.jobb
Posts: 167
Joined: Tue Aug 02, 2011 4:37 pm

Nagios REST API's

Post by paul.jobb »

Hi;

what is the difference between using :

http://nagiosserver/nagios/jsonquery.html

or

http://nagiosserver/nagiosxi/api/v1/

Is one preferred over the other?

from what I can tell it appears that the first one, jsonquery, seems to have some better capabilities when querying for status(i.e. hostlisting based on groups, hostcount and so on..)
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: Nagios REST API's

Post by jomann »

The first one is the JSON CGI for Nagios Core, which while it has some better filtering right now, does not have the ability to do things such as modify the configs, restart core, apply configs, etc. Besides those, most of the same data should show up unless it's XI-specific, which will only show up in the second one.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
paul.jobb
Posts: 167
Joined: Tue Aug 02, 2011 4:37 pm

Re: Nagios REST API's

Post by paul.jobb »

so for querying, at that moment anyways, the nagios core JSON may be a better option?? sounds like that will change in the future.

I'm wanting to check the health of a number of network switches at a particular site(we have hundreds of sites across the province) and using the nagmap plugin plot the overall group health of the switches at each site for display to management. My plan was to group those switches in hosts groups and then develop a plugin to check the overall group health of each of those groups using a JSON query. Does that make sense or is there an easier way to tackle that??

I just stumbled across the xi api this morning, I do use the \etc\import folder for importing new hosts and services through automation, do the post commands support inserting free variables as well? is there any additional documentation on the XI api outside of what is in the online help?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios REST API's

Post by rkennedy »

This presentation has a bit of information - http://www.slideshare.net/nagiosinc/eri ... -nagios/46

On top of that, you can take a look at what's possible through the API by navigating to Backend API URL -> Click 'wrench icon' -> Select the user. From here you'll see all the information that can be used with the API.

More documentation can be found by going to your Nagios XI Home page and clicking 'Help', you'll see a section for 'Nagios XI API Docs' on the left side.

Is that what you were looking for?
Former Nagios Employee
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios REST API's

Post by Box293 »

paul.jobb wrote:so for querying, at that moment anyways, the nagios core JSON may be a better option?? sounds like that will change in the future.
Yes. There is a bug that will be fixed in the next release of core. Sometimes a complete JSON is not returned. If you come across this, I know it's fixed in core pre 4.1.2 on Github.
paul.jobb wrote:I'm wanting to check the health of a number of network switches at a particular site(we have hundreds of sites across the province) and using the nagmap plugin plot the overall group health of the switches at each site for display to management. My plan was to group those switches in hosts groups and then develop a plugin to check the overall group health of each of those groups using a JSON query. Does that make sense or is there an easier way to tackle that??
BPI might also be an option.
https://support.nagios.com/kb/article.php?id=280
paul.jobb wrote:I just stumbled across the xi api this morning, I do use the \etc\import folder for importing new hosts and services through automation, do the post commands support inserting free variables as well? is there any additional documentation on the XI api outside of what is in the online help?
Basically any directive that can be configured in an object that is defined in the nagios core documentation. However I just did some quick tests and it does not appear these are currently supported. Perhaps define these in a template and "use=" those templates might be a work around.
https://support.nagios.com/kb/article.php?id=356

Some directives are mandatory, however when using templates you might not want to define some directives. You need to use &force=1 to allow that.

Code: Select all

curl -k -XPOST "https://xitest.box293.local/nagiosxi/api/v1/config/host?apikey=5goacg8s&pretty=1" -d "host_name=my_test_host&address=127.0.0.1&use=linux-server&force=1&applyconfig=1"
NOTE: The "Backend API URL" that @rkennedy referrenced is an older API that works, but is depreciated (it's just a read-only api).
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
paul.jobb
Posts: 167
Joined: Tue Aug 02, 2011 4:37 pm

Re: Nagios REST API's

Post by paul.jobb »

Thank you Troy

force=1 was a good tip thanks for the heads up on that, I don't need free variables for network devices so I can get away without those for now, the following is the powershell I got working this morning with your suggestion.

$body = @{
host_name="AGSGSFL2SW1"
address="255.255.255.255"
alias="AGSGSFL2SW1"
notes="latlng: 51.046259,-114.053315"
_testvar="some string"
use="GOA-Network-Device"
force=1
}

$url="http://nagiosserver.gov.ab.ca/nagiosxi/ ... x&pretty=1"

$result=Invoke-RestMethod -Method Post -Uri $url -Body $body

$result


Thanks also for pointing out BPI, I do use that currently for some other stuff but have sort of moved away from that towards check_multi, BPI is a bit of a chore to maintain and for availability measurement it doesnt seem to filter out soft states which check_multi does.

With the network stuff switches are being added and removed from the environment daily so its just easier to reconcile nagios with there inventory DB through automation scripts a few times a day, group them on location and then measure the availability of the group health of the site .

I really appreciate your input.
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: Nagios REST API's

Post by jomann »

Great! Is there anything other questions about the APIs we can help with?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios REST API's

Post by Box293 »

Great to hear you got it working.
paul.jobb wrote:_testvar="some string"
Just curious, did this custom variable make it through into the object, or did the API drop it?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
paul.jobb
Posts: 167
Joined: Tue Aug 02, 2011 4:37 pm

Re: Nagios REST API's

Post by paul.jobb »

no it didn't make it, hopefully in the next release it does.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Nagios REST API's

Post by lmiltchev »

FYI, we already have an internal feature request for adding free variables to the REST API (TASK ID 7853).
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked