Icinga2 check assigned with NodeName

I’m trying to define a generic load checks the load of the given machine. On some of the examples, they use a check as follows:

apply Service "load" {
  import "generic-service"

  check_command = "load"
  vars.backup_downtime = "02:00-03:00"
  assign where host.name == NodeName
}

I have NodeName defined as a constant in /etc/icinga2/constants.conf.

This check is defined in /etc/icinga2/zones.d/global-commands/services.conf, and I have a global zone as defined by the following block in /etc/icinga2/zones.conf.

object Zone "global-commands" {
  global = true
}

Yet, this never assigned, or at least I think it’s not. I came to this conclusion by means of the output of icinga2 daemon -C where I see the following:

[2021-04-14 14:59:27 -0400] information/cli: Icinga application loader (version: r2.12.3-1)
[2021-04-14 14:59:27 -0400] information/cli: Loading configuration file(s).
[2021-04-14 14:59:27 -0400] information/ConfigItem: Committing config item(s).
[2021-04-14 14:59:27 -0400] information/ApiListener: My API identity: icinga.workdomain.com
[2021-04-14 14:59:28 -0400] warning/ApplyRule: Apply rule 'load' (in /etc/icinga2/zones.d/global-commands/services.conf: 17:1-17:20) for type 'Service' does not match anywhere!
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 NotificationComponent.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 47 Hosts.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 GraphiteWriter.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 3 NotificationCommands.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 FileLogger.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 IcingaApplication.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 3 HostGroups.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 CheckerComponent.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 50 Zones.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 StatusDataWriter.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 48 Endpoints.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 ExternalCommandListener.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 CompatLogger.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 ApiListener.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 228 CheckCommands.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 1 IdoPgsqlConnection.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 3 TimePeriods.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 141 Services.
[2021-04-14 14:59:28 -0400] information/ConfigItem: Instantiated 6 ServiceGroups.
[2021-04-14 14:59:28 -0400] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2021-04-14 14:59:28 -0400] information/cli: Finished validating the configuration file(s).

I’m pretty new to Icinga2, so maybe I’m overlooking something obvious or I’m implementing this in a wonky way.

Any help getting this setup would be greatly appreciated.

NodeName is always a very bad idea as it will generate a different configuration everywhere.

In your case it is only matching on the central system for itself, all other systems where the configuration is synced to will also generate a local service, but this will not accepted by the central system as it does not have an object for it.

@dgoetz Oh okay. If I wanted this to get applied to all Linux/*NIX nodes would you suggest something more like:

apply Service "load" {
  import "generic-service"

  check_command = "load"
  vars.backup_downtime = "02:00-03:00"
  assign where host.vars.os == 'Linux'
}

Yes, having a custom variable on all hosts and using this for apply is the best way to go.

My goal is always a rule-based configuration where only a host with custom variables needs to be created and no other configuration to be touched.

(There is a small error by using single instead of double quotes in your example. Icinga 2 is really picky with this.)

1 Like

Awesome, thanks for the information. I was able to get this working, I appreciate the effort.