Check multi IP

Good morning,

I want to check more than one IP on a host/ more IPs from a host, but I think my config does not work:

Service:

apply Service for (ping => config in host.vars.ping_additional) {
    import "generic-service"
    check_command = "ping"

	vars += config
	vars.ping = ping	
	vars.sla = "workhours"
	
	display_name = "ping-" + vars.descr

	 vars.notification["mail"] = {
        groups = [ "unix" ]
      }

        assign where host.vars.ping_additional != ""
}

Host (example):

object Host		"example" {
    import		"generic-host"
    address =			"IP"
    notes =			"Developement"
    vars.ping_additional["172.0.0.100"] = { descr = "sapascs50ds1" }
    vars.ping_additional["172.0.0.110"] = { descr = "sapascs50ds2" }
}

Icingaweb Output:

Unbenannt

Status OK, but there is no change to critical when the second IP is unreachable.

Is there a better way to check multi IPs for host cluster?

I think I found a solution with ping4-check:

apply Service for (ping => config in host.vars.ping_additional) {
    import "generic-service"
    check_command = "ping4"

    vars += config
    vars.ping_address = ping
    vars.sla = "workhours"

    display_name = "ping-" + vars.descr

     vars.notification["mail"] = {
        groups = [ "unix" ]
      }

        assign where host.vars.ping_additional != ""
}

object Host     "host" {
....
....
....
    vars.ping_additional["172.00.00.100"] = { descr = "ip" }
}

My test was successfull. :stuck_out_tongue:

with check_icmp you can just check multiple ips at the same time.
just separate them by a space:

./check_icmp -h
Copyright (c) 2005 Andreas Ericsson <ae@op5.se>
Copyright (c) 2005-2008 Monitoring Plugins Development Team
        <devel@monitoring-plugins.org>



Usage:
 check_icmp [options] [-H] host1 host2 hostN

Options:
 -h, --help
    Print detailed help screen
 -V, --version
    Print version information
 --extra-opts=[section][@file]
    Read options from an ini file. See
    https://www.monitoring-plugins.org/doc/extra-opts.html
    for usage and examples.
 -H
    specify a target
 -w
    warning threshold (currently 200,000ms,40%)
 -c
    critical threshold (currently 500,000ms,80%)
 -s
    specify a source IP address or device name
 -n
    number of packets to send (currently 5)
 -i
    max packet interval (currently 80,000ms)
 -I
    max target interval (currently 0,000ms)
 -m
    number of alive hosts required for success
 -l
    TTL on outgoing packets (currently 0)
 -t
    timeout value (seconds, currently  10)
 -b
    Number of icmp data bytes to send
    Packet size will be data bytes + icmp header (currently 68 + 8)
 -v
    verbose

 ./check_icmp -H 8.8.8.8 100.100.100.100 -m 1
OK - 8.8.8.8: rta 2,219ms, lost 0% :: 100.100.100.100: rta nan, lost 100%|8.8.8.8rta=2,219ms;200,000;500,000;0; 8.8.8.8pl=0%;40;80;; 8.8.8.8rtmax=2,366ms;;;; 8.8.8.8rtmin=2,111ms;;;; 100.100.100.100rta=0,000ms;200,000;500,000;0; 100.100.100.100pl=100%;40;80;; 100.100.100.100rtmax=0,000ms;;;; 100.100.100.100rtmin=0,000ms;;;;
1 Like

Thank you @log1c!!

That is the same in my config with icmp instead of ping4.

Both works perfect! :hugs:

Hi,

that generates two or more ping service object for your host.

ICMP over all addresses

With using icmp you can just define an array of addresses like this:

object Host "h1" {
  check_command = "hostalive"
  adress = "..."

  vars.ping_additional = [ "192.168.3.1" ]
}

apply Service "icmp-all" {
  check_command = "icmp"

  if (typeof(host.vars.ping_additional) == Array) {
    vars.icmp_address = host.vars.ping_additional + [ address ]
  } else {
    vars.icmp_address = [ host.vars.ping_additional, address ]
  }

  assign where len(host.vars.ping_additional) > 0
} 

Only additional ICMP

Depending on your needs you may remove the address attribute above, this is just to build the entire array and ping everything including the host’s address. A minimized version could look like this:

apply Service "icmp" {
  check_command = "icmp"

  vars.icmp_address = host.vars.ping_additional

  assign where len(host.vars.ping_additional) > 0
} 

ICMP config on the host

Likewise, you could also move icmp_address directly into the host object without specifying it on the service apply rule. This creates even more readable configuration.

object Host "h1" {
  check_command = "hostalive"
  adress = "..."

  vars.icmp_address = [ "1.2.3.4", "192.168.3.1" ]
}

apply Service "icmp" {
  check_command = "icmp"

  assign where len(host.vars.icmp_address) > 0 || host.address != ""
} 

If you don’t want to create an extra service just replace the hostalive check command in the host object. Keep in mind here that the host being down from 2 addresses may create trouble with notifications and dependencies - better have this as additional service.

The above should work, I did not test it inside config validation :kissing_heart:

Cheers,
Michael

2 Likes

Thank you @dnsmichi

I need a description for every single additional IP.
I am happy with my config, which solve my problem. :slight_smile:

apply Service for (icmp => config in host.vars.icmp_extra) {
    import "generic-service"
    check_command = "icmp"

    vars += config
    vars.icmp_address = icmp
    vars.sla = "workhours"

    display_name = "icmp-" + vars.descr

    assign where host.vars.icmp_extra 
} 

object Host     "h1" {
    ....
    ....

    vars.icmp_extra["172.00.00.000"] = { descr = "ip2" }
    vars.icmp_extra["172.00.00.001"] = { descr = "ip3" }
}
1 Like

If you are using the director, there is a easy way for this. Look at this example from the docs: https://github.com/Icinga/icingaweb2-module-director/blob/master/doc/15-Service-apply-for-example.md. This example describes how to Monitor tcp ports. We use this way for our checks, if a device has more than one IP. The director will do the Magic for us and it works fine.

2 Likes

this config failed to pass icinga daemon -C

[root@cent1 conf.d]# icinga2 daemon -C
[2019-12-21 02:56:04 -0500] information/cli: Icinga application loader (version: 2.11.2-1)
[2019-12-21 02:56:04 -0500] information/cli: Loading configuration file(s).
[2019-12-21 02:56:04 -0500] information/ConfigItem: Committing config item(s).
[2019-12-21 02:56:04 -0500] information/ApiListener: My API identity: cent1
[2019-12-21 02:56:04 -0500] critical/config: Error: Error while evaluating expression: Tried to access undefined script variable ‘address’
Location: in /etc/icinga2/conf.d/services.conf: 155:55-155:61
/etc/icinga2/conf.d/services.conf(153):
/etc/icinga2/conf.d/services.conf(154): if (typeof(host.vars.ping_additional) == Array) {
/etc/icinga2/conf.d/services.conf(155): vars.icmp_address = host.vars.ping_additional + [ address ]
^^^^^^^
/etc/icinga2/conf.d/services.conf(156): } else {
/etc/icinga2/conf.d/services.conf(157): vars.icmp_address = [ host.vars.ping_additional, address ]

[2019-12-21 02:56:04 -0500] critical/config: 1 error
[2019-12-21 02:56:04 -0500] critical/cli: Config validation failed. Re-run with ‘icinga2 daemon -C’ after fixing the config.

service failed to start

Dec 21 02:44:15 cent1 icinga2[2951]: [2019-12-21 02:44:15 -0500] critical/config: Error: Error while evaluating expression: Tried to access undefined script variabl
Dec 21 02:44:15 cent1 icinga2[2951]: Location: in /etc/icinga2/conf.d/services.conf: 157:54-157:60
Dec 21 02:44:15 cent1 icinga2[2951]: /etc/icinga2/conf.d/services.conf(155): vars.icmp_address = host.vars.ping_additional + [ address ]
Dec 21 02:44:15 cent1 icinga2[2951]: /etc/icinga2/conf.d/services.conf(156): } else {
Dec 21 02:44:15 cent1 icinga2[2951]: /etc/icinga2/conf.d/services.conf(157): vars.icmp_address = [ host.vars.ping_additional, address ]
Dec 21 02:44:15 cent1 icinga2[2951]: ^^^^^^^
Dec 21 02:44:15 cent1 icinga2[2951]: /etc/icinga2/conf.d/services.conf(158): }
Dec 21 02:44:15 cent1 icinga2[2951]: /etc/icinga2/conf.d/services.conf(159):
Dec 21 02:44:15 cent1 icinga2[2951]: [2019-12-21 02:44:15 -0500] critical/config: 1 error
Dec 21 02:44:15 cent1 icinga2[2951]: [2019-12-21 02:44:15 -0500] critical/cli: Config validation failed. Re-run with ‘icinga2 daemon -C’ after fixing the config.
Dec 21 02:44:15 cent1 systemd[1]: icinga2.service: main process exited, code=exited, status=1/FAILURE
Dec 21 02:44:15 cent1 systemd[1]: Failed to start Icinga host/service/network monitoring system.
– Subject: Unit icinga2.service has failed

===
services.conf
apply Service “icmp-all” {
check_command = “icmp”

if (typeof(host.vars.ping_additional) == Array) {
vars.icmp_address = host.vars.ping_additional + [ address ]
} else {
vars.icmp_address = [ host.vars.ping_additional, address ]
}

assign where len(host.vars.ping_additional) > 0
}

==========
hosts.conf

object Host "cent1" {


vars.ping_additional =["192.168.1.1"] 
  }

Should be host.address.

Happy holidays,
Michael

Hello all,

I just found this thread here and I am playing with this check. Though, I’ve found a weird behaviour of this check. My check has a list of 16 hosts and the value for -m is 11, but with already one dead hosts, my check goes critical, but it should have been OK. Then I’ve tried something else: A list with only two hosts (both alive) and a value of 3 for -m, check goes OK, but should have been Critical, or?
Both checks don’t work as expected or as I understood the options, and I only use -m and -H. My version: check_icmp v2.3.1 (nagios-plugins 2.3.1)

I am little bit confused right now :frowning: Any ideas?

Greetings René

Had the same issue a while back:

According to the maintainer the problem was fixed with 2.3.0.
Seems like it wasn’t.
By this time I had switched to check_mping for pinging my ip addresses, so I didn’t even confirm, if it was working or not.

1 Like

Hi log1c,

thanks for your reply and confirming that I wasn’t the only one with this problem. I will try compiling it, as mentioned in https://github.com/nagios-plugins/nagios-plugins/pull/487 and will report how it worked.
As a matter of fact I do need a check where I get a Critical when a given number of hosts is not alive :slight_smile:
Greetings

René

1 Like

check_mping does that as well, but I’m not sure if you can do 16 addresses :smiley:

1 Like

Hi log1c,

I haven’t found this option with check_mping :frowning:
What I’ve did so far:

  • Get the git-repo
  • Compiled it
  • and then ran the “new” check_icmp with just the -m and -H options

Tadaaa! It works now, when I have more dead hosts as given with the -m option it goes Critical :slight_smile:
Now I have to decide on how to use it on my monitoring server, maybe copying it to a special directory (so it won’t interfere with updates) and build a new check command in Icinga is the best solution.

René

2 Likes