#!/bin/ksh

#
# Script to check health of network interfaces, helpful
# when using IPMP and a broken interface may otherwise
# go unnoticed.
#
# Eddie D. Anzalone, 21/Nov/2003
#
# Changed into a nagios plugin
#
# Mike Adams, Thu Sep 16 16:29:21 PDT 2004
#


PATH="/usr/bin:/usr/sbin" ; export PATH
ALERT="echo"


#
# Check network interfaces for failed links
#
ifconfig -a | awk '/FAILED/ {print $1}' | cut -d: -f1 | while read IN
do
	$ALERT "Network interface failure on $IN"
        exit 2
done


#
# Check network interfaces that are not up
#
ifconfig -a | awk '/^[a-z]*[0-9]:/ {print $0}' | grep -v 'UP,' | while read IN
do
	DEV=`echo $IN | cut -d: -f1`
	$ALERT "Network interface $DEV is down"
        exit 2
done


# If we made it this far, everything must look ok
$ALERT "Network interfaces are OK"
exit 0
