#!/bin/sh

IPSF='/etc/ips'
TMPF='/tmp/ysa_check_ips'
ip_errors=0

if [ -f "$IPSF" ] ; then
	ip add ls | grep inet | grep global | grep -v inet6 | awk {'print $2'} | cut -d/ -f1 > ${TMPF}_active_ips
	
	if [ -f ${TMPF}_active_ips ] ; then

		for ip in `grep : /etc/ips | cut -d: -f1` ; do
			grep -q $ip "${TMPF}_active_ips" || let "ip_errors++"
		done
		rm -f ${TMPF}_active_ips
		if (( $ip_errors > 0 )) ; then
			echo "IP STATUS: CRITICAL ($ip_errors IPs are down)"
			exit 2
		else
			echo "IP STATUS: OK"
			exit 0
		fi
	else
		t_size=$(df -Th | grep "/tmp" | awk {'print$5'})
		echo "IP STATUS: CRITICAL  unable to write /tmp | /tmp size $t_size"
		exit 2
	fi
else
	echo "IP STATUS: OK"
	exit 0
fi
