How to get host history using curl api rest

Hello, I am making a python script to obtain the json data from the hosts through the icingaweb 2 api using curl. So far it prints some data but it is not all the data registered by the system, I would like it to print the complete history of the hosts but I cannot find the url corresponding to that in the documentation and if I use the direct url from the history option (from the side menu) → general view of the event I get a 404 error. I leave you what I have so far:

import requests, json
import time

def generate_pdf_file(data):
for information in parse_json[“results”]:
hora= time.ctime(last_change_status)

req_url = ‘https://localhost:5665/v1/objects/hosts

resp = requests.get(req_url, auth=(‘root’, ‘pass’), verify=False)

if (resp.status_code == 200):

print (resp.text)

link documentation used:Api - Icinga 2

Hope you can help me, regards

For Python specifically, I prefer to use the icinga2apic package (installable from pip) as it gives me a nifty client to make things easier.

I would like it to print the complete history of the hosts

Do you mean that you want a history of hosts being added/removed from monitoring?

If so you probably want to checkout the event stream API docs – there are 3 types you might be interested in – ObjectCreated, ObjectDeleted, and ObjectModified. You may have to do some further filtering to filter out non-host objects.

Also worth noting that this endpoint is a listener – it will stay connected to the API and listen until the API no longer responds, or you tell the script to stop.

but those methods work only with post not with get, if I used get new values ​​would be added to the json data that I want to obtain.What I want is to list the history with the data that I already have registered in icinga 2.

Not sure if the API has what you want (I can’t find anything that provides “complete history of the hosts” – do you mean creation history, check history?)

For creation/deletion/modification history, you would likely have to use the eventstream api to stream the events that you want to a db (sqlite for instance) and either query the db when you want the data or put an API in front of that db.

For status history (ie, “monitoring history”) there are some values returned with a host object query, such as last state change and the one prior to the last, but I don’t think the API has all of that information.

In fact, I don’t even know if that information is stored in the IDO object, it may be stored in the statefile, or even somewhere else.

Of course, someone else may come along and have different ideas.