How to get a list of hosts and current status

Hi,
I created per-host monitoring using process-check-result API. So, there’s a group of host which I just need to check if it’s up or down.

Is there a way to request icinga’s API and get a list of hosts and its status?

If possible, I’d like to request icinga’s API passing a filter like ‘*.location-1.mydomain’, and get something like:
{
results: [
{
‘Host’: ‘host-1.location-1.mydomain’,
‘state’: ‘up’
}.
{
‘Host’: ‘host-2.location-1.mydomain’,
‘state’: ‘up’
}
]
}

Is there any way to achieve this?

Thanks

Hello @ronanlucio
This will return your the complete object list of hosts you target :
get_objects(Host).filter(h => regex("*.location-1.mydomain",h.name))

you’ll need further processing to get the status output like in your example, but you could actually map the output of this function to an other one to achieve it.

Hi @Someone,

That’s great.
Do you have any clue how can I fetch this list via external API call?

Thank you,

OK, got this working through /v1/objects/services endpoint.

Thank you,