Using service output as host var

Hi everyone,
I’m monitor some Proxmox virtual machines with Icinga and I wish to add the information about the virtual machine ID and the node name which is serving it.

As these info can change I’m thinking about adding two services with a custom check script which get these info from the Proxmox API.

Anyway I would also like to have these info as host var in order to use them as search filter on hosts.

Is there any possibility to have the output of a check command ad host var?

If not, do you have any other ideas to achieve what I want? Maybe some custom Icingaweb2 plugin?

Thank you very much!
Bye

How often does this change?

It sounds like a job for the Director automation.

1 Like

How often does this change?

Not so frequently, but the change is not predictable and can happen in any moment.

It sounds like a job for the Director automation.

Unfortunately I’m not using the Director yet…
Yes I know, I really need to upgrade to Director, but unfortunately my custom Ansible roles do not support Director yet and this is a task I want to achieve during the current year…

I asked about frequency as it would require a config reload.
Maybe I can interest you in:

I don’t want to reload config when that change, this is because I asked if it would be possible to have an host var which takes is value from the output of a service check.

Sorry, don’t think it is currently possible at runtime.

What is your use case? Maybe there is an other way then host vars?

you can use icinga api to add these variables to the host.
having a script that knows the icinga vm hosts, get information via proxmox api and write it directly to the icinga host via icinga api on a specified interval.

https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#modifying-objects
The following example updates the address attribute and the custom variable os for the example.localdomain host:

curl -k -s -S -i -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/objects/hosts/example.localdomain' \
 -d '{ "attrs": { "address": "192.168.1.2", "vars.os" : "Windows" }, "pretty": true }'

Thanks!
So host vars can be changed at runtime through the Icinga API?

Wonderful!

yes :slight_smile:
these changes are stored in /var/lib/icinga2/modified-attributes.conf
It also survives a director redeploy so be careful with that.
Keep in mind that you need an api user (not icignaweb2 user) configurable in /etc/icinga2/conf.d/api-users.conf

But I’m not using the Director actually.
Would this work anyway?

yes, but try it out and report back