Obtaining Availability Report Data Via API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Obtaining Availability Report Data Via API

Post by awilson »

Hi.
Can you verify our approach on this method to obtain the availability report data via the API?

Are these the API and parameter settings to pull the same content the current CSV extract is gathering for the server availability reporting? It appears that it is running the exact same report, though I would like you to verify and confirm. The start/end times are seconds since the Epoch for the selected time period. We are planning to load this information daily (each day pulls yesterday's info) so we can see the current month trends as well as prior months.

url = (nagios_server + '/nagios/cgi-bin/archivejson.cgi?'+
'query=availability' +
'&availabilityobjecttype=servicegroups' +
'&statetypes=hard'+
'&servicegroup=SLA-Compliance-Server-Availability-Check.TCP-Ping-and-Agent-Activity'+
'&assumeinitialstate=true' +
'&assumestateretention=true' +
'&assumestatesduringnagiosdowntime=true'+
'&assumedinitialhoststate=up' +
'&assumedinitialservicestate=ok' +
'&backtrackedarchives=4'+
'&starttime={}'.format(long(time.mktime(sync_from.timetuple()))) +
'&endtime={}'.format(long(time.mktime(sync_to.timetuple()))))

We built up the info on this URL from the JSON query page: https://ourserver/nagios/jsonquery.html

Thanks!
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Obtaining Availability Report Data Via API

Post by npolovenko »

Hi, @awilson. If you wanted to download the availability report from the command line you could use this command:
Replace the IP address with XI IP address. And replace my ticket with your "insecure backend API ticket".


Backend ticket needs to be enabled from the System Settings in XI -> Backward Compatibility tab. Then you can get the actual ticket by clicking on the username at the top right corner. It should be at the bottom of the page.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Re: Obtaining Availability Report Data Via API

Post by awilson »

Would this give us the report or the data seen in the report in JSON format?

I see that it says CSV. We are on 5.4.4. I don't see a Backward Compatibility tab.

Thanks.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Obtaining Availability Report Data Via API

Post by npolovenko »

@awilson, Here is the instruction on how to enable backend API on your version of XI. You can copy backend api ticket from the backend API URL(page 3 of this tutorial).
https://assets.nagios.com/downloads/nag ... nd_API.pdf
The output is not in json format.

The json query you suggested seems valid as well. The output repeats the legacy availability report.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Re: Obtaining Availability Report Data Via API

Post by awilson »

archivejson_cgi results image.png
avail_cgi results image.png
We are using Nagios XI 5.4.4
We notice that running the legacy Availability report avail.cgi gives different results from archivejson.cgi. Is this due to our being on an older release? Is this the same issue analyzed in out ticket #191120?

Thanks!
You do not have the required permissions to view the files attached to this post.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Obtaining Availability Report Data Via API

Post by npolovenko »

@awilson, I ran JSON and legacy reports on XI 5.4.12 and both matched. I suggest checking the arguments like "assume initial state", "assume state retention" and similar. If some of them are different on 2 reports that can cause differences in the data. Also, make sure that the timestamp you're using in the JSON report exactly corresponds with the time you chose on the legacy report.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Re: Obtaining Availability Report Data Via API

Post by awilson »

Thanks. I'll check
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Obtaining Availability Report Data Via API

Post by npolovenko »

Sounds good.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
awilson
Posts: 224
Joined: Mon Mar 21, 2016 1:20 pm

Re: Obtaining Availability Report Data Via API

Post by awilson »

Can archivejson.cgi or avail.cgi exclude scheduled downtime? Is there a way to pull the same exact availability reports from the api as from the UI?
Thanks
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Obtaining Availability Report Data Via API

Post by npolovenko »

@awilson, No it's not possible to exclude downtime. But there's an option to exclude downtime in the command I gave you earlier. This command is using the new availability report in XI.
One easy way to find a curl command for the report you like is to run a developer tool in chrome while you're generating a new report from the GUI. It will show you the command+arguments that you can reuse later.
But yes, this command is not using JSON. JSON command does not have the functionality to exclude downtime.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked