Skip to content
Snippets Groups Projects
Commit de3ae8a5 authored by Andreas Unterkircher's avatar Andreas Unterkircher
Browse files

initial import, version 1.0

parents
Branches
Tags v1.0
No related merge requests found
# Changes in check_doveadm_replication
# 1.0
* Initial release
Copyright 2015-2017 Patrick Kirsch patrick.kirsch@olanis.de
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This is check_doveadm_replication.sh.
This plugin allows checking the dsync-based replication state of Dovecot
between a Dovecot server pair (2 nodes).
The original plugin can be found at the following URL:
https://gist.github.com/patrickkirsch/950d5d184fac6fa854f2
See LICENSE file for licensing information.
Original author:
(c) 2015-2017 Patrick Kirsch <patrick.kirsch@olanis.de>
Modifications:
2017 Andreas Unterkircher <unki@netshadow.net>
#!/bin/bash
#
# Nagios NRPE wrapper for dovecot replicator status
#
# Installation hint:
#
# cat > /etc/nagios/nrpe.d/dovecot.cfg <<EOD
# command[check_doveadm_repli]=/srv/scripte/check_doveadm_replication.sh status
# command[check_doveadm_repli_json]=/srv/scripte/check_doveadm_replication.sh json
# EOD
#
#
# Patrick Kirsch patrick.kirsch@olanis.de
# License: MIT
DOVEADM='/usr/bin/doveadm'
PROGNAME=`basename $0`
VERSION="Version 1.0"
AUTHOR="Patrick Kirsch"
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
print_version() {
echo "$PROGNAME $VERSION $AUTHOR"
}
print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME - Checks Dovecot replication status"
echo ""
echo "$PROGNAME is a Nagios wrapper for showing dovecot replication errors"
echo ""
echo "Usage:"
echo " $PROGNAME -s runs doveadm replicator status"
echo " $PROGNAME -j runs doveadm replicator status and outputs json (useful for comparing replication between hosts at nagios server side)"
echo ""
exit $STATE_OK
}
# check for dependencies
if [ ! -e $DOVEADM ] || [ ! -x $DOVEADM ]; then
echo "Doveadm ($DOVEADM) is not present or executeable!"
echo "This script heavily depends on it!"
echo ""
exit $STATE_CRITICAL
fi
json_output() {
#tmpfile="$(mktemp)"
tmpfile="/tmp/doveadm"
$DOVEADM replicator status | sed "s/'//g" > $tmpfile
perl -e 'use JSON; @in=grep(s/\n$//, <>); %h=map{/(.+?)\s+(\d+)/;$1 => $2} @in; print encode_json(\%h)."\n";' $tmpfile
exit $STATE_OK
}
check_replicator_status() {
#tmpfile="$(mktemp)"
tmpfile="/tmp/doveadm"
$DOVEADM replicator status | sed "s/'//g" > $tmpfile
requests=`grep 'requests' $tmpfile | wc -l`
if [ "$requests" == "0" ]; then
echo "UKNOWN - No requests found. Check manual doveadm replicator output!"
exit $STATE_UNKNOWN
fi
critical_req_full_resync=`perl -n -e '/full resync requests.+?(\d+)/g && print $1' $tmpfile`
critical_req_failed_queue=`perl -n -e '/Queued failed requests.+?(\d+)/g && print $1' $tmpfile`
critical_req_failed_waiting=`perl -n -e '/Waiting failed requests.+?(\d+)/g && print $1' $tmpfile`
ok_known_users=`perl -n -e '/of known users\s+(\d+)/ && print $1' $tmpfile`
if [ ! -z "$critical_req_full_resync" ]; then
echo "CRITICAL - Doveadmin full resync requests: $critical_req_full_resync"
exit $STATE_CRITICAL
fi
if [ ! -z "$critical_req_failed_queue" ]; then
echo "CRITICAL - Doveadmin queued failed resync requests: $critical_req_failed_queue"
exit $STATE_CRITICAL
fi
if [ ! -z "$critical_req_failed_waiting" ]; then
echo "CRITICAL - Doveadmin waiting failed requests: $critical_req_failed_waiting"
exit $STATE_CRITICAL
fi
echo "OK - doveadm replicator users: $ok_known_users"
exit $STATE_OK
}
# Check for parameters
while test -n "$1"; do
case "$1" in
-h)
print_help
exit $STATE_OK;;
-v)
print_version
exit $STATE_OK;;
-s)
check_replicator_status
;;
status)
check_replicator_status
;;
-j)
json_output
;;
json)
json_output
;;
esac
shift
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment