-
Notifications
You must be signed in to change notification settings - Fork 2
/
check-uptime.sh
executable file
·57 lines (51 loc) · 1.42 KB
/
check-uptime.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
#!/bin/bash
#
# Check uptime. Nagios alert on conditions we don't like.
#
# Critdays & warndays are configurable. if $1 and $2, then use those values. Otherwise, use defaults
# $1 CRITDAYS
# $2 WARNDAYS
# needed variables
HOST_NAME=`hostname`
PROGNAME=`basename $0`
PROGPATH=`dirname $0`
# defaults
if [ -n "$1" ]; then
CRITDAYS=$1
else
CRITDAYS=900
fi
if [ -n "$2" ]; then
WARNDAYS=$2
else
WARNDAYS=800
fi
# Hours
WARNHOURS=24
CRITHOURS=0
# pull in exit states
. $PROGPATH/utils.sh
# calculate time
UPTIME=`gawk -F . '{ print $1 }' /proc/uptime`
MINS=$(($UPTIME/60))
HOURS=$(($MINS/60))
DAYS=$(($HOURS/24))
if [ "$HOURS" -lt "${CRITHOURS}" ]; then
echo "CRITICAL - ${hostname} has only been up ${HOURS} hours"
exit $STATE_CRITICAL
elif [ "$HOURS" -lt "${WARNHOURS}" ]; then
echo "WARNING - ${hostname} has only been up ${HOURS} hours."
exit $STATE_WARNING
elif [ "$DAYS" -gt "${CRITDAYS}" ]; then
echo "CRTIICAL - ${hostname} has gone ${DAYS} since reboot"
exit $STATE_CRITICAL
elif [ "$DAYS" -gt "${WARNDAYS}" ]; then
echo "WARNING - ${hostname} has gone ${DAYS} since reboot"
exit $STATE_WARNING
elif [ "${CRITDAYS}" -lt "${WARNDAYS}" ]; then
echo "UNKNOWN - You've got CRITDAYS - $1 - setup to be less than WARNDAYS - $2"
exit $STATE_UNKNOWN
else
echo "OK - ${DAYS} days or ${HOURS} hours uptime"
exit $STATE_OK
fi