2010-11-26 00:35:33 +01:00
|
|
|
#!/bin/bash
|
2010-11-24 12:48:06 +01:00
|
|
|
#
|
|
|
|
# Copyright 2010, Pall Sigurdsson <palli@opensource.is>
|
|
|
|
#
|
|
|
|
# This script is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This script is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# About this script
|
|
|
|
#
|
|
|
|
# Checks uptime of a specified host, using NRPE is host is remote
|
|
|
|
|
|
|
|
HOSTN="localhost" # By default check localhost
|
|
|
|
CHECK_COMMAND="uptime" # Default command to check uptime
|
|
|
|
|
2010-12-02 12:17:05 +01:00
|
|
|
print_help() {
|
|
|
|
echo "$0 version $VERSION"
|
|
|
|
echo "This plugin checks uptime of local or remote host"
|
|
|
|
echo ""
|
|
|
|
echo "Usage: $0 [-H <host>]"
|
|
|
|
echo ""
|
|
|
|
echo "Example: Check uptime of a remote host"
|
|
|
|
echo "# $0 -H remotehost -s Enforcing"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse arguments
|
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case $1
|
|
|
|
in
|
|
|
|
-H)
|
|
|
|
HOSTN=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
print_help ;
|
|
|
|
exit $UNKNOWN
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-26 00:17:13 +01:00
|
|
|
# We we are not checking localhost, lets get remote uptime via NRPE
|
2010-11-26 00:35:33 +01:00
|
|
|
if [ "$HOSTN" != "localhost" ]; then
|
2010-12-14 17:23:02 +01:00
|
|
|
export PATH=$PATH:/usr/lib/nagios/plugins:/usr/lib64/nagios/plugins:/nagios/usr/lib/nagios/plugins
|
2010-11-26 00:17:13 +01:00
|
|
|
CHECK_COMMAND="check_nrpe -H $HOSTN -c get_uptime"
|
|
|
|
fi
|
|
|
|
|
2010-11-24 12:48:06 +01:00
|
|
|
|
2010-12-02 12:17:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-26 00:17:13 +01:00
|
|
|
# Get the uptime, raise error if we are unsuccessful
|
2010-11-24 12:48:06 +01:00
|
|
|
OUTPUT=`$CHECK_COMMAND`
|
|
|
|
RESULT=$?
|
|
|
|
|
|
|
|
if [ $RESULT -gt 0 ]; then
|
|
|
|
echo "Error - Could not run command $CHECK_COMMAND"
|
|
|
|
echo "Error was: $OUTPUT"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
2010-11-26 00:17:13 +01:00
|
|
|
# Parse the output from uptime command
|
2010-11-24 12:48:06 +01:00
|
|
|
set -- $OUTPUT
|
|
|
|
if [ $4 == 'min(s),' ]; then
|
|
|
|
echo "Warning, $HOSTN uptime is $OUTPUT"
|
|
|
|
exit 1
|
|
|
|
elif [ `echo $3 | grep -c :` -gt 0 ]; then
|
|
|
|
echo "Ok, ${HOSTN} uptime is $OUTPUT"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "Ok, ${HOSTN} uptime is $OUTPUT"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|