Initial version
This commit is contained in:
commit
2acd8c085f
3 changed files with 127 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*~
|
||||||
|
.*.swp
|
38
README.md
Normal file
38
README.md
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
Nagios plugin to check slapd schema
|
||||||
|
===================================
|
||||||
|
|
||||||
|
This script could be used as Nagios check plugin to check schema compliance of the contents of a slapd database.
|
||||||
|
|
||||||
|
This script use slapschema utility to do this check.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
Usage : check_slapd_schema [-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
|
||||||
|
|
||||||
|
Copyright
|
||||||
|
---------
|
||||||
|
|
||||||
|
Copyright (c) 2019 Benjamin Renard
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License version 3
|
||||||
|
as published by the Free Software Foundation.
|
||||||
|
|
||||||
|
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, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
87
check_slapd_schema
Executable file
87
check_slapd_schema
Executable file
|
@ -0,0 +1,87 @@
|
||||||
|
#!/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
|
Loading…
Reference in a new issue