Last active
June 18, 2018 16:34
-
-
Save ilyaevseev/1986d40137a1c3859c66021ea0c62b56 to your computer and use it in GitHub Desktop.
Quick and dirty Zabbix check for replication status between OpenLDAP master and slave. Should be called on slave.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CONFIG="/etc/openldap/slapd.d/cn=config/olcDatabase={2}hdb.ldif" | |
Return() { echo $@; exit; } | |
test -s "$CONFIG" || Return "BAD_CONF" | |
URL="$(sed -n 'H; ${ x; s/\n//; s/\n //g; p}' "$CONFIG" | awk 'match($0, "provider=([^ ]+)", m) { print m[1] }')" ; test -z "$URL" && Return "BAD_URL" #' | |
DN="$(sed -n 'H; ${ x; s/\n//; s/\n //g; p}' "$CONFIG" | awk 'match($0, "binddn=\"([^ ]+)\"", m) { print m[1] }')" ; test -z "$DN" && Return "BAD_DN" #' | |
BASE="$(sed -n 'H; ${ x; s/\n//; s/\n //g; p}' "$CONFIG" | awk 'match($0, "base=\"([^ ]+)\"", m) { print m[1] }')" ; test -z "$BASE" && Return "BAD_BASE" #' | |
PASS="$(sed -n 'H; ${ x; s/\n//; s/\n //g; p}' "$CONFIG" | awk 'match($0, "credentials=([^ ]+)", m) { print m[1] }')" ; test -z "$PASS" && Return "BAD_PASS" #' | |
EMPTY="$(true | sha512sum)" | |
A="$(ldapsearch -x -w "$PASS" -D "$DN" -b "$BASE" -LLL -h 127.0.0.1 2>/dev/null | sha512sum)" ; test "$A" = "$EMPTY" && Return "BAD_LOCAL" | |
B="$(ldapsearch -x -w "$PASS" -D "$DN" -b "$BASE" -LLL -H "$URL" 2>/dev/null | sha512sum)" ; test "$B" = "$EMPTY" && Return "BAD_REMOTE" | |
test "$A" = "$B" && Return "OK" || Return "MISMATCH" | |
## END ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment