]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | ||
3 | STATE_OK=0 | |
4 | STATE_WARNING=1 | |
5 | STATE_CRITICAL=2 | |
6 | STATE_UNKNOWN=3 | |
7 | ||
8 | distant_host="$1" | |
9 | replication_dn="$2" | |
10 | replication_pw="$3" | |
11 | base="$4" | |
12 | config="$5" | |
13 | ||
14 | to_date() { | |
15 | i="$1" | |
16 | i=$(echo "$i" | grep contextCSN | cut -d":" -f2 | sed -e "s/\s//g") | |
17 | i=$(echo "$i" | cut -d"#" -f1) | |
18 | i=$(echo "$i" | cut -d"." -f1) | |
19 | echo "$i" | |
20 | } | |
21 | ||
22 | # ldap | |
23 | remote_ldap=$(ldapsearch -H $distant_host -D "$replication_dn" -y "$replication_pw" -b "$base" -s base -LLL contextCSN ) | |
24 | exit_code_remote=$? | |
25 | remote_ldap=$(to_date "$remote_ldap") | |
26 | ||
27 | # slapcat | |
28 | local_ldap=$(slapcat -b "$base" -f "$config" -a "(entryDN=$base)") | |
29 | exit_code_local=$? | |
30 | local_ldap=$(to_date "$local_ldap") | |
31 | ||
32 | offset=$(($remote_ldap - $local_ldap)) | |
33 | ||
34 | if [[ $exit_code_remote -ne 0 || $exit_code_local -ne 0 ]]; then | |
35 | echo "UNKNOWN - Impossible to run ldap command" | |
36 | exit $STATE_UNKNOWN | |
37 | elif [[ -z "$offset" ]]; then | |
38 | echo "UNKNOWN - No replication found" | |
39 | exit $STATE_UNKNOWN | |
40 | else | |
41 | output="Replication lag for openldap is ${offset}s" | |
42 | LC_ALL=C lag=$(printf "%.*f" 0 $lag) | |
43 | ||
44 | if [[ $offset -lt 5 ]]; then | |
45 | echo "OK - $output | time=${offset}s;5;10;;" | |
46 | exit $STATE_OK | |
47 | elif [[ $offset -lt 10 ]]; then | |
48 | echo "WARNING - $output | time=${offset}s;5;10;;" | |
49 | exit $STATE_WARNING | |
50 | else | |
51 | echo "CRITICAL - $output | time=${offset}s;5;10;;" | |
52 | exit $STATE_CRITICAL | |
53 | fi | |
54 | fi |