-
Notifications
You must be signed in to change notification settings - Fork 57
/
check_drupal-cron
executable file
·74 lines (65 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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
# Workaround for https://github.com/drush-ops/drush/issues/2183.
# On older Drush 8.x versions, .my.cnf has preference over settings.php,
# which causes `drush state-get system.cron_last` to fail.
if [[ -f "${HOME}/.my.cnf" ]]
then
DRUSH_HOME="/tmp"
else
DRUSH_HOME="${HOME}"
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
DRUPAL_VERSION=$(${DRUSH} --root=${root} --uri=${uri} status | grep 'Drupal version' | sed 's/.*:\s*//')
if [[ "$DRUPAL_VERSION" =~ ^[6-7] ]]
then
# drupal 6/7
LAST_CRON_RUN=$(HOME=${DRUSH_HOME} ${DRUSH} --root=${root} --uri=${uri} vget '^cron_last$'|cut -d: -f 2)
else
# other drupal versions
LAST_CRON_RUN=$(HOME=${DRUSH_HOME} ${DRUSH} --root=${root} --uri=${uri} state-get system.cron_last)
fi
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