Override variable in Apply

Hi,

In my host config I have

vars.mem_wused = "98%"
vars.mem_cused = "99%"

And in my service config I have

apply Service "Memory [Physical]" {
  import "nrpe-generic-service"
  import "service-override-24x7"

  check_command = "nrpe"

  vars.nrpe_command = "check_memory"
  vars.memory_type = "physical"

  if (vars.mem_wused == "" ) {
    vars.mem_wused = "98%"
  }
  if (vars.mem_cused == "" ) {
    vars.mem_cused = "99%"
  }

  vars.nrpe_arguments = [ "type=" + vars.memory_type, "warning=used>"+vars.mem_wused+"!critical=used>"+vars.mem_cused+"!empty-state=unknown" ]

  assign where host.vars.os == "Windows" && host.vars.nrpe == true
}

I know my IF is not working, what am I doing wrong ?

What I want to do, it’s if under the HOST i don’t set the variable, inside the apply, it will override something…

Hi @PointPubMedia

does it work with the following?

// ...
if (!host.vars.mem_wused) {
// ...
1 Like