#!/bin/sh # # Check_Service Rel. 1.00 # # Copyleft 2004 IBCL # # Author: Christoph Lechleitner # # Please call # check_service --help # for usage information # # reading parameters SERVICENAME="$1" shift OPTIONS="$*" if [ $(echo " $SERVICENAME $OPTIONS " |egrep -i -- " (-v|--version) ") ] then echo "check_service 1.00 by Christoph Lechleitner " exit 0 fi if [ $(echo " $SERVICENAME $OPTIONS " |egrep -i -- " (-h|--help) ") ] then echo ' Service check plugin for Nagios 1.x, Release 1.00, Copyleft 2004 by IBCL.at Usage: check_service servicename [--tryrestart] check_service -h|--help check_service -v|--version Options: servicename Name of script in /etc/init.d -h, --help Prints this help text --tryrestart Tries to restart a dead service. -v, --version Prints the version information Checks, if a service runs and optionally tries to restart it. Requirements: /etc/init.d/ status must return 0 if and only if service is ok /etc/init.d/ restart must try to (stop and) start the service If you have comments or suggestions, feel free to contact the Author: Christoph Lechleitner ' exit 0 fi if [ "$SERVICENAME" == "" ] then echo "Service UNKNOWN No servicename given." echo "Usage: check_service servicename [--tryrestart] [--help] [--version]" exit 3 fi if [ ! -x /etc/init.d/$SERVICENAME ] then echo "Service UNKNOWN $SERVICENAME not found in /etc/init.d" exit 3 fi STATUSMSG=$(/etc/init.d/$SERVICENAME status) RC=$? if [ $RC == 0 ] then echo "Service OK $SERVICENAME $STATUSMSG" exit 0 else if [ $(echo " $OPTIONS " |grep -i -- " --tryrestart ") ] then RESTARTMSG=$(/etc/init.d/$SERVICENAME restart) STATUS2MSG=$(/etc/init.d/$SERVICENAME status) RC2=$? if [ $RC2 == 0 ] then echo "Service WARNING Had to restart $SERVICENAME" exit 1 else echo "Service CRITICAL Failed to restart $SERVICENAME $STATUS2MSG" exit 2 fi else echo "Service CRITICAL $SERVICENAME $STATUSMSG" exit 2 fi fi