-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_rsync
108 lines (95 loc) · 2.17 KB
/
check_rsync
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/ksh
#
#
#
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
VERSION="Version 0.1"
AUTHOR="Narayan Newton <[email protected]>"
PROGNAME=`/usr/bin/basename $0`
NOW="$(date +"%s")"
function revision {
echo "$PROGNAME - $VERSION"
}
function usage {
echo "Usage: $PROGNAME [-v] -w <age warning> -c <age critical>"
}
function help {
revision
usage
/bin/cat <<__EOT
OPTIONS:
-h
Print help screen
-V
Print version
-w
Exit with warning if timestamp file is greater than N old
-c
Exit with error if timestamp file is greater than N old
-t
Rsync Target Path
__EOT
}
while [ "$1" ]; do
case "$1" in
-h | --help)
help
exit $STATE_OK
;;
-V | --version)
revision
exit $STATE_OK
;;
-w | --warning | -c | --critical)
if [[ "$2" = +([0-9]) ]]; then
thresh=$2
[[ "$1" = *-w* ]] && thresh_warn=$thresh || thresh_crit=$thresh
shift 2
else
echo 'Number required'
exit $STATE_CRITICAL
fi
;;
-t | --target)
RSYNC_TARGET=$2
shift 2
;;
-?)
usage
exit $STATE_OK
;;
*)
echo "Invalid option '$1'"
usage
exit $STATE_CRITICAL
;;
esac
done
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
echo "Threshold not set"
usage
exit $STATE_CRITICAL
elif [[ "$thresh_crit" -lt "$thresh_warn" ]]; then
echo "Critical must be greater than warn threshold"
usage
exit $STATE_CRITICAL
elif [[ -z "$RSYNC_TARGET" ]]; then
echo "You must set a rsync target"
exit $STATE_CRITICAL
fi
timestamp=`cat ${RSYNC_TARGET}/.rsync_timestamp`
secdiff=$(( ${NOW} - ${timestamp} ))
if [ ${secdiff} -gt ${thresh_crit} ]; then
echo "RSYNC CRITICAL - timestamp file is ${secdiff} seconds old"
exit $STATE_CRITICAL
fi
if [ ${secdiff} -gt ${thresh_warn} ]; then
echo "RSYNC WARNING - timestamp file is ${secdiff} seconds old"
exit $STATE_WARNING
fi
echo "RSYNC OK - timestamp file is ${secdiff} seconds old"
exit $STATE_OK