Compare commits

...

8 Commits
v1.0 ... master

Author SHA1 Message Date
2a500f3339 Bumped the version to 1.2 after Onkobu's updates 2021-01-11 01:30:47 +01:00
56edc7a786 Updated the list of very kind people 2021-01-11 01:13:26 +01:00
3c0407dc11
Merge pull request #7 from onkobu/master
Argument order irrelevant/ sensor parsing improved/ fixed multi-sensor and added new-style/old-style parsing
2021-01-11 01:08:36 +01:00
onkobu
1853626e49 Fix multi-sensor with identical thresholds
- keep thresholds once found, wait for regular re-definition
2021-01-07 22:10:25 +01:00
onkobu
9a3f4cc3a9 Overlay new filtering and fix multi-sensor call
- introduced -n to use sed-based filtering
- multi-sensor call yields output for all sensors instead of only last
2020-12-27 10:30:32 +01:00
onkobu
b504956f4f Argument order irrelevant/ sensor parsing improved
- -s/ --sensor first does not ignore following -c/ -w anymore
- current sensor's multiline output without adapter and temperatur in 2nd line
2020-12-12 13:41:10 +01:00
c60b88813a
Merge pull request #6 from lucaswall/patch-1
Correctly handle -s argument with spaces.
2020-04-17 19:46:40 +02:00
Lucas Wall
b6241fd46d
Correctly handle -s argument with spaces. 2020-04-17 14:27:49 -03:00
3 changed files with 44 additions and 13 deletions

10
HISTORY
View File

@ -34,3 +34,13 @@ Version 1.0:
- Enriched performance data output. For example, "CPU=34;40;55 MB=32;40;55" - Enriched performance data output. For example, "CPU=34;40;55 MB=32;40;55"
- Changed (and improved) the way temperatures are retrieved - Changed (and improved) the way temperatures are retrieved
- Other fixes and touch-ups, such as the help text now shows long options - 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

8
THANKS
View File

@ -5,6 +5,8 @@ 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 Nikodimos kikniknik on Github
Shakalandy shakalandy on Github
Onkobu Tanaake onkobu on Github

View File

@ -33,8 +33,8 @@
# # # #
############################################################################### ###############################################################################
VERSION="Version 1.0" VERSION="Version 1.2"
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)" AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se), (c) 2020 Onkobu Tanaake (oss@onkobutanaake.de)"
# 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}')
@ -88,11 +88,13 @@ Options:
-c, --critical <INTEGER> -c, --critical <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. 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: Examples:
./check_temp.sh -w 65 -c 75 --sensor CPU ./check_temp.sh [-n] -w 65 -c 75 --sensor CPU
./check_temp.sh -w 65 -c 75 --sensor CPU --sensor temp1 ./check_temp.sh [-n] -w 65 -c 75 --sensor CPU --sensor temp1
./check_temp.sh -w 65 -c 75 --sensor CPU -w 75 -c 85 --sensor temp1,GPU ./check_temp.sh [-n] -w 65 -c 75 --sensor CPU -w 75 -c 85 --sensor temp1,GPU
EOT EOT
} }
@ -144,7 +146,11 @@ function process_sensor {
fi fi
# Get the temperature # Get the temperature
# Grep the first float with a plus sign and keep only the integer # Grep the first float with a plus sign and keep only the integer
WHOLE_TEMP=$(${SENSORPROG} | grep "$sensor" | head -n1 | grep -o "+[0-9]\+\(\.[0-9]\+\)\?[^ \t,()]*" | head -n1) 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]\+\)\?") TEMPF=$(echo "$WHOLE_TEMP" | grep -o "[0-9]\+\(\.[0-9]\+\)\?")
TEMP=$(echo "$TEMPF" | cut -d. -f1) TEMP=$(echo "$TEMPF" | cut -d. -f1)
@ -184,6 +190,8 @@ __EOT
fi 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
@ -248,21 +256,32 @@ while [[ -n "$1" ]]; do
exit $STATE_UNKNOWN exit $STATE_UNKNOWN
fi fi
sensor_declared=true sensor_declared=true
process_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
if [ "$sensor_declared" = false ]; then
process_sensor "$default_sensor"
fi
case "$STATE" in case "$STATE" in
"$STATE_OK") STATE_TEXT="OK" ;; "$STATE_OK") STATE_TEXT="OK" ;;