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

1 Like

Thank you @mfriedrich

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