From 2acd8c085f070d74cacd0fe93078d47ae34587d6 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 12 Jun 2019 13:22:52 +0200 Subject: [PATCH] Initial version --- .gitignore | 2 ++ README.md | 38 ++++++++++++++++++++ check_slapd_schema | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 check_slapd_schema diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c5f88a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +.*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..3250267 --- /dev/null +++ b/README.md @@ -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. + diff --git a/check_slapd_schema b/check_slapd_schema new file mode 100755 index 0000000..6d27a39 --- /dev/null +++ b/check_slapd_schema @@ -0,0 +1,87 @@ +#!/bin/bash +# +# Nagios plugin to check slapd schema +# +# Author : Benjamin Renard +# 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