88 lines
1.5 KiB
Plaintext
88 lines
1.5 KiB
Plaintext
|
#!/bin/bash
|
||
|
#
|
||
|
# Nagios plugin to check slapd schema
|
||
|
#
|
||
|
# Author : Benjamin Renard <brenard@easter-eggs.com>
|
||
|
# Date : Wed, 12 Jun 2019 13:15:33 +0200
|
||
|
# Source : http://gogs.zionetrix.net/check_slapd_schema
|
||
|
#
|
||
|
|
||
|
SUDO_USER=""
|
||
|
SLAPSCHEMA=slapschema
|
||
|
DB_ID=""
|
||
|
DEBUG=0
|
||
|
|
||
|
function debug() {
|
||
|
if [ $DEBUG -eq 1 ]
|
||
|
then
|
||
|
>&2 echo -e "[DEBUG] $1"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function usage() {
|
||
|
cat << EOF
|
||
|
Usage : $0 [-d] [-h] [options]
|
||
|
-u Sudo as specified user to run slapschema
|
||
|
-s Path to slapschema (Default : auto-detected)
|
||
|
-n Slapd database ID (Default : auto-detected)
|
||
|
-d Debug mode
|
||
|
-h Show this message
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
while getopts "hu:s:n:d" OPTION
|
||
|
do
|
||
|
case $OPTION in
|
||
|
u)
|
||
|
SUDO_USER=$OPTARG
|
||
|
;;
|
||
|
s)
|
||
|
SLAPSCHEMA=$OPTARG
|
||
|
;;
|
||
|
n)
|
||
|
DB_ID=$OPTARG
|
||
|
;;
|
||
|
d)
|
||
|
DEBUG=1
|
||
|
;;
|
||
|
h)
|
||
|
usage
|
||
|
exit 0
|
||
|
;;
|
||
|
*)
|
||
|
echo "Unkown option '$OPTION'"
|
||
|
usage
|
||
|
exit 1
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
CMD="$SLAPSCHEMA"
|
||
|
[ -n "$DB_ID" ] && CMD="$CMD -n $DB_ID"
|
||
|
debug "slapschema command = '$CMD'"
|
||
|
|
||
|
if [ -n "$SUDO_USER" ]
|
||
|
then
|
||
|
debug "run slapdschema command as $SUDO_USER"
|
||
|
ERRORS=$( sudo -u $SUDO_USER $CMD 2>&1 > /dev/null )
|
||
|
EXITCODE=$?
|
||
|
else
|
||
|
ERRORS=$( $CMD 2>&1 > /dev/null )
|
||
|
EXITCODE=$?
|
||
|
fi
|
||
|
debug "Errors :\n$ERRORS"
|
||
|
debug "Exit code : $EXITCODE"
|
||
|
|
||
|
if [ $EXITCODE -ne 0 ]
|
||
|
then
|
||
|
echo "UNKNOWN - slapschema exit with $EXITCODE"
|
||
|
exit 3
|
||
|
elif [ -z "$ERRORS" ]
|
||
|
then
|
||
|
echo "OK - no error detected in slapd schema"
|
||
|
exit 0
|
||
|
else
|
||
|
count=$( echo -e "$ERRORS"|wc -l )
|
||
|
echo "WARNING - $count error(s) detected in slapd schema"
|
||
|
echo -e "$ERRORS"
|
||
|
fi
|