Merge pull request #3 from Elyrith/master

A lot of changes
This commit is contained in:
Jack-Benny Persson 2014-09-20 10:10:36 +02:00
commit fcb2be369d

View File

@ -33,17 +33,24 @@
# #
###############################################################################
VERSION="Version 0.8"
VERSION="Version 0.93"
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
# Sensor program
SENSORPROG=/usr/bin/sensors
SENSORPROG=$(whereis -b -B /{bin,sbin,usr,etc} /{bin,sbin,usr,etc}/* -f sensors | awk '{print $2}')
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# Ryan's note: utils.sh is installed with nagios-plugins in with the plugins
# Check if utils.sh exists. This lets you use check_domain in a testing environment
# or outside of Nagios.
if [ -e "$PROGPATH/utils.sh" ]; then
. "$PROGPATH/utils.sh"
else
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# STATE_DEPENDENT=4 (Commented because it's unused.)
fi
shopt -s extglob
@ -52,15 +59,15 @@ shopt -s extglob
# Print version information
print_version()
{
printf "\n\n$0 - $VERSION\n"
echo "$0 - $VERSION"
}
#Print help information
print_help()
{
print_version
printf "$AUTHOR\n"
printf "Monitor temperature with the use of sensors\n"
echo "$AUTHOR"
echo "Monitor temperature with the use of sensors"
/bin/cat <<EOT
Options:
@ -93,7 +100,7 @@ sensor=CPU
# See if we have sensors program installed and can execute it
if [[ ! -x "$SENSORPROG" ]]; then
printf "\nIt appears you don't have lm-sensors installed in $SENSORPROG\n"
echo "It appears you don't have lm-sensors installed. You may find help in the readme for this script."
exit $STATE_UNKNOWN
fi
@ -119,7 +126,7 @@ while [[ -n "$1" ]]; do
-w | --warning)
if [[ -z "$2" ]]; then
# Threshold not provided
printf "\nOption $1 requires an argument"
echo "Option $1 requires an argument"
print_help
exit $STATE_UNKNOWN
elif [[ "$2" = +([0-9]) ]]; then
@ -127,7 +134,7 @@ while [[ -n "$1" ]]; do
thresh=$2
else
# Threshold is not an integer
printf "\nThreshold must be an integer"
echo "Threshold must be an integer"
print_help
exit $STATE_UNKNOWN
fi
@ -138,7 +145,7 @@ while [[ -n "$1" ]]; do
-c | --critical)
if [[ -z "$2" ]]; then
# Threshold not provided
printf "\nOption '$1' requires an argument"
echo "Option '$1' requires an argument"
print_help
exit $STATE_UNKNOWN
elif [[ "$2" = +([0-9]) ]]; then
@ -146,7 +153,7 @@ while [[ -n "$1" ]]; do
thresh=$2
else
# Threshold is not an integer
printf "\nThreshold must be an integer"
echo "Threshold must be an integer"
print_help
exit $STATE_UNKNOWN
fi
@ -161,7 +168,7 @@ while [[ -n "$1" ]]; do
--sensor)
if [[ -z "$2" ]]; then
printf "\nOption $1 requires an argument"
echo "Option $1 requires an argument"
print_help
exit $STATE_UNKNOWN
fi
@ -170,7 +177,7 @@ while [[ -n "$1" ]]; do
;;
*)
printf "\nInvalid option '$1'"
echo "Invalid option '$1'"
print_help
exit $STATE_UNKNOWN
;;
@ -181,7 +188,7 @@ done
# Check if a sensor were specified
if [[ -z "$sensor" ]]; then
# No sensor to monitor were specified
printf "\nNo sensor specified"
echo "No sensor specified"
print_help
exit $STATE_UNKNOWN
fi
@ -196,12 +203,12 @@ TEMP=`${SENSORPROG} | grep "$sensor" | cut -d+ -f2 | cut -c1-2 | head -n1`
# Check if the thresholds have been set correctly
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
# One or both thresholds were not specified
printf "\nThreshold not set"
echo "Threshold not set"
print_help
exit $STATE_UNKNOWN
elif [[ "$thresh_crit" -lt "$thresh_warn" ]]; then
# The warning threshold must be lower than the critical threshold
printf "\nWarning temperature should be lower than critical"
echo "Warning temperature should be lower than critical"
print_help
exit $STATE_UNKNOWN
fi
@ -216,9 +223,8 @@ Debugging information:
Verbosity level: $verbosity
Current $sensor temperature: $TEMP
__EOT
printf "\n Temperature lines directly from sensors:\n"
echo "Temperature lines directly from sensors:"
${SENSORPROG}
printf "\n\n"
fi
# Get performance data for Nagios "Performance Data" field
@ -228,7 +234,7 @@ PERFDATA=`${SENSORPROG} | grep "$sensor" | head -n1`
# And finally check the temperature against our thresholds
if [[ "$TEMP" != +([0-9]) ]]; then
# Temperature not found for that sensor
printf "No data found for that sensor ($sensor)\n"
echo "No data found for that sensor ($sensor) | $PERFDATA"
exit $STATE_UNKNOWN
elif [[ "$TEMP" -gt "$thresh_crit" ]]; then
@ -246,4 +252,5 @@ if [[ "$TEMP" != +([0-9]) ]]; then
echo "$sensor OK - Temperature is $TEMP | $PERFDATA"
exit $STATE_OK
fi
exit 3
exit $STATE_UNKNOWN