From ed39f4a6d2818431efc3b8a714c8500c520c204a Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Fri, 2 Apr 2010 16:54:50 +0100 Subject: [PATCH] add uptime check Signed-off-by: Stephen Gran --- dsa-nagios-checks/checks/dsa-check-uptime | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 dsa-nagios-checks/checks/dsa-check-uptime diff --git a/dsa-nagios-checks/checks/dsa-check-uptime b/dsa-nagios-checks/checks/dsa-check-uptime new file mode 100755 index 0000000..233569b --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-uptime @@ -0,0 +1,56 @@ +#!/bin/sh + +# Need to cover this also: +# 4:13pm up 29 day(s), 3 min(s), 3 users, load average: 1.59, 2.54, 2.58 +# +uptimeOutput=`/usr/bin/uptime`; +PATH="/bin:/usr/bin:/usr/local/bin"; +export PATH; + +days=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *day[\(s\)]*.*$/\1/'`; +if [ x"`echo $days | /bin/grep -w up`" != x ] +then + days=0; +fi +hours_mins=`echo $uptimeOutput | /bin/sed 's/^.* up [^0-9]*\([0-9][0-9]*:[0-9][0-9]*\).*/\1/'`; +if [ x"`echo $hours_mins | /bin/grep up`" = x ] +then + hours=`echo $hours_mins | cut -f1 -d:`; + minutes=`echo $hours_mins | cut -f2 -d:`; +else + hours=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *hr[\(s\)]*.*$/\1/'`; + if [ x"`echo $hours | grep up`" != x ] + then + hours="0"; + fi + minutes=`echo $uptimeOutput | /bin/sed 's/^.* up.* \([0-9][0-9]*\) *min[\(s\)]*.*$/\1/'`; + if [ x"`echo $minutes | grep up`" != x ] + then + minutes="0"; + fi +fi + +if [ x"`echo \"$days $hours $minutes\" | /bin/grep up`" != x ] +then + echo "Uptime UNKNOWN: Unable to parse uptime output: \"$uptimeOutput\""; + exit 3; +fi + +# 1440 minutes in a day +dayMinutes=`expr $days \* 1440`; +hourMinutes=`expr $hours \* 60`; + +totalMinutes=`expr $dayMinutes \+ $hourMinutes`; +totalMinutes=`expr $totalMinutes \+ $minutes`; + +# Has it been rebooted in the last hour? +if [ "$totalMinutes" -lt 60 ] +then + # exit with a warning + echo "Uptime WARNING: Uptime less than one hour (currently $totalMinutes minutes)|mins=$totalMinutes"; + exit 1; +else + # everything's okay! + echo "Uptime OK: Currently $days days, $hours hours and $minutes minutes|mins=$totalMinutes"; + exit 0; +fi -- 2.20.1