Missing defined constant on agent

I have setup a single master, multiple agent environment (v 2.11).

zones.d
    ├── master.srv.com
    │   ├── api-users.conf
    │   ├── commands.conf
    │   ├── constants.conf
    │   ├── downtimes.conf
    │   ├── groups.conf
    │   ├── hosts
    │   │   ├── agt01t.srv.com.conf
    │   │   ├── agt02t.srv.com.conf
    │   │   ├── agt03t.srv.com.conf
    │   │   ├── agt04t.srv.com.conf
    │   ├── notifications.conf
    │   ├── services.conf
    │   ├── templates.conf
    │   ├── timeperiods.conf
    │   └── users.conf
    ├── global-templates
    │   └── commands.conf

Where master.srv.com is my master zone and ZoneName = master.srv.com.

Content of zones.d/master.srv.com/constants.conf
const LocalPluginDir = "/usr/local/lib/nagios/plugins"

Content of global-templates/commands.conf

 object CheckCommand "memory" {
  import "plugin-check-command"

  command = [ LocalPluginDir + "/check_mem" ]

  arguments = {
		"-u" = {
			set_if = "$mem_used$"
			description = "Check USED memory"
		}
		"-f" = {
			set_if = "$mem_free$"
			description = "Check FREE memory"
		}
		"-C" = {
			set_if = "$mem_cache$"
			description = "Count OS caches as FREE memory"
		}
		"-w" = {
			value = "$mem_warning$"
			description = "Percent free/used when to warn"
		}
		"-c" = {
			value = "$mem_critical$"
			description = "Percent free/used when critical"
		}
	}

	vars.mem_used = true
	vars.mem_free = false
	vars.mem_cache = false

	vars.mem_warning = 80
	vars.mem_critical = 95
}

On my agent I got the error, from /var/lib/icinga2/api/zones-stage/startup.log:

critical/config: Error: Error while evaluating expression: Tried to access undefined script variable ‘LocalPluginDir’
Location: in /var/lib/icinga2/api/zones-stage//global-templates/_etc/commands.conf: 10:15-10:28
/var/lib/icinga2/api/zones-stage//global-templates/_etc/commands.conf(8): import “plugin-check-command”
/var/lib/icinga2/api/zones-stage//global-templates/_etc/commands.conf(9):
/var/lib/icinga2/api/zones-stage//global-templates/_etc/commands.conf(10): command = [ LocalPluginDir + “/check_mem” ]
^^^^^^^^^^^^^^
/var/lib/icinga2/api/zones-stage//global-templates/_etc/commands.conf(11):
/var/lib/icinga2/api/zones-stage//global-templates/_etc/commands.conf(12): arguments = {

icinga2 daemon -C doesn’t complain about anything. Why is the constants.conf not synced to my agents?

And one more question, is it a good practice to define the zones in the host.conf files like I did.
Content of zones.d/master.srv.com/hosts/agt01t.srv.com.conf
object Zone “agt01t.srv.com.conf” {
endpoints = [ “agt01t.srv.com.conf” ]
parent = ZoneName
}

object Endpoint "agt01t.srv.com.conf" {
  host = "agt01t.srv.com.conf"
  log_duration = 0
}

object Host "agt01t.srv.com.conf" {
  import "generic-host"
  address = "172.28.28.5"

  display_name = "SRV-APP01 (Test)"
  vars.os = "DEBIAN"

  vars.partitions["disk /"] = {
    disk_partitions = "/"
  }

  vars.http_vhosts["http"] = {
    http_ssl = true
    http_host = "agt01t.srv.com"
    http_uri = "/info"
  }

  vars.load_wload1 	= 5
  vars.load_wload5 	= 4
  vars.load_wload15 = 3
  vars.load_cload1 	= 10
  vars.load_cload5 	= 6
  vars.load_cload15 = 4

  vars.procs_warning	= 250
  vars.procs_critical	= 400

  vars.agent_endpoint = name
}

Thank you for your feedback.

Hello

IIRC Constants are not zone specific and as such need to be defined the the root directory of icinga, preferably in the constants.conf file.

as for defining zones in the host file, while it will work and Icinga will parse the file and read the configuration (it really doesn’t care what you name the file), the best practice is to put the zones and endpoints definitions in a separate file with a self explanatory name as to it’s content.

Your master zone is not global (which is correct), hence not synchronized to the agents.

Thank you, I moved all custom nagios plugins to the default location /var/lib/nagios/plugins, now it works.