Skip to content

Instantly share code, notes, and snippets.

@swelljoe
Last active May 3, 2016 23:31
Show Gist options
  • Save swelljoe/fbca735b43450a91937f239222e5e3c8 to your computer and use it in GitHub Desktop.
Save swelljoe/fbca735b43450a91937f239222e5e3c8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Nagios Plugin check_uptime
# This plugin returns CRITICAL if uptime is less than CRITICAL_THRESHOLD minutes
#
# Check for missing parameters
if [[ -z "$1" ]]; then
echo "Missing parameters! Syntax: ./nagios-uptime.sh CRITICAL_THRESHOLD"
exit 3
fi
# Get the current uptime in seconds and divide by 60 to get minutes
uptime=`cat /proc/uptime | awk '{print $1}'` # Easier to parse than uptime command
upsecs=`printf "%.0f\n" "$uptime"` # Division in bash is silly, so drop the decimal
upmins=$((upsecs / 60))
# Check if uptime in minutes is greater than CRITICAL threshold parameter
if [[ "$upmins" -gt "$1" ]]; then
echo "OK - Uptime is $upmins minutes"
exit 0
fi
# Current uptime in minutes is less than CRITICAL threshold parameter
echo "CRITICAL - Uptime is $upmins minutes"
exit 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment