retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-uptime
1 #!/bin/sh
2
3 # Need to cover this also:
4 #  4:13pm  up 29 day(s), 3 min(s),  3 users,  load average: 1.59, 2.54, 2.58
5 #
6 uptimeOutput=`/usr/bin/uptime`;
7 PATH="/bin:/usr/bin:/usr/local/bin";
8 export PATH;
9
10 days=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *day[\(s\)]*.*$/\1/'`;
11 if [ x"`echo $days | /bin/grep -w up`" != x ]
12 then
13         days=0;
14 fi
15 hours_mins=`echo $uptimeOutput | /bin/sed 's/^.* up [^0-9]*\([0-9][0-9]*:[0-9][0-9]*\).*/\1/'`;
16 if [ x"`echo $hours_mins | /bin/grep up`" = x ]
17 then
18         hours=`echo $hours_mins | cut -f1 -d:`;
19         minutes=`echo $hours_mins | cut -f2 -d:`;
20 else
21         hours=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *hr[\(s\)]*.*$/\1/'`;
22         if [ x"`echo $hours | grep up`" != x ]
23         then
24                 hours="0";
25         fi
26         minutes=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *min[\(s\)]*.*$/\1/'`;
27         if [ x"`echo $minutes | grep up`" != x ]
28         then
29                 minutes="0";
30         fi
31 fi
32
33 if [ x"`echo \"$days $hours $minutes\" | /bin/grep up`" != x ]
34 then
35         echo "Uptime UNKNOWN: Unable to parse uptime output: \"$uptimeOutput\"";
36         exit 3;
37 fi
38
39 # 1440 minutes in a day
40 dayMinutes=`expr $days \* 1440`;
41 hourMinutes=`expr $hours \* 60`;
42
43 totalMinutes=`expr $dayMinutes \+ $hourMinutes`;
44 totalMinutes=`expr $totalMinutes \+ $minutes`;
45
46 # Has it been rebooted in the last hour?
47 if [ "$totalMinutes" -lt 60 ]
48 then
49         # exit with a warning
50         echo "Uptime WARNING: Uptime less than one hour (currently $totalMinutes minutes)|mins=$totalMinutes";
51         exit 1;
52 else
53         # everything's okay!
54         echo "Uptime OK: Currently $days days, $hours hours and $minutes minutes|mins=$totalMinutes";
55         exit 0;
56 fi