Director Service Sets: Add service checks based on host templates

Author: @mfriedrich
Version: v0.1

Tested 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 external and disk-windows. Select disk_win_path as field - we want to use this later in service definitions.

  • Add a new service template called windows-disk. This imports the disk-windows CheckCommand.

Create the service sets

  • Create windows-disk-basic
  • Create windows-disk-more

  • Navigate into each service set and choose Add service

:bulb: 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_path to assign the value C: to it.
  • Repeat that for the second service set with D: and E: services

Service Set: Assign where?

:bulb: 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 field of type Boolean. Call it win_partitions_enabled.

  • Navigate into Hosts > Templates and add the windows-partitioned template.
  • 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 Yes.

Create Hosts matching Service Set assign where

  • Create two new hosts, one imports the windows-generic template
  • The second host imports the windows-partitioned template

Conditions

  • The default service set windows-disk-basic should be applied to all hosts which have the os custom property defined to windows as string.

:bulb: You could also check for importing the host template windows-generic before. Try it and add your feedback as reply.

  • The advanced service set windows-disk-more should be applied to all windows hosts, but only when the host has win_enable_partitions is set to true.

:bulb: 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-basic is applied to all hosts where host.templates contain the windows-generic template
  • windows-disk-more is applied to all hosts where host.templates contain the windows-partitioned template

:bulb: The first service set will always apply, since windows-partitioned as host template imports the windows-generic template. 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: and 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.

Questions

Please share your experience :slight_smile:

  • How would you solve this problem with service sets?
  • Is there are different route you prefer here?
4 Likes