Compare commits
No commits in common. "master" and "v0.94" have entirely different histories.
21
HISTORY
21
HISTORY
@ -23,24 +23,3 @@ Version 0.94:
|
|||||||
In 0.94 I removed /etc from the whereis path as it didn't work for me
|
In 0.94 I removed /etc from the whereis path as it didn't work for me
|
||||||
on my setup. It found the config-file for lm-sensors and tried to run
|
on my setup. It found the config-file for lm-sensors and tried to run
|
||||||
it.
|
it.
|
||||||
|
|
||||||
Version 0.95:
|
|
||||||
Changed the Performance Data Field to only contain a label and the
|
|
||||||
actual value in celsius. For example, "temperature=39".
|
|
||||||
|
|
||||||
Version 1.0:
|
|
||||||
Several improvements made by Nikodimos, including:
|
|
||||||
- Added support for multiple sensors
|
|
||||||
- Enriched performance data output. For example, "CPU=34;40;55 MB=32;40;55"
|
|
||||||
- Changed (and improved) the way temperatures are retrieved
|
|
||||||
- Other fixes and touch-ups, such as the help text now shows long options
|
|
||||||
|
|
||||||
Version 1.1:
|
|
||||||
Improvements for Icinga 2, made by Onkobu
|
|
||||||
- order of arguments is irrelevant now, --sensor first ignored following -c & -w
|
|
||||||
- current sensors' multiline output needs sophisticated treatment
|
|
||||||
|
|
||||||
Version 1.2:
|
|
||||||
Improvements for Icinga 2, made by Onkobu
|
|
||||||
- Added the ability to switch between old and new style with an -n option
|
|
||||||
- Fixed multi-sensor with identical thresholds
|
|
||||||
|
7
THANKS
7
THANKS
@ -5,8 +5,5 @@ Some kind people have been contributing by reporting problems, suggesting
|
|||||||
improvements or submitting code.
|
improvements or submitting code.
|
||||||
Here is a list of these kind people.
|
Here is a list of these kind people.
|
||||||
|
|
||||||
Chad Columbus ccolumbu@hotmail.com
|
Chad Columbus ccolumbu@hotmail.com
|
||||||
Ryan Loudfoot elyrith@gmail.com
|
Ryan Loudfoot elyrith@gmail.com
|
||||||
Nikodimos kikniknik on Github
|
|
||||||
Shakalandy shakalandy on Github
|
|
||||||
Onkobu Tanaake onkobu on Github
|
|
||||||
|
209
check_temp.sh
209
check_temp.sh
@ -33,8 +33,8 @@
|
|||||||
# #
|
# #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
VERSION="Version 1.2"
|
VERSION="Version 0.94"
|
||||||
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se), (c) 2020 Onkobu Tanaake (oss@onkobutanaake.de)"
|
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
||||||
|
|
||||||
# Sensor program
|
# Sensor program
|
||||||
SENSORPROG=$(whereis -b -B /{bin,sbin,usr} /{bin,sbin,usr}/* -f sensors | awk '{print $2}')
|
SENSORPROG=$(whereis -b -B /{bin,sbin,usr} /{bin,sbin,usr}/* -f sensors | awk '{print $2}')
|
||||||
@ -71,30 +71,20 @@ print_help()
|
|||||||
/bin/cat <<EOT
|
/bin/cat <<EOT
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h, --help
|
-h
|
||||||
Print detailed help screen
|
Print detailed help screen
|
||||||
-V, --version
|
-V
|
||||||
Print version information
|
Print version information
|
||||||
-v, --verbose
|
-v
|
||||||
Verbose output
|
Verbose output
|
||||||
|
|
||||||
-s, --sensor <WORD[,DISPLAY_NAME]>
|
--sensor WORD
|
||||||
Set what to monitor, for example CPU or MB (or M/B). Check sensors for the
|
Set what to monitor, for example CPU or MB (or M/B). Check sensors for the
|
||||||
correct word. Default is CPU. A different display name can be used in output,
|
correct word. Default is CPU.
|
||||||
by adding it next to sensor with a comma.
|
-w INTEGER
|
||||||
It can be used more than once, with different warning/critical thresholds optionally.
|
|
||||||
-w, --warning <INTEGER>
|
|
||||||
Exit with WARNING status if above INTEGER degrees
|
Exit with WARNING status if above INTEGER degrees
|
||||||
-c, --critical <INTEGER>
|
-c INTEGER
|
||||||
Exit with CRITICAL status if above INTEGER degrees
|
Exit with CRITICAL status if above INTEGER degrees
|
||||||
Warning and critical thresholds must be provided before the corresponding --sensor option.
|
|
||||||
-n
|
|
||||||
Use the new sed based filter in case classic filter yields no temperature.
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
./check_temp.sh [-n] -w 65 -c 75 --sensor CPU
|
|
||||||
./check_temp.sh [-n] -w 65 -c 75 --sensor CPU --sensor temp1
|
|
||||||
./check_temp.sh [-n] -w 65 -c 75 --sensor CPU -w 75 -c 85 --sensor temp1,GPU
|
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,10 +96,7 @@ thresh_warn=
|
|||||||
# Critical threshold
|
# Critical threshold
|
||||||
thresh_crit=
|
thresh_crit=
|
||||||
# Hardware to monitor
|
# Hardware to monitor
|
||||||
default_sensor="CPU"
|
sensor=CPU
|
||||||
sensor_declared=false
|
|
||||||
|
|
||||||
STATE=$STATE_OK
|
|
||||||
|
|
||||||
# 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
|
||||||
@ -117,81 +104,6 @@ if [[ ! -x "$SENSORPROG" ]]; then
|
|||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function set_state {
|
|
||||||
[[ "$STATE" -lt "$1" ]] && STATE=$1
|
|
||||||
}
|
|
||||||
|
|
||||||
function process_sensor {
|
|
||||||
sensor=$(echo $1 | cut -d, -f1)
|
|
||||||
sensor_display=$(echo $1 | cut -d, -f2)
|
|
||||||
# Check if a sensor were specified
|
|
||||||
if [[ -z "$sensor" ]]; then
|
|
||||||
# No sensor to monitor were specified
|
|
||||||
echo "No sensor specified"
|
|
||||||
print_help
|
|
||||||
exit $STATE_UNKNOWN
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the thresholds have been set correctly
|
|
||||||
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
|
|
||||||
# One or both thresholds were not specified
|
|
||||||
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
|
|
||||||
echo "Warning temperature should be lower than critical"
|
|
||||||
print_help
|
|
||||||
exit $STATE_UNKNOWN
|
|
||||||
fi
|
|
||||||
# Get the temperature
|
|
||||||
# Grep the first float with a plus sign and keep only the integer
|
|
||||||
if [ $CLASSIC_FILTER -eq 1 ]; then
|
|
||||||
WHOLE_TEMP=$(${SENSORPROG} | grep "$sensor" | head -n1 | grep -o "+[0-9]\+\(\.[0-9]\+\)\?[^ \t,()]*" | head -n1)
|
|
||||||
else
|
|
||||||
WHOLE_TEMP=$(${SENSORPROG} -A "$sensor" | sed -n '2 p' | grep -o "+[0-9]\+\(\.[0-9]\+\)\?[^ \t,()]*" | head -n1)
|
|
||||||
fi
|
|
||||||
TEMPF=$(echo "$WHOLE_TEMP" | grep -o "[0-9]\+\(\.[0-9]\+\)\?")
|
|
||||||
TEMP=$(echo "$TEMPF" | cut -d. -f1)
|
|
||||||
|
|
||||||
# Verbose output
|
|
||||||
if [[ "$verbosity" -ge 1 ]]; then
|
|
||||||
/bin/cat <<__EOT
|
|
||||||
Debugging information:
|
|
||||||
Warning threshold: $thresh_warn
|
|
||||||
Critical threshold: $thresh_crit
|
|
||||||
Verbosity level: $verbosity
|
|
||||||
Current $sensor temperature: $TEMP
|
|
||||||
__EOT
|
|
||||||
echo "Temperature lines directly from sensors:"
|
|
||||||
${SENSORPROG}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get performance data for Nagios "Performance Data" field
|
|
||||||
PERFDATA="$PERFDATA $sensor_display=$TEMP;$thresh_warn;$thresh_crit"
|
|
||||||
|
|
||||||
# And finally check the temperature against our thresholds
|
|
||||||
if [[ "$TEMP" != +([0-9]) ]]; then
|
|
||||||
# Temperature not found for that sensor
|
|
||||||
OUTPUT_TEXT="$OUTPUT_TEXT, No data found for sensor ($sensor)"
|
|
||||||
set_state $STATE_UNKNOWN
|
|
||||||
elif [[ "$TEMP" -gt "$thresh_crit" ]]; then
|
|
||||||
# Temperature is above critical threshold
|
|
||||||
OUTPUT_TEXT="$OUTPUT_TEXT, $sensor_display has temperature: $WHOLE_TEMP"
|
|
||||||
set_state $STATE_CRITICAL
|
|
||||||
elif [[ "$TEMP" -gt "$thresh_warn" ]]; then
|
|
||||||
# Temperature is above warning threshold
|
|
||||||
OUTPUT_TEXT="$OUTPUT_TEXT, $sensor_display has temperature: $WHOLE_TEMP"
|
|
||||||
set_state $STATE_WARNING
|
|
||||||
else
|
|
||||||
# Temperature is ok
|
|
||||||
OUTPUT_TEXT="$OUTPUT_TEXT, $sensor_display has temperature: $WHOLE_TEMP"
|
|
||||||
set_state $STATE_OK
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
CLASSIC_FILTER=1
|
|
||||||
|
|
||||||
# Parse command line options
|
# Parse command line options
|
||||||
while [[ -n "$1" ]]; do
|
while [[ -n "$1" ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -249,47 +161,96 @@ while [[ -n "$1" ]]; do
|
|||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-s | --sensor)
|
-\?)
|
||||||
|
print_help
|
||||||
|
exit $STATE_OK
|
||||||
|
;;
|
||||||
|
|
||||||
|
--sensor)
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
echo "Option $1 requires an argument"
|
echo "Option $1 requires an argument"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
fi
|
fi
|
||||||
sensor_declared=true
|
sensor=$2
|
||||||
sensors_to_check="$2"
|
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-n | --new-filter)
|
|
||||||
CLASSIC_FILTER=0
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
echo "Invalid option '$1'"
|
echo "Invalid option '$1'"
|
||||||
print_help
|
print_help
|
||||||
exit $STATE_UNKNOWN
|
exit $STATE_UNKNOWN
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# argument order is irrelevant, Icinga2 gives no guarantees
|
|
||||||
# as soon as there are enough output is generated
|
|
||||||
if [ ! -z "$thresh_warn" ] && [ ! -z "$thresh_crit" ] && [ ! -z "$sensors_to_check" -o $# -eq 0 ]; then
|
|
||||||
if [ "$sensor_declared" = false ]; then
|
|
||||||
process_sensor "$default_sensor"
|
|
||||||
else
|
|
||||||
process_sensor "$sensors_to_check"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
case "$STATE" in
|
# Check if a sensor were specified
|
||||||
"$STATE_OK") STATE_TEXT="OK" ;;
|
if [[ -z "$sensor" ]]; then
|
||||||
"$STATE_WARNING") STATE_TEXT="WARNING" ;;
|
# No sensor to monitor were specified
|
||||||
"$STATE_CRITICAL") STATE_TEXT="CRITICAL" ;;
|
echo "No sensor specified"
|
||||||
"$STATE_UNKNOWN") STATE_TEXT="UNKNOWN" ;;
|
print_help
|
||||||
esac
|
exit $STATE_UNKNOWN
|
||||||
|
fi
|
||||||
|
|
||||||
OUTPUT_TEXT=$(echo $OUTPUT_TEXT | sed -e 's/, //')
|
|
||||||
echo "TEMPERATURE $STATE_TEXT - $OUTPUT_TEXT |$PERFDATA"
|
#Get the temperature
|
||||||
exit $STATE
|
TEMP=`${SENSORPROG} | grep "$sensor" | cut -d+ -f2 | cut -c1-2 | head -n1`
|
||||||
|
#Old way - Get the temperature
|
||||||
|
#TEMP=`${SENSORPROG} | grep "$sensor" | awk '{print $3}' | cut -c2-3 | 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
|
||||||
|
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
|
||||||
|
echo "Warning temperature should be lower than critical"
|
||||||
|
print_help
|
||||||
|
exit $STATE_UNKNOWN
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Verbose output
|
||||||
|
if [[ "$verbosity" -ge 1 ]]; then
|
||||||
|
/bin/cat <<__EOT
|
||||||
|
Debugging information:
|
||||||
|
Warning threshold: $thresh_warn
|
||||||
|
Critical threshold: $thresh_crit
|
||||||
|
Verbosity level: $verbosity
|
||||||
|
Current $sensor temperature: $TEMP
|
||||||
|
__EOT
|
||||||
|
echo "Temperature lines directly from sensors:"
|
||||||
|
${SENSORPROG}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get performance data for Nagios "Performance Data" field
|
||||||
|
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
|
||||||
|
echo "No data found for that sensor ($sensor) | $PERFDATA"
|
||||||
|
exit $STATE_UNKNOWN
|
||||||
|
|
||||||
|
elif [[ "$TEMP" -gt "$thresh_crit" ]]; then
|
||||||
|
# Temperature is above critical threshold
|
||||||
|
echo "$sensor CRITICAL - Temperature is $TEMP | $PERFDATA"
|
||||||
|
exit $STATE_CRITICAL
|
||||||
|
|
||||||
|
elif [[ "$TEMP" -gt "$thresh_warn" ]]; then
|
||||||
|
# Temperature is above warning threshold
|
||||||
|
echo "$sensor WARNING - Temperature is $TEMP | $PERFDATA"
|
||||||
|
exit $STATE_WARNING
|
||||||
|
|
||||||
|
else
|
||||||
|
# Temperature is ok
|
||||||
|
echo "$sensor OK - Temperature is $TEMP | $PERFDATA"
|
||||||
|
exit $STATE_OK
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $STATE_UNKNOWN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user