#!/bin/bash
if [ -z "$1" ]
then
  echo "No hostname given."
  exit 3
fi
hostname=$1
state=$(/usr/bin/ssh -i /var/lib/nagios3/.ssh/id_rsa root@$hostname "ping -c 1 8.8.8.8|grep loss|sed 's/\([0-9]*\)%.*/\1/g;s/.*, *//g'")
if [ $state -eq 100 ]
then
  echo "CRITICAL - Network is Unreachable. $state"
  exit 1
elif [ $state -eq 0 ]
then
  echo "OK - Network is OK."
  exit 0
else
  echo "UNKOWN - Network is UNKNOW."
  exit 3
fi
exit 3
~
~