Check is not applied

Hello,

I reached point where I cannot find the problem. Its weird.

I was configuring new check “ifutil” for monitoring traffic on ethernet.
I have about 30 hosts and just for 4 of them its not applied and I dont know why.

One master, multi satellites with multi clients.

Everything is stored on Master in zones.d -> Sync is working OK

All hosts object contains this
workingone:

object Host “host_1” {
check_command = “hostalive”
import “db-host”
address = “192.168.26.100”
vars.check_ifutil_interface = “eth0”
}

bad one:

object Host “host_2” {
check_command = “hostalive”
import “db-host”
vars.check_ifutil_interface = “ens192”
vars.procs_warning = “600”
vars.procs_critical = “800”
address = “192.168.26.110”
}

As you can see the diff is about name of the public internet interface “eth0” vs “ens192”

And in global template 2 services applied according to this interface (version with apply service for (x in y) was not applied at all))

apply Service “net traffic eth” {
check_interval = 5m
retry_interval = 1m
check_command = “ifutil”
vars.check_ifutil_interface = “ens192”
vars.check_ifutil_warning = “70”
vars.check_ifutil_critical = “90”
vars.check_ifutil_bandwidth = “100M”
assign where host.vars.check_ifutil_interface == “ens192”
}

apply Service “net traffic eth” {
check_interval = 5m
retry_interval = 1m
check_command = “ifutil”
vars.check_ifutil_interface = “eth0”
vars.check_ifutil_warning = “70”
vars.check_ifutil_critical = “90”
vars.check_ifutil_bandwidth = “100M”
assign where host.vars.check_ifutil_interface == “eth0”
}

PS: 2 another ens192 hosts are working

Result for icinga2 daemon -C:

[2020-02-14 13:39:41 +0100] warning/ApplyRule: Apply rule ‘net traffic eth’ (in /var/lib/icinga2/api/zones/global-templates/_etc/mini.conf: 481:1-481:31) for type ‘Service’ does not match anywhere!
[2020-02-14 13:39:41 +0100] warning/ApplyRule: Apply rule ‘net traffic eth’ (in /var/lib/icinga2/api/zones/global-templates/_etc/mini.conf: 492:1-492:31) for type ‘Service’ does not match anywhere!

I would be very thankfull if you can point me in right direction or show the problem of appling via one apply service with the for looking for params and taking them from host definition.

Thanks

Hi,

I would try to rule out copy-paste errors by assigning the service custom variable from the host directly.

Also, I would hide generic values in a template first.

template Service "ifutil-template" {
  vars.check_ifutil_warning = “70”
  vars.check_ifutil_critical = “90”
  vars.check_ifutil_bandwidth = “100M”

  check_command = “ifutil”
  check_interval = 5m
  retry_interval = 1m
}

Then the service apply rules become more readable, and we can optimize this even further in terms of readability.

  • Import the template
  • Calculate the display name from host.vars.check_ifutil_interface, this makes this generic
  • Override the service custom variable from the host value
  • assign the apply rule generically to all hosts having this string attribute
apply Service “net traffic” {
  import "ifutil-template"

  display_name = name + " " + host.vars.check_ifutil_interface // beautify the display name in Icinga Web 

  vars.check_ifutil_interface = host.vars.check_ifutil_interface // fetch the value from the host

  assign where host.vars.check_ifutil_interface != "" // apply the rule on all hosts where this is a string value
}

There’s no need for two or three apply rules with the above. If you for example need a special handling for check_intervals or thresholds, you can also solve that with conditions like

  if (host.vars.check_ifutil_interface == "eth0") {
    //Override template imports
    vars.check_ifutil_warning = “80”
  } 

Cheers,
Michael

Hello back again Michael,

thanks for your suggestion, it looks promissing

I already try it with all hope into this configuration.
Unfortunatelly it results in the same.
I can see the new check, its applied, check vars are shown OK but its UNKNOWN.

icinga2 daemon -C result on target host

[2020-02-21 13:49:11 +0100] warning/ApplyRule: Apply rule ‘net traffic’ (in /var/lib/icinga2/api/zones/global-templates/_etc/mini.conf: 156:1-156:27) for type ‘Service’ does not match anywhere!

Its weird while its nor working only on few servers.
Manual run on server looks OK, even run as nagios user.

sudo -H -u nagios bash -c ‘/usr/lib/nagios/plugins/check_ifutil.pl -i ens192 -w 70 -c 90 -p -b 100M’
RX Bytes: 3TB, TX Bytes: 1TB; RX Speed: 384KBps, TX Speed: 261KBps; OK bandwidth utilization | rx=393657;73400320;94371840 tx=267447;73400320;94371840

What exactly you want from me to provide to you? There must be something bad. In situations like this it must be something stupid.

Many thanks for your support!

EDIT: Does the host name affect anything?
e.g.:
xyz-manager-1
VS
xyz_manager_1

EDIT 2: I also tried to move apply rule from global template to zone specific service.conf -> No luck
Second try I made assign for

assign where host.vars.check_ifutil_interface != “”

As you mentioned.
Other hosts (control_machine with icinga master itself) and 1 more server with changed name for interface (ens192) also work.
So I suspect this must be server specific (4 hosts installed in a bulk). But why?
Everything else works. All checks on these hosts.