Run script on object (host) creation

I’m looking into setting up a new installation of Icinga on Ubuntu and we are wanting to use Director for most things such as host and service configuration.

My question:
Is there a way to run a script (bash/python/…) when an object (host) has been created or modified in Director?
Depending on the host name, IP address, etc. entered, and using data from a different database, I would like a script to automatically fill/correct some data fields (custom variables), especially after cloning, and perhaps add/remove some host templates.

Best regards,
Sean

Maybe I don’t get it but why don’t you run the script and then use the information to create the host in the director via the self service API at the end?

The information from the database wouldn’t be enough to actually create hosts, and we would like the various team members to be able to create hosts from the nice Director GUI as they’re building them.
With our host naming conventions and IP addresses we can determine some functionality and location details to pull in some extra information for just filling/correcting some object configs (e.g. templates, distribution, custom variables, checks, etc).
I’m just trying to make things simpler to configure for the team, with less steps, less things to forget to configure.

The information from the database wouldn’t be enough to actually create hosts

We use the director self service API in a first run script of new servers because we also don’t have alle the information beforehand.

I’m just trying to make things simpler to configure for the team, with less steps, less things to forget to configure.

We use a custom variable called tags to add service-sets to hosts. This way there is a nice drop down directly on the host’s property page in the director. If I build custom service-sets, then I use a clone of the host.vars.tags called host.vars.custom_tags and attach the service-set with assign where "new-tag" in host.vars.custom_tags - its the GUI it’s the contains operator. I also restrict the new tag to the team in the data list (https://icinga.example.com/icingaweb2/director/data/lists) that is attached to the data field (https://icinga.example.com/icingaweb2/director/data/fields). Don’t forget to add the field for the tags to your default host template.

The Linuxfabrik monitoring plugins “about me” check will even suggest tags for service-sets in there collection. Look for the --tags argument.

To end the thread, what I’ve done now is create a script that is run on button press, a button that is accessible from a custom navigation item on the Icingaweb interface. It’s actually nicer this way as you can see the script output, seeing what it’s actually doing instead of it being some hidden thing in the background.
The script modifies host variables, and creates and deletes host templates and host groups through the Director API.

1 Like