Override service variable value with host variable

I am moving from SSH based checks to distributed setup. Icinga 2.11.3 on all nodes.

I have problem with overriding procs service threshold variable values with host variable values.

In this scenario I have a single master node and one client master monitors (I call it server.domain.tld in this example).

Configuration:

zones.d/master/services.conf

apply Service "procs" {
  import "generic-service"
  check_command = "procs"
  command_endpoint = host.vars.agent_endpoint
  check_interval = 10m
  vars.procs_warning = 333
  vars.procs_critical = 444

  assign where ( host.zone == "master" && host.vars.agent_endpoint ) && host.vars.hosttype != "remote"
}

zones.d/master/hosts/server.domain.tld

object Host "server.domain.tld" {
  import "generic-host"
  address = "server.IP.v.4"
  vars.procs_warning = 555
  vars.procs_critical = 666
  vars.agent_endpoint = name
}

zones.d/master/clients.conf

object Endpoint "server.domain.tld" {
    host = "server.IP.v.4"
    log_duration = 0
}

object Zone "server.domain.tld" {
  endpoints = [ "server.domain.tld" ]
  parent = "master"
}

Which values should be used for the check?
In my case check is assigned to server.domain.tld with vars.procs_warning = 333 and vars.procs_critical = 444 ignoring the variables (555,666) in the host object. Is this expected behavior? Am I doing something wrong?

Hi,

and welcome to the community :slight_smile:

Yeah this is the expected behavior since you are not passing the values to the service object.
You need to check if a value is defined on host level and use this value else fallback to a default value.- something like this (not tested):

apply Service "procs" {
    import "generic-service"
    check_command = "procs"
    command_endpoint = host.vars.agent_endpoint
    check_interval = 10m

    // check if procs_warning is set on host level
    if (host.vars.procs_warning) {
        // use value from host
        vars.procs_warning = host.vars.procs_warning
    } else {
        // fallback to defaut 
        vars.procs_warning = 333
    }

    // check if procs_critical is set on host level
    if (host.vars.procs_critical) {
        // use value from host
        vars.procs_critical = host.vars.procs_critical
    } else {
        // fallback to defaut 
        vars.procs_critical = 444
    }

    assign where ( host.zone == "master" && host.vars.agent_endpoint ) && host.vars.hosttype != "remote"
}

Greetz

2 Likes

Hello,

the host vars will be used if there is no vars set in the service. So you have only to check if no variable is set in the host. and btw. command_endpoint = host.vars.agent_endpointis not needed, just set it to command_endoint = host.name

Regards,
Carsten

1 Like

Thank you so much for the solution! :slight_smile:

1 Like