commit
fcb2be369d
@ -33,17 +33,24 @@
|
|||||||
# #
|
# #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
VERSION="Version 0.8"
|
VERSION="Version 0.93"
|
||||||
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
||||||
|
|
||||||
# Sensor program
|
# 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
|
# Ryan's note: utils.sh is installed with nagios-plugins in with the plugins
|
||||||
STATE_OK=0
|
# Check if utils.sh exists. This lets you use check_domain in a testing environment
|
||||||
STATE_WARNING=1
|
# or outside of Nagios.
|
||||||
STATE_CRITICAL=2
|
if [ -e "$PROGPATH/utils.sh" ]; then
|
||||||
STATE_UNKNOWN=3
|
. "$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
|
shopt -s extglob
|
||||||
|
|
||||||
@ -52,15 +59,15 @@ shopt -s extglob
|
|||||||
# Print version information
|
# Print version information
|
||||||
print_version()
|
print_version()
|
||||||
{
|
{
|
||||||
printf "\n\n$0 - $VERSION\n"
|
echo "$0 - $VERSION"
|
||||||
}
|
}
|
||||||
|
|
||||||
#Print help information
|
#Print help information
|
||||||
print_help()
|
print_help()
|
||||||
{
|
{
|
||||||
print_version
|
print_version
|
||||||
printf "$AUTHOR\n"
|
echo "$AUTHOR"
|
||||||
printf "Monitor temperature with the use of sensors\n"
|
echo "Monitor temperature with the use of sensors"
|
||||||
/bin/cat <<EOT
|
/bin/cat <<EOT
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
@ -93,7 +100,7 @@ sensor=CPU
|
|||||||
|
|
||||||
# See if we have sensors program installed and can execute it
|
# See if we have sensors program installed and can execute it
|
||||||
if [[ ! -x "$SENSORPROG" ]]; then
|
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
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -119,7 +126,7 @@ while [[ -n "$1" ]]; do
|
|||||||
-w | --warning)
|
-w | --warning)
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
# Threshold not provided
|
# Threshold not provided
|
||||||
printf "\nOption $1 requires an argument"
|
echo "Option $1 requires an argument"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
elif [[ "$2" = +([0-9]) ]]; then
|
elif [[ "$2" = +([0-9]) ]]; then
|
||||||
@ -127,7 +134,7 @@ while [[ -n "$1" ]]; do
|
|||||||
thresh=$2
|
thresh=$2
|
||||||
else
|
else
|
||||||
# Threshold is not an integer
|
# Threshold is not an integer
|
||||||
printf "\nThreshold must be an integer"
|
echo "Threshold must be an integer"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
@ -138,7 +145,7 @@ while [[ -n "$1" ]]; do
|
|||||||
-c | --critical)
|
-c | --critical)
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
# Threshold not provided
|
# Threshold not provided
|
||||||
printf "\nOption '$1' requires an argument"
|
echo "Option '$1' requires an argument"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
elif [[ "$2" = +([0-9]) ]]; then
|
elif [[ "$2" = +([0-9]) ]]; then
|
||||||
@ -146,7 +153,7 @@ while [[ -n "$1" ]]; do
|
|||||||
thresh=$2
|
thresh=$2
|
||||||
else
|
else
|
||||||
# Threshold is not an integer
|
# Threshold is not an integer
|
||||||
printf "\nThreshold must be an integer"
|
echo "Threshold must be an integer"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
@ -161,7 +168,7 @@ while [[ -n "$1" ]]; do
|
|||||||
|
|
||||||
--sensor)
|
--sensor)
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
printf "\nOption $1 requires an argument"
|
echo "Option $1 requires an argument"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
@ -170,7 +177,7 @@ while [[ -n "$1" ]]; do
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
printf "\nInvalid option '$1'"
|
echo "Invalid option '$1'"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
;;
|
;;
|
||||||
@ -181,7 +188,7 @@ done
|
|||||||
# Check if a sensor were specified
|
# Check if a sensor were specified
|
||||||
if [[ -z "$sensor" ]]; then
|
if [[ -z "$sensor" ]]; then
|
||||||
# No sensor to monitor were specified
|
# No sensor to monitor were specified
|
||||||
printf "\nNo sensor specified"
|
echo "No sensor specified"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
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
|
# Check if the thresholds have been set correctly
|
||||||
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
|
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
|
||||||
# One or both thresholds were not specified
|
# One or both thresholds were not specified
|
||||||
printf "\nThreshold not set"
|
echo "Threshold not set"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
elif [[ "$thresh_crit" -lt "$thresh_warn" ]]; then
|
elif [[ "$thresh_crit" -lt "$thresh_warn" ]]; then
|
||||||
# The warning threshold must be lower than the critical threshold
|
# 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
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
@ -216,9 +223,8 @@ Debugging information:
|
|||||||
Verbosity level: $verbosity
|
Verbosity level: $verbosity
|
||||||
Current $sensor temperature: $TEMP
|
Current $sensor temperature: $TEMP
|
||||||
__EOT
|
__EOT
|
||||||
printf "\n Temperature lines directly from sensors:\n"
|
echo "Temperature lines directly from sensors:"
|
||||||
${SENSORPROG}
|
${SENSORPROG}
|
||||||
printf "\n\n"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get performance data for Nagios "Performance Data" field
|
# 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
|
# And finally check the temperature against our thresholds
|
||||||
if [[ "$TEMP" != +([0-9]) ]]; then
|
if [[ "$TEMP" != +([0-9]) ]]; then
|
||||||
# Temperature not found for that sensor
|
# 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
|
exit $STATE_UNKNOWN
|
||||||
|
|
||||||
elif [[ "$TEMP" -gt "$thresh_crit" ]]; then
|
elif [[ "$TEMP" -gt "$thresh_crit" ]]; then
|
||||||
@ -246,4 +252,5 @@ if [[ "$TEMP" != +([0-9]) ]]; then
|
|||||||
echo "$sensor OK - Temperature is $TEMP | $PERFDATA"
|
echo "$sensor OK - Temperature is $TEMP | $PERFDATA"
|
||||||
exit $STATE_OK
|
exit $STATE_OK
|
||||||
fi
|
fi
|
||||||
exit 3
|
|
||||||
|
exit $STATE_UNKNOWN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user