Question about API structure

Hi

I’ve a question about icinga and api structure.

I’ve some config i’ve added manually (with differents zones):

/etc/icinga2/zones.d
zone1
zone2

On these zones i create my hosts, hostgroup, …

And in the same time i use API for some hosts:
/var/lib/icinga2/api/packages/_api/XXXX-XXX-XXXX-XXX-XXXXXXXX
conf.d
include.conf
zones.d

My “problem” is that all host i create with api are correctly created but in:
/var/lib/icinga2/api/packages/_api/XXXX-XXX-XXXX-XXX-XXXXXXXX/conf.d/hosts
server1.zone1
server2.zone1
server1.zone2

Is it possible with the API to put all servers from one zone in one directory from example in
/var/lib/icinga2/api/packages/_api/XXXX-XXX-XXXX-XXX-XXXXXXXX/zones.d/zone1

I create my object like this:
curl -k -s -u admin:$PASSWORD_API_ADMIN -H ‘Accept: application/json’ -X PUT ‘https://localhost:5665/v1/objects/hosts/server1’ -d '{ “templates”: [ “generic-host” ], “attrs”: { “address”: “XX.XX.XX.XX”, “check_command”: “hostalive”, “zone”: “zone1”, “vars”: {“services”: [“XXX”]} }, “pretty”: true }

In fact i will have many servers to add and i’d like to have a proper structure if possible (one directory for one zone and perhaps one subdirectory for some servers for a zone)

Thanks for help
Alex

This is an internal storage path for Icinga, and might be changed/migrated in the future. Do not attempt to change things manually in there, this will break Icinga. Nor should your scripts depend on that structure.

Cheers,
Michael

1 Like

Thanks for answer.
So it’s normal if I have 1000 hosts to have 1000 files in /var/lib/icinga2/api/packages/_api/XXXX-XXX-XXXX-XXX-XXXXXXXX/conf.d/hosts ?

And in this case what is the role of /var/lib/icinga2/api/packages/_api/XXXX-XXX-XXXX-XXX-XXXXXXXX/conf.d/zones.d/ ?

I can’t add hosts there with API?

Thanks for your informations!
Alex

As said, that’s an internal structure and has nothing to do with /etc. It borrows several concepts but they are not visible as a user API.

If you want to move a config object to a specific zone via the REST API as runtime object, I’d suggest setting the zone attribute accordingly.

Besides, mixing runtime objects and static configuration is something I generally recommend to avoid unless you know about the implications.

Cheers,
Michael

1 Like