- Director v1.6.0, release package
- Icinga 2 v2.10.2, Icinga Web 2 v2.6.2
This howto originates from helping a user, and finding out that the template inheritance strategy doesn’t solve the problem. You can read more here: Adding values to arrays in director in template inheritance
Knowledge requirement: Define data fields, add fields for Checkcommands, create host/service templates before creating objects/apply/sets, add custom properties.
Since template inheritance doesn’t support additive array assignments, I would go for a different pattern. When you’re German speaking, I can recommend getting the Icinga 2 Book v2.0, where “Service Sets” are explained in detail.
This follows the approach that you have specific services defined as basis, and can opt-in and opt-out from specific changes.
If you for example keep the default
disks attribute in the host template, and create a service apply rule for this, it is just fine. Additional service sets can then be defined and grouped to the host, e.g. as
- Navigate into CheckCommand, choose
disk_win_pathas field - we want to use this later in service definitions.
- Add a new service template called
windows-disk. This imports the
Create the service sets
- Navigate into each service set and choose
Hint: We need to this here, and not outside as single service - there we would need to know the host name relation already.
- Select the previously created service template
windows-disk, define the name as
disk C:and use the custom property
disk_win_pathto assign the value
- Repeat that for the second service set with
Service Set: Assign where?
Hint: Best is to learn about sets first, play around in a demo installation, and build the best templates and set assign where strategy base on your findings. Discuss your ideas here too!
This needs some additional changes for the host templates. There’s the
windows-generic template we’ve created before already.
Windows hosts with additional partitions should inherit from a dedicated template, where we put an additional variable. This allows us to create a condition for different host types later.
- Add a new
data fieldof type
Boolean. Call it
- Navigate into
Hosts > Templatesand add the
- Add the previously created data field as field property.
- Set the custom property from the field definition (Caption:
More than C: as partition, D: and E: with additional data) to
Create Hosts matching Service Set assign where
- Create two new hosts, one imports the
- The second host imports the
- The default service set
windows-disk-basicshould be applied to all hosts which have the
oscustom property defined to
You could also check for importing the host template
windows-genericbefore. Try it and add your feedback as reply.
- The advanced service set
windows-disk-moreshould be applied to all windows hosts, but only when the host has
win_enable_partitionsis set to true.
You can also check for importing the host template
windows-partitioned. Try it out!
As mentioned above, I came to the conclusion while trying things out here, that the template inheritance chain is a better fit to apply service templates. That’s also known as Director best practice.
So I’ve changed the service set conditions to this:
windows-disk-basicis applied to all hosts where
windows-disk-moreis applied to all hosts where
The first service set will always apply, since
windows-partitionedas host template imports the
windows-generictemplate. Keep that in mind!
There’s a small rendering bug, the value in the form is “windows-partitioned”.
Deploy and profit
Deploy the configuration and search for
- The basic host only has the
disk C:service assigned.
- The partitioned host has
C:and in addition,
E:as service objects assigned.
Problems found while learning
Boolean values are rendered as string in assign where. You need to choose “is not true” from the dropdown, as explained by Tom
Better go with the template contains checks shown above.
Please share your experience
- How would you solve this problem with service sets?
- Is there are different route you prefer here?