How to list all monitored Host IPs

Hello,
I’m working on a Perl Script which use the Icinga2 API to query information about all monitored Hosts.
The Script should list all monitored Host IPs of a specific VLAN. So i will be able check which of my Hosts aren’t monitored yet.
I wonder if there is a way to get all those Host IPs listed.
Does anyone already implemented that?

Thanks for your help!

Hi,

Have you had a look a the docs already?
The parts about the API are pretty good imo, and more or less show you everything you need for basic queries with some filters. You just have to adapt the examples to what you want.

What you need is a query for hosts with attributes name and address and a filter to the hosts addresses belonging to that VLAN.

You basically have all that right in the first example about parameters and just have to adjust that:
https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#parameters

API filters: Api - Icinga 2
API querying objects: Api - Icinga 2

There are examples for query URLs as well as examples for queries in a JSON objects in the body.

Also you have example code for different programming languages:
API: programmatic-examples

Cheers :slight_smile:

Just to add one more to @log1c quite good hints. Depending on if you can get the information of the matching VLAN for the host already based on existing fields or not, looking at cidr_match for the filter could be a good idea.