Run through shellcheck.net. Converted all printf to echo since it's easier, may convert back later if given good reason.

This commit is contained in:
Ryan Loudfoot 2013-11-02 13:18:46 -04:00
parent 32252b61ea
commit 75b4a1c6d6

View File

@ -33,7 +33,7 @@
# # # #
############################################################################### ###############################################################################
VERSION="Version 0.91" VERSION="Version 0.92"
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)" AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
# Sensor program # Sensor program
@ -59,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:
@ -100,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 in $SENSORPROG"
exit $STATE_UNKNOWN exit $STATE_UNKNOWN
fi fi
@ -126,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
@ -134,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
@ -145,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
@ -153,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
@ -168,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
@ -177,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
;; ;;
@ -188,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
@ -203,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
@ -223,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
@ -235,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
@ -253,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