forked from pool/monitoring-plugins-nis
OBS-URL: https://build.opensuse.org/package/show/server:monitoring/monitoring-plugins-nis?expand=0&rev=3
148 lines
3.3 KiB
Bash
148 lines
3.3 KiB
Bash
#!/bin/sh
|
|
###############################################
|
|
#
|
|
# Nagios script to check NIS status on a host
|
|
#
|
|
# Copyright 2007, 2008 Ian Yates
|
|
#
|
|
# See usage for command line switches
|
|
#
|
|
# Created: 2006-07-04 (i.yates@uea.ac.uk)
|
|
# Updated: 2007-07-30 (i.yates@uea.ac.uk) - Added user lookup and error checking
|
|
# Updated: 2008-11-27 (i.yates@uea.ac.uk) - Added GPLv3 licence
|
|
#
|
|
# This program 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 program 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/>.
|
|
#
|
|
###############################################
|
|
|
|
. /usr/local/nagios/libexec/utils.sh
|
|
|
|
|
|
VERSION="1.2"
|
|
|
|
AWK=/bin/awk
|
|
SED=/bin/sed
|
|
GREP=/bin/grep
|
|
YPPOLL=/usr/sbin/yppoll
|
|
YPCAT=/usr/bin/ypcat
|
|
|
|
|
|
FLAG_VERBOSE=FALSE
|
|
NIS_HOST=""
|
|
NIS_DOMAIN=""
|
|
NIS_USER_TEST=""
|
|
RESULT=""
|
|
EXIT_STATUS=$STATE_OK
|
|
|
|
|
|
###############################################
|
|
#
|
|
## FUNCTIONS
|
|
#
|
|
|
|
## Print usage
|
|
usage() {
|
|
echo " check_nis $VERSION - Nagios NIS check script"
|
|
echo ""
|
|
echo " Usage: check_nis -H <hostname> -d <nis domain> [ -u <username> ] [ -v ] [ -h ]"
|
|
echo ""
|
|
echo " -H Name of host running the NIS service you wish to check"
|
|
echo " -d NIS domain"
|
|
echo " -u Username to query NIS with"
|
|
echo " -v Verbose output"
|
|
echo " -h Show this page"
|
|
echo ""
|
|
}
|
|
|
|
## Process command line options
|
|
doopts() {
|
|
if ( `test 0 -lt $#` )
|
|
then
|
|
while getopts H:d:u:vh myarg "$@"
|
|
do
|
|
case $myarg in
|
|
h|\?)
|
|
usage
|
|
exit;;
|
|
H)
|
|
NIS_HOST=$OPTARG;;
|
|
d)
|
|
NIS_DOMAIN=$OPTARG;;
|
|
u)
|
|
NIS_USER_TEST=$OPTARG;;
|
|
v)
|
|
FLAG_VERBOSE=TRUE;;
|
|
*) # Default
|
|
usage
|
|
exit;;
|
|
esac
|
|
done
|
|
else
|
|
usage
|
|
exit
|
|
fi
|
|
}
|
|
|
|
|
|
# Write output and return result
|
|
theend() {
|
|
echo $RESULT
|
|
exit $EXIT_STATUS
|
|
}
|
|
|
|
|
|
#
|
|
## END FUNCTIONS
|
|
#
|
|
|
|
#############################################
|
|
#
|
|
## MAIN
|
|
#
|
|
|
|
|
|
# Handle command line options
|
|
doopts $@
|
|
|
|
# Do the do
|
|
OUTPUT=`$YPPOLL -h $NIS_HOST -d $NIS_DOMAIN passwd.byname 2> /dev/null | $GREP 'is supported'`
|
|
if test "$OUTPUT" != "" ; then
|
|
if test -n "$NIS_USER_TEST" ; then
|
|
## If we're checking user lookup
|
|
OUTPUT=`$YPCAT -h $NIS_HOST -d $NIS_DOMAIN passwd | grep $NIS_USER_TEST`
|
|
if test -n "$OUTPUT" ; then
|
|
OUTPUT=`echo "$OUTPUT" | grep "RPC"`
|
|
if test "$OUTPUT" != "" ; then
|
|
RESULT="NIS CRITICAL - domain $NIS_DOMAIN, user \"$NIS_USER_TEST\" lookup failed"
|
|
EXIT_STATUS=$STATE_CRITICAL
|
|
else
|
|
RESULT="NIS OK - domain $NIS_DOMAIN, user \"$NIS_USER_TEST\" lookup succeeded"
|
|
EXIT_STATUS=$STATE_OK
|
|
fi
|
|
else
|
|
RESULT="NIS CRITICAL - domain $NIS_DOMAIN, user \"$NIS_USER_TEST\" lookup failed"
|
|
EXIT_STATUS=$STATE_CRITICAL
|
|
fi
|
|
else
|
|
RESULT="NIS OK - domain $NIS_DOMAIN"
|
|
EXIT_STATUS=$STATE_OK
|
|
fi
|
|
else
|
|
RESULT="NIS CRITICAL - domain $NIS_DOMAIN not answering"
|
|
EXIT_STATUS=$STATE_CRITICAL
|
|
fi
|
|
|
|
# Quit and return information and exit status
|
|
theend
|