Page 1 of 1

check_icmp succeed on down host

Posted: Mon Mar 21, 2016 11:45 am
by doneil326
hello, is there a way to get the check_icmp module to return a success status when a host is down instead of up?

Re: check_icmp succeed on down host

Posted: Mon Mar 21, 2016 12:57 pm
by bheden
I think creating a script to wrap the check would be the way to go. Here is a VERY basic script, which could potentially aid you.

I created a file /usr/local/nagios/libexec/check_icmp_reverse.sh, and made it executable.

Here is the contents of check_icmp_reverse.sh

Code: Select all

#!/bin/sh

ICMP_RETURN=$(/usr/local/nagios/libexec/check_icmp "$@")

OLDIFS=$IFS
IFS=" - "
read -r ICMP_VAL ICMP_DATA <<< "$ICMP_RETURN"
IFS=$OLDIFS

if [ "$ICMP_VAL" == "CRITICAL" ]; then
        echo "OK - $ICMP_DATA"
else
        echo $ICMP_RETURN
fi

As of right now, that script only takes into account if the host is in Critical state, it will return Ok with all of the associated data returned from check_icmp. Otherwise, it just returns whatever check_icmp would have returned.

You can call this script using the exact same syntax as check_icmp (/usr/local/nagios/libexec/check_icmp_reverse -H localhost, etc.).

Hope this helps!