Author: @mfriedrich
Version: v0.1Tested with:
- Director v1.6.0, release package
- Icinga 2 v2.10.2, Icinga Web 2 v2.6.2
General
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.
Service Sets
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 more-win-disks.
Requirements
- Navigate into CheckCommand, choose
externalanddisk-windows. Selectdisk_win_pathas field - we want to use this later in service definitions.
- Add a new service template called
windows-disk. This imports thedisk-windowsCheckCommand.
Create the service sets
- Create
windows-disk-basic - Create
windows-disk-more
- Navigate into each service set and choose
Add service
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 asdisk C:and use the custom propertydisk_win_pathto assign the valueC:to it. - Repeat that for the second service set with
D:andE:services
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 typeBoolean. Call itwin_partitions_enabled.
- Navigate into
Hosts > Templatesand add thewindows-partitionedtemplate. - 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) toYes.
Create Hosts matching Service Set assign where
- Create two new hosts, one imports the
windows-generictemplate - The second host imports the
windows-partitionedtemplate
Conditions
- The default service set
windows-disk-basicshould be applied to all hosts which have theoscustom property defined towindowsas string.
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 haswin_enable_partitionsis set to true.
You can also check for importing the host template
windows-partitioned. Try it out!
Conditions, refactored
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 wherehost.templatescontain thewindows-generictemplatewindows-disk-moreis applied to all hosts wherehost.templatescontain thewindows-partitionedtemplate
The first service set will always apply, since
windows-partitionedas host template imports thewindows-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 win32.
- The basic host only has the
disk C:service assigned. - The partitioned host has
C:and in addition,D:andE: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.
Questions
Please share your experience ![]()
- How would you solve this problem with service sets?
- Is there are different route you prefer here?















