# Icinga2 check assigned with NodeName

**URL:** <https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131>\
**Category:** Service Monitoring\
**Tags:** icinga2\
**Created:** [April 14, 2021, 7:04pm UTC](https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131 "2021-04-14T19:04:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdelaney](https://community.icinga.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@mdelaney](https://community.icinga.com/u/mdelaney)\
**Post date:** [April 14, 2021, 7:04pm UTC](https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131/1 "2021-04-14T19:04:31Z")

</div>

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:

```auto
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`.

```auto
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:

```auto
[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.

---

<div class="post-metadata">

**Author:** ![dgoetz](https://community.icinga.com/user_avatar/community.icinga.com/dgoetz/32/917_2.png) [@dgoetz](https://community.icinga.com/u/dgoetz)\
**Post date:** [April 15, 2021, 6:34am UTC](https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131/2 "2021-04-15T06:34:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mdelaney](https://community.icinga.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@mdelaney](https://community.icinga.com/u/mdelaney)\
**Post date:** [April 16, 2021, 1:19pm UTC](https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131/3 "2021-04-16T13:19:24Z")

</div>

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

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

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

```

---

<div class="post-metadata">

**Author:** ![dgoetz](https://community.icinga.com/user_avatar/community.icinga.com/dgoetz/32/917_2.png) [@dgoetz](https://community.icinga.com/u/dgoetz)\
**Post date:** [April 16, 2021, 1:37pm UTC](https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131/4 "2021-04-16T13:37:17Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![mdelaney](https://community.icinga.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@mdelaney](https://community.icinga.com/u/mdelaney)\
**Post date:** [April 16, 2021, 2:27pm UTC](https://community.icinga.com/t/icinga2-check-assigned-with-nodename/7131/5 "2021-04-16T14:27:46Z")

</div>

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