forked from inuits/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_drupal-cron
executable file
·56 lines (48 loc) · 1.22 KB
/
check_drupal-cron
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
#!/bin/bash
NOW=$(date +%s)
RETVAL=3
if [ -x /usr/local/bin/drush ];then
DRUSH='/usr/local/bin/drush'
elif [ -x /usr/bin/drush ];then
DRUSH='/usr/bin/drush'
else
DRUSH=`which drush`
if [ $? != 0 ]; then
echo "UNKNOWN: Drush is not installed or it's not in PATH"
RETVAL=3
exit $RETVAL
fi
fi
while getopts u:r:c:w: o; do
case "$o" in
u) uri="$OPTARG";;
r) root="$OPTARG";;
w) warning="$OPTARG";;
c) critical="$OPTARG";;
esac
done
if [ -z $uri ] || [ -z $root ] || [ -z $warning ] || [ -z $critical ]; then
echo "All the paramaters are required"; exit $RETVAL
fi
LAST_CRON_RUN=$(${DRUSH} --root=${root} --uri=${uri} vget '^cron_last$'|cut -d: -f 2)
DELTA=$(($NOW - $LAST_CRON_RUN))
#Check if Drush executed correctly
if [ $? != 0 ]; then
echo "UNKNOWN: Drush didn't execute correctly"
RETVAL=3
else
#Check Critical threshold
if [ $DELTA -gt ${critical} ]; then
echo "CRITICAL: Cron ran $DELTA seconds ago"
RETVAL=2
#Check Warning threshold
elif [ $DELTA -gt ${warning} ]; then
echo "WARNING: Cron ran $DELTA seconds ago"
RETVAL=1
#Everything is normal
else
echo "OK: Cron ran $DELTA seconds ago"
RETVAL=0
fi
fi
exit $RETVAL