Bakend API getstatehistory time interval

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ciprianm
Posts: 3
Joined: Mon Nov 03, 2014 2:40 pm

Bakend API getstatehistory time interval

Post by ciprianm »

Hello,

I am trying to use the Backend API to extract Nagios data and I noticed that the getstatehistory command only returns recent historical data by default.

http://<nagios_server>/nagiosxi/backend/?cmd=getstatehistory&username=nagiosadmin&ticket=<my_ticket>

How would I specify a target time interval for getstatehistory? Also, is there some more detailed documentation available on Backend API, I was only able to find brief docs on how to get started.

Regards,

Ciprian
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Bakend API getstatehistory time interval

Post by abrist »

To get an idea of the GET params available, open the state history report in a new tab. Now choose some option from the dropdowns and click "update". The address bar url should now contain all the necessary params for the query. For example, a report for the last 24hours resembles:

Code: Select all

http://<ip>0/nagiosxi/reports/statehistory.php?host=&service=&search=&reportperiod=last24hours&startdate=&enddate=&host=<hostname>&hostgroup=&servicegroup=&statetype=hard&reporttimesubmitbutton=Update&manual_run=1&page=1&records=25
And a report for a custom timeframe resembles:

Code: Select all

http://<ip>/nagiosxi/reports/statehistory.php?host=<hostname>&service=&search=&reportperiod=custom&startdate=2014-10-04&enddate=2014-11-05&host=192.168.4.39+yerp&hostgroup=&servicegroup=&statetype=hard&reporttimesubmitbutton=Update&manual_run=1&page=1&records=25
Does this help?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ciprianm
Posts: 3
Joined: Mon Nov 03, 2014 2:40 pm

Re: Bakend API getstatehistory time interval

Post by ciprianm »

Much appreciate the quick response.

I still can't the get backend API to return records the way statehistory.php displays them.

With this URL I can see a number of records from statehistory.php:
http://<nagios_server>/nagiosxi/reports/statehistory.php?host=&service=&search=&reportperiod=custom&startdate=2014-10-17&enddate=2014-11-11

Using the same startdate and endate parameters with getstatehistory backend API I get 0 records:
http://<nagios_server>/nagiosxi/backend/?cmd=getstatehistory&username=nagiosadmin&ticket=<my_ticket>&startdate=2014-08-17&enddate=2014-11-11

It seems startdate and endate parameters don't apply to getsatehistory backend API the same way as in statehistory.php. Any thoughts?

Thanks,

Ciprian
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Bakend API getstatehistory time interval

Post by abrist »

My apologies, I forgot the backend is slightly different. It uses unixtime and the params "starttime" and "endtime". For example:

Code: Select all

http://<ip>/nagiosxi/backend/?cmd=getstatehistory&starttime=1415311302&endtime=1415312302
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ciprianm
Posts: 3
Joined: Mon Nov 03, 2014 2:40 pm

Re: Bakend API getstatehistory time interval

Post by ciprianm »

That worked. Thanks!
Locked