+

Last commit for check_nfs_services: 4de3b7302bc928652723c0c25a82d2110a2c2a22

Initial commit

Benjamin Renard [2014-12-08 14:14:58]
Initial commit
#!/bin/bash

CHECK_NFSD=0
NFSD_PROCESS_NAME=nfsd

CHECK_MOUNTD=0
MOUNTD_PROCESS_NAME=rpc.mountd

CHECK_STATD=0
STATD_PROCESS_NAME=rpc.statd

CHECK_IDMAPD=0
IDMAPD_PROCESS_NAME=rpc.idmapd

CHECK_GSSD=0
GSSD_PROCESS_NAME=rpc.gssd

DEBUG=0

function usage() {
        echo "Usage : $0 [parameters]"
        echo
        echo "Check NFS services status"
        echo
        echo "Parameters :"
        echo "  -n               Enable check of nfsd status"
        echo "  -N process name  The process name of nfsd (Default : $NFSD_PROCESS_NAME)"
        echo "  -m               Enable check of mountd status"
        echo "  -M process name  The process name of mountd (Default : $MOUNTD_PROCESS_NAME)"
        echo "  -s               Enable check of statd status"
        echo "  -S process name  The process name of statd (Default : $STATD_PROCESS_NAME)"
        echo "  -i               Enable check of idmapd status"
        echo "  -I process name  The process name of idmapd (Default : $IDMAPD_PROCESS_NAME)"
        echo "  -g               Enable check of gssd status"
        echo "  -G process name  The process name of gssd (Default : $GSSD_PROCESS_NAME)"
        echo "  -d               Enable debug mode"
        echo "  -h               Show this message"
}

while getopts :nN:mM:sS:iI:gG:dh FLAG
do
        [ $DEBUG -eq 1 ] && echo "Parameter $FLAG present. Value : '$OPTARG'"
        case $FLAG in
		n)
			CHECK_NFSD=1
		;;
		N)
			NFSD_PROCESS_NAME=$OPTARG
		;;
		m)
			CHECK_MOUNTD=1
		;;
		M)
			MOUNTD_PROCESS_NAME=$OPTARG
		;;
                s)
                        CHECK_STATD=1
                ;;
		S)
			STATD_PROCESS_NAME=$OPTARG
		;;
		i)
			CHECK_IDMAPD=1
		;;
		I)
			IDMAPD_PROCESS_NAME=$OPTARG
		;;
		g)
			CHECK_GSSD=1
		;;
		G)
			GSSD_PROCESS_NAME=$OPTARG
		;;
                d)
                        DEBUG=1
                ;;
                h)
                        usage
                        exit 0
                ;;
		*)
			echo "Invalid parameter -$FLAG"
			usage
			exit 1
		;;
        esac
done

[ $CHECK_NFSD -eq 0 -a $CHECK_MOUNTD -eq 0 -a $CHECK_STATD -eq 0 -a $CHECK_IDMAPD -eq 0 -a $CHECK_GSSD -eq 0 ] && echo "You must enable check of at least one service" && usage && exit 1

STATE=OK
MSG=""
EXIT=0

function check_process() {
	check="$1"
	name="$2"
	process="$3"

	if [ "$check" == "1" ]
	then
		P=$( pidof "$process" )
		if [ $? -ne 0 ]
		then
			[ $DEBUG -eq 1 ] && echo "Process $process not found."
			MSG="$MSG - $name NOT running"
			STATE=CRITICAL
			EXIT=2
		else
			[ $DEBUG -eq 1 ] && echo "Process $process found. PID = $P"
			MSG="$MSG - $name is running"
		fi
	fi
}

check_process $CHECK_NFSD nfsd "$NFSD_PROCESS_NAME"
check_process $CHECK_MOUNTD mountd "$MOUNTD_PROCESS_NAME"
check_process $CHECK_STATD statd "$STATD_PROCESS_NAME"
check_process $CHECK_IDMAPD idmapd "$IDMAPD_PROCESS_NAME"
check_process $CHECK_GSSD gssd "$GSSD_PROCESS_NAME"

echo "${STATE}${MSG}"
exit $EXIT
ViewGit