Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_uptime3

Rating
8 votes
Favoured:
3
Current Version
1.06
Last Release Date
2011-01-27
Hits
102197
Files:
FileDescription
check_uptime3check_uptime3
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
* Original script written by Dmitry Vayntrub with version 1.04 released on 03/11/2009.

* Bugfix added.

* Performance Data added.
####

Performance Data added by Tony Yarusso on Jan 27, 2011. (revision incremented to 1.06)

####

There was bug report posted by reviewer jsnyder on the script's page: http://exchange.nagios.org/directory/Plugins/System-Metrics/Uptime/check_uptime2/details

My fix simply adds another "if" conditional checking for existence of keyword "min" which means there will not be an hour count listed in the output of "uptime".

I also incremented the revision number to 1.05.

Sample output:
OK - uptime is 57 Minutes
OK - uptime is 1 Hours, 27 Minutes
OK - uptime is 1 Days, 27 Minutes
OK - uptime is 1 Days, 1 Hours, 57 Minutes
Reviews (5)
Thank you for this !!

I have been hunting and testing for MONTHS to find a check_uptime script that works correctly. This is the only one that does with the different results (depending on time up) from 'uptime'. i.e Minutes, Hours & Minutes, Days & Minutes, Day & Hours & Minutes.

I have made a few adjustments to mine as I have no need for warnings, just for monitoring:

==========
#!/bin/sh

UPTIME_REPORT=`uptime | tr -d ","`

if echo $UPTIME_REPORT | grep -i day > /dev/null ; then

if echo $UPTIME_REPORT | grep -i "min" > /dev/null ; then

DAYS=`echo $UPTIME_REPORT | awk '{ print $3 }'`
MINUTES=`echo $UPTIME_REPORT | awk '{ print $5}'`

else
DAYS=`echo $UPTIME_REPORT | awk '{ print $3 }'`
HOURS=`echo $UPTIME_REPORT | awk '{ print $5}' | cut -f1 -d":"`
MINUTES=`echo $UPTIME_REPORT | awk '{ print $5}' | cut -f2 -d":"`
fi

elif #in AIX 5:00 will show up as 5 hours, and in Solaris 2.6 as 5 hr(s)
echo $UPTIME_REPORT | egrep -e "hour|hr\(s\)" > /dev/null ; then
HOURS=`echo $UPTIME_REPORT | awk '{ print $3}'`
else
echo $UPTIME_REPORT | awk '{ print $3}' | grep ":" > /dev/null && \
HOURS=`echo $UPTIME_REPORT | awk '{ print $3}' | cut -f1 -d":"`
MINUTES=`echo $UPTIME_REPORT | awk '{ print $3}' | cut -f2 -d":"`
fi

UPTIME_MSG="${DAYS:+$DAYS Days,} ${HOURS:+$HOURS Hours,} $MINUTES Minutes"

echo System Uptime - $UPTIME_MSG
==========

I now have this running on CentOS, Ubuntu and Raspberry Pi servers, all running perfectly!

System Uptime - 0 Minutes
System Uptime - 4 Hours, 19 Minutes
System Uptime - 2 Days, 8 Hours, 54 Minutes
Hello,
This is a patch to use with Debian and optiomal min/max options

2a3
> # Edit by Belgotux www.monlinux.net 30/07/2014
7a9
> # v 1.07 - Debian version and optiomal min/max options
107c109
UPTIME_DAYS=$(printf %3.4f $RAW_DAYS)
109c111,119

> PERFDATA="|Uptime=$UPTIME_DAYS;"
> if [ "$MIN_WARNING" != "" ] || [ "$MAX_WARNING" != "" ] ; then PERFDATA="${PERFDATA}${MIN_WARNING}:${MAX_WARNING};" ; fi
> if [ "$MIN_CRITICAL" != "" ] || [ "$MAX_CRITICAL" != "" ] ; then PERFDATA="${PERFDATA}${MIN_CRITICAL}:${MAX_CRITICAL};" ; fi
>
> PERFDATA="${PERFDATA}0;"
>
> #|Uptime=$UPTIME_DAYS;$MIN_WARNING:$MAX_WARNING;$MIN_CRITICAL:$MAX_CRITICAL;0;
>
byelpatron, October 14, 2013
Works like a charm on my Raspberry Pi.
byschams.net, October 4, 2011
2 of 2 people found this review helpful
@cnoyes72: you can simply change the shell to: "/bin/bash", so the script works fine under Debian as well. Do this by editing the first line and replace "#!/bin/sh" with "#!/bin/bash".

Hope this helps. Cheers.
bycnoyes72, September 26, 2011
Executing this script on a debian system results in the following being reported (along with the results):


printf: 107: %3.4l: invalid directive
OK - uptime is 10 Days, 19 Hours, 25 Minutes|Uptime=;:;:;0;