Hi Team,
I need support on how to pass time variables to get Host/Service Status in Backend API URL
I want to get a host availability with up or down based on specific Host with day wise or between two dates.
If any possibility get reports directly from nagios?
Thanks
Srikanth
Pass StartTime,Endtime Parameters in BackEnd URL API
Re: Pass StartTime,Endtime Parameters in BackEnd URL API
I'm not sure if the XI REST API can do that (it probably can), but you can definitely do it with the JSON CGIs present in Nagios Core.
Note that the START and END times are Unix epochs.
Which then, on the right-hand side of the page, churns out a lovely HTTP request which returns JSON with the results you'd like (you will need to include credentials in your request):
Which might return something like this:
And if you only wanted OK/CRITICAL/whatever states, you would just adjust the hoststates part of your request.
Code: Select all
http://your_nagios_host/nagios/jsonquery.htmlWhich then, on the right-hand side of the page, churns out a lovely HTTP request which returns JSON with the results you'd like (you will need to include credentials in your request):
Code: Select all
https://username:password@your_nagios_host/nagios/cgi-bin/archivejson.cgi?query=alertlist&objecttypes=host&hoststates=up+down+unreachable&hostname=esprod00&starttime=0&endtime=1500395712000Code: Select all
{
"format_version": 0,
"result": {
"query_time": 1500395888000,
"cgi": "archivejson.cgi",
"user": "nagiosadmin",
"query": "alertlist",
"query_status": "released",
"program_start": 1500385372000,
"last_data_update": 1500392869000,
"type_code": 0,
"type_text": "Success",
"message": ""
},
"data": {
"selectors": {
"endtime": 1500395712000000,
"objecttypes": 1,
"hostname": "esprod00"
},
"alertlist": [{
"timestamp": 1497553881000,
"object_type": 1,
"name": "esprod00",
"state_type": 2,
"state": 2,
"plugin_output": "CRITICAL - Could not complete HTTP request"
}, {
"timestamp": 1497553938000,
"object_type": 1,
"name": "esprod00",
"state_type": 2,
"state": 2,
"plugin_output": "CRITICAL - Could not complete HTTP request"
}, {
"timestamp": 1497553998000,
"object_type": 1,
"name": "esprod00",
"state_type": 2,
"state": 2,
"plugin_output": "CRITICAL - Could not complete HTTP request"
}, {
"timestamp": 1497554054000,
"object_type": 1,
"name": "esprod00",
"state_type": 2,
"state": 1,
"plugin_output": "OK - Can connect to ElasticSearch on port 9200"
}, {
"timestamp": 1497965729000,
"object_type": 1,
"name": "esprod00",
"state_type": 2,
"state": 2,
"plugin_output": "CRITICAL - Could not complete HTTP request"
}, {
"timestamp": 1500385374000,
"object_type": 1,
"name": "esprod00",
"state_type": 2,
"state": 1,
"plugin_output": "OK - Can connect to ElasticSearch on port 9200"
}
]
}
}
You do not have the required permissions to view the files attached to this post.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Pass StartTime,Endtime Parameters in BackEnd URL API
Thanks @mcapra for the help.
The API in XI does have the ability to specify the Start and End times on the API call to get specific dates.
To get more information on building queries in the API, login to the XI GUI and go to the Help > REST API Docs > Object Reference menu to see the options you can use in the queries.
The API in XI does have the ability to specify the Start and End times on the API call to get specific dates.
Code: Select all
starttime <timestamp> (Default: -24 hours) objects/statehistory?starttime=1499808016 - Displays the last week of data until now.
endttime <timestamp> (Default: now) objects/statehistory?starttime=1499203216&endtime=1499808016 - Displays 1 week of data starting 2 weeks ago. Should be used with starttime.Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Pass StartTime,Endtime Parameters in BackEnd URL API
Hi mcapra,
cgi-bin/archivejson.cgi for older versions.For >5.0,it's not working.
Please suggest, if tried in higher version.
Thanks,
Srikanth
cgi-bin/archivejson.cgi for older versions.For >5.0,it's not working.
Please suggest, if tried in higher version.
Thanks,
Srikanth
Re: Pass StartTime,Endtime Parameters in BackEnd URL API
Refer to @tgriep's suggestion. The statehistory REST endpoint does roughly the same thing and has better granularity.
Though i'm 90% sure the JSON cgis should work on versions of XI >5.0. I was using it on 5.2.7 way back when, which I think had Nagios Core 4.1.1 under the hood. I most recently did this against a Nagios Core 4.3.0 machine. If it's not working, I think there's problems beyond the XI version, possibly an incorrect URL being used.
Though i'm 90% sure the JSON cgis should work on versions of XI >5.0. I was using it on 5.2.7 way back when, which I think had Nagios Core 4.1.1 under the hood. I most recently did this against a Nagios Core 4.3.0 machine. If it's not working, I think there's problems beyond the XI version, possibly an incorrect URL being used.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Pass StartTime,Endtime Parameters in BackEnd URL API
I just ran the JSON query on my XI server running 5.4.7 and it worked.
Verify that you are using this URL to access it. Replace xxx.xxx.xxx.xxx with the IP address or the hostname.
Verify that you are using this URL to access it. Replace xxx.xxx.xxx.xxx with the IP address or the hostname.
Code: Select all
http://xxx.xxx.xxx.xxx/nagios/jsonquery.htmlBe sure to check out our Knowledgebase for helpful articles and solutions!