Page 1 of 2

Obtaining Availability Report Data Via API

Posted: Wed Apr 24, 2019 1:58 pm
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!

Re: Obtaining Availability Report Data Via API

Posted: Wed Apr 24, 2019 5:02 pm
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.

Re: Obtaining Availability Report Data Via API

Posted: Wed Apr 24, 2019 5:20 pm
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.

Re: Obtaining Availability Report Data Via API

Posted: Thu Apr 25, 2019 1:24 pm
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.

Re: Obtaining Availability Report Data Via API

Posted: Mon Apr 29, 2019 12:17 pm
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!

Re: Obtaining Availability Report Data Via API

Posted: Mon Apr 29, 2019 1:00 pm
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.

Re: Obtaining Availability Report Data Via API

Posted: Mon Apr 29, 2019 2:03 pm
by awilson
Thanks. I'll check

Re: Obtaining Availability Report Data Via API

Posted: Mon Apr 29, 2019 2:54 pm
by npolovenko
Sounds good.

Re: Obtaining Availability Report Data Via API

Posted: Mon Apr 29, 2019 3:53 pm
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

Re: Obtaining Availability Report Data Via API

Posted: Mon Apr 29, 2019 4:34 pm
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.