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.
Code: Select all
http://your_nagios_host/nagios/jsonquery.html
2017_07_18_11_36_56_JSON_Query_Generator.png
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):
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=1500395712000
Which might return something like this:
Code: 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"
}
]
}
}
And if you only wanted OK/CRITICAL/whatever states, you would just adjust the
hoststates part of your request.