Apply Service not using host variable

I need a sanity check on this config item, it is not pulling the nrpe_port variable from the host config. Is that expected behaviour?

apply Service "NRPE checks" for ( key => config in host.vars.nrpe_check_instance) {
  import "nrpe-check-service"
  display_name = key
  vars += config
  vars.nrpe_port = host.vars.nrpe_port
  vars.nrpe_timeout_unknown = true
  assign where host.vars.nrpe_check_instance
}

Or, do I have to specify nrpe_port for each key in the host object config where this applies?

Hmm I don’t know how to solve your dictionary key problem, but have the same problem in solving an nrpe check from icinga2 to an nrpe host.

object CheckCommand "nrpe-check-1arg" {
        import "plugin-check-command"
        command = [PluginDir + "/check_nrpe" ]
        arguments = {
	"-t" = "100"
        "-H" = "$host$"
        "-c" = "$check$"
        }
}

apply Service "NRPE_Disk" {
        import "generic-service"
        notes_url = "https://opswiki.devnull.com/wiki/index.php/Resize_root"
        host_name = "op-icinga.devnull.com"
        check_command = "nrpe-check-1arg"
        vars.host = "10.21.97.21"
        vars.check = "check_disk"
        assign where host.name == "op-icinga.devnull.com"
}

Please try this configuration:

apply Service "NRPE checks" for (key => config in host.vars.nrpe_check_instance) {
  import "nrpe-check-service"
  display_name = key
  vars += config
  vars.nrpe_port = config.nrpe_port
  vars.nrpe_timeout_unknown = true
  assign where host.vars.nrpe_check_instance
}

In that case, I still need a nrpe_port variable for each config in nrpe_check_instance, no?
If that is the case there is no need to include it in the apply because its is already defined for the instance and passed along to the actual check.

re: your issue:

object CheckCommand "check_nrpe" {
  import "plugin-check-command"
  command = [ "/usr/local/icinga/libexec/check_nrpe" ]

  arguments = {
    "-c" = {
      value = "$check$"
      description = "NRPE host check name"
      required = true
    }
    "-H" = {
      value = "$host_address$"
      description = "Host address"
      required = true
    }

    "-p" = {
      description = "optional TCP port, default is 5666"
      value = "$nrpe_port$"
      required = false
    }

    "-u" = {
      description = "Unknown instead of critical on socket timeout"
      required = true
    }
  }
  vars.check = "$service.vars.check_name$"
  vars.host_address = "$host.address$"
  vars.nrpe_port = "$host.vars.nrpe_port$"