-
Notifications
You must be signed in to change notification settings - Fork 11
/
check_lsyncd.sh
executable file
·74 lines (64 loc) · 1.6 KB
/
check_lsyncd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Warning : This is very ugly and does not read lua properly
# Other option, one script per sync
ret=0
check_lsync() {
src=$1
target=$2
mkdir -p "$src/.test"
date > "$src/.test/date"
datenow=$(date -r "$src/.test/date" +%s)
target_host=$(echo "$target" | cut -d ':' -f 1)
target_dir=$(echo "$target" | cut -d ':' -f 2)
# shellcheck disable=SC2034
for i in {1..5}; do
if datetarget=$(ssh -n "$target_host" "date -r $target_dir/.test/date +%s"); then
lag=$((datenow - datetarget))
if [ $lag -eq 0 ]; then
break
fi
sleep 1
else
exit 3
fi
done
if [ "$lag" -gt 3200 ]; then
retmsg="CRITICAL"
ret=2
elif [ "$lag" -gt 600 ] && [ $ret -lt 2 ]; then
retmsg="WARNING"
ret=1
else
retmsg="OK"
fi
echo "$retmsg - Last sync to $target was $lag seconds ago."
if [ $ret -ne 0 ]; then
exit $ret
fi
}
pids=""
while IFS="" read -r line; do
if echo "$line" | grep -q 'source ='; then
src=$(echo "$line" | cut -d "'" -f 2)
elif echo "$line" | grep -q 'target ='; then
target=$(echo "$line" | cut -d "'" -f 2)
elif echo "$line" | grep -q 'sync {'; then
src=""
target=""
fi
if [ -n "$src" ] && [ -n "$target" ]; then
check_lsync $src $target &
pids+=" $!"
src=""
target=""
fi
done < /etc/lsyncd/lsyncd.conf.lua
ret=0
for p in $pids; do
wait $p
p_ret=$?
if [ $p_ret -gt $ret ]; then
ret=$p_ret
fi
done
exit $ret