Saturday, November 10, 2012

Using arping in Zabbix

This is a quick recipe how to make Zabbix 2.x use arping instead of simple ICMP check with fping utility. Following method is more a proof of concept then a complete solution. Consider modify for your needs. Instead of messing with zabbix internals I chose to substitute fping utility (in zabbix_server.conf)

FpingLocation=/usr/sbin/fping.sh

The script parses input from Zabbix. Checks for some of arguments are hardcoded (-C3), thus if you change parameters of a simple check in Zabbix web interface it may failure.


#!/bin/bash
# /usr/sbin/fping.sh
#
export PATH=/root/bin:/sbin:/usr/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/default/bin/:/usr/local/bin/:/usr/local/sbin/:

while IFS=$'\n' read -r LINE || [[ -n "$LINE" ]];
do
    IP="$LINE";

if [[ "$1" == "-q" && "$2" == "-C3" ]];
then

    DEV=`ip route get $IP | cut -d' ' -f3|tr -d '\n'`
    # local
    if [[ $DEV == "local0" ]];
    then
        ARPING=`/sbin/arping -I local0 -c 3 $IP 2>&1|grep Unicast`;
        if [[ $ARPING == "" ]];
        then
            echo "$IP : - - -";
        else
            echo "$IP : 1.10 1.10 1.10";
        fi
    else
    # not local
         /usr/sbin/fping -q -C3 $IP 2>&1;
    fi
else
    # something else
    /usr/sbin/fping $1 $2 $3 $4 $IP 2>&1;
fi