blob: b511ff203b1d42af641aa04df6fdb5e7eee1ec20 (
plain) (
tree)
|
|
#!/bin/bash
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
distant_host="$1"
replication_dn="$2"
replication_pw="$3"
base="$4"
config="$5"
to_date() {
i="$1"
i=$(echo "$i" | grep contextCSN | cut -d":" -f2 | sed -e "s/\s//g")
i=$(echo "$i" | cut -d"#" -f1)
i=$(echo "$i" | cut -d"." -f1)
echo "$i"
}
# ldap
remote_ldap=$(ldapsearch -H $distant_host -D "$replication_dn" -y "$replication_pw" -b "$base" -s base -LLL contextCSN )
exit_code_remote=$?
remote_ldap=$(to_date "$remote_ldap")
# slapcat
local_ldap=$(slapcat -b "$base" -f "$config" -a "(entryDN=$base)")
exit_code_local=$?
local_ldap=$(to_date "$local_ldap")
offset=$(($remote_ldap - $local_ldap))
if [[ $exit_code_remote -ne 0 || $exit_code_local -ne 0 ]]; then
echo "UNKNOWN - Impossible to run ldap command"
exit $STATE_UNKNOWN
elif [[ -z "$offset" ]]; then
echo "UNKNOWN - No replication found"
exit $STATE_UNKNOWN
else
output="Replication lag for openldap is ${offset}s"
LC_ALL=C lag=$(printf "%.*f" 0 $lag)
if [[ $offset -lt 5 ]]; then
echo "OK - $output"
exit $STATE_OK
elif [[ $offset -lt 10 ]]; then
echo "WARNING - $output"
exit $STATE_WARNING
else
echo "CRITICAL - $output"
exit $STATE_CRITICAL
fi
fi
|