Compare commits

...

47 Commits
v0.5 ... 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
b618a2cc8d Bumped version and updated HISTORY & THANKS 2019-05-30 21:05:21 +02:00
d166498290
Merge pull request #4 from kikniknik/master
Support for multiple sensors and general Improvements
2019-05-30 20:20:48 +02:00
kikniknik
bb88a0a5af Add support for multiple sensors 2019-05-28 19:48:14 +03:00
kikniknik
1912395135 Enrich performance data output 2019-05-28 02:24:23 +03:00
kikniknik
8e88c82517 Change the way that temperature is retrieved
Fixes issue with temperatures < 10.
2019-05-28 02:09:07 +03:00
2286e23d19 Changed the Performace Data Field 2017-06-29 05:24:15 +02:00
52670df1be Removed /etc from whereis-path 2014-09-20 10:47:26 +02:00
fcb2be369d Merge pull request #3 from Elyrith/master
A lot of changes
2014-09-20 10:10:36 +02:00
Ryan Loudfoot
aa68be9a5a Add more acceptable paths to whereis command, as per further testing. 2014-09-06 17:46:11 -04:00
Ryan Loudfoot
615089a044 Now use whereis to find the sensors program instead of assuming a path. Also mention help in the readme if the program is not found. 2014-09-06 16:36:21 -04:00
Ryan Loudfoot
75b4a1c6d6 Run through shellcheck.net. Converted all printf to echo since it's easier, may convert back later if given good reason. 2013-11-02 13:18:46 -04:00
Ryan Loudfoot
32252b61ea Add utils.sh checking code. 2013-11-02 12:38:43 -04:00
Ryan Loudfoot
b2e2301067 Forgot to update version number last update. Fixed. 2013-11-02 12:30:25 -04:00
dc34595ff0 Merge pull request #2 from Elyrith/0.9
Fixed some typos, including one that created a bug
2013-10-06 00:51:56 -07:00
Elyrith
b8f3e6a283 Merge branches 'master' and '0.9' 2013-10-05 23:39:52 -04:00
Elyrith
6b1c3b0d95 Fix typo: If lm-sensors is not installed, it would exit with OK instead of UNKNOWN. 2013-10-05 23:39:34 -04:00
Elyrith
664cac6965 Typo and changed 'sensors' to 'lm-sensors' in message if it's not installed. 2013-10-05 23:37:59 -04:00
Elyrith
bf12a45ab9 README and THANKS updates. 2013-10-05 23:33:19 -04:00
a8382bf6c5 Added instructions for OpenSUSE 2013-06-08 14:23:39 +02:00
85be1e7ccd Merge pull request #1 from Elyrith/master
Added some instructions to install lm-sensors
2013-06-06 20:40:09 -07:00
Elyrith
c19869c89f Update repo link. 2013-06-04 17:30:16 -04:00
Elyrith
39313dffac Add help instructions and where to find them. 2013-06-04 17:27:50 -04:00
f2acaea98b Changed version to 0.8 and moved version history to HISTORY file 2012-12-08 07:19:28 +01:00
41d103ab22 Limit parsing to only grab the first line of output for performance data 2012-12-08 06:58:35 +01:00
c594f1768f Merged in elyrith/check_temp (pull request #5) 2012-12-08 00:15:33 +01:00
Elyrith
877d08b166 Merge remote-tracking branch 'jackbenny/check_temp/master' 2012-12-07 17:59:54 -05:00
Elyrith
0fe7e5aa90 Limit parsing to only grab the first result found for the sensor. Sometimes you get more than one result for things like CPU cores (Quad core printing as: Core0,Core0,Core1,Core1 on a Toshiba laptop with sensor k8temp-pci-00c3) 2012-12-07 17:38:10 -05:00
e9c10b3f54 Fixed tabs/spaces in THANKS file and added URL to the BitBucket project 2012-12-06 05:05:10 +01:00
Elyrith
6df8362ab0 Put the old sensor parsing back, but commented. It may help somebody. 2012-12-01 21:02:36 -05:00
95a7d33142 Merged in elyrith/check_temp (pull request #3) 2012-12-01 03:09:30 +01:00
Elyrith
92a9b70125 Fixed line numbers mentioned in comments due to my comments pushing the code down 2012-11-30 00:29:22 -05:00
Elyrith
7e33e13abc Increased version to 0.7 because of new "advanced" sensor parsing (line 191)
-Added following line edits info to comments at the top and increased version number
-Line 193, modified sensor parsing to cut after the first '+' since all positive temperatures are preceded by a + and the one we want is labeled first
-Line 211, reduced "verbosity" needed to see verbose info (was 2: -v -v)
-Line 229-232, now checks if no sensor data was found and exits with STATE_UNKNOWN
-Fixed 2 typos, one in output and other an in-line comment
-Updated line numbers in previous version info lines in comments since my comments pushed the lines down
2012-11-30 00:08:45 -05:00
3223933494 Merged in elyrith/check_temp (pull request #2) 2012-11-30 00:55:10 +01:00
Elyrith
add8a481c7 Added myself to THANKS with permission from author. 2012-11-29 18:51:03 -05:00
37b8e9db82 Merged in elyrith/check_temp (pull request #1)
A few typos and mentioning that is uses *nix 'sensors'
Added PERFDATA to put Nagios Performance Data when viewing service details
2012-11-30 00:35:45 +01:00
Elyrith
e4228c22e5 A few typos and mentioning that is uses *nix 'sensors' 2012-11-29 17:56:54 -05:00
Elyrith
3c8ab0cdc2 Added PERFDATA to put Nagios Performance Data when viewing service details. 2012-11-29 17:18:40 -05:00
844218b7d5 Fixed a bug by escaping the -? option 2012-02-19 23:03:10 +01:00
dc66a71fce Updated README with known forks 2012-01-26 02:13:40 +01:00
4 changed files with 241 additions and 104 deletions

46
HISTORY Normal file
View File

@ -0,0 +1,46 @@
Version 0.2:
Line 103, fixed the missing "-n" option (Thanks to Chad who pointed this out
this out for me). Also added a "shopt -s extglob". (Thx to Chad)
Version 0.5:
Line 168, fixed a typo (EXIT_UNKNOWN to STATE_UNKNOWN)
Version 0.7:
Line 193, modified sensor parsing to cut after the first '+' since all
positive temperatures are preceded by a '+'
Line 211, reduced "verbosity" needed to see verbose info (was 2: -v -v)
Line 229-232, now checks to see if no sensor data was found and
exits with STATE_UNKNOWN
Version 0.8:
Line 196 and 230, added 'head -n1' to only fetch the first result from
sensors output. On some machine you get two Core0 and two Core1 temps.
Moved version history to it's own file, HISTORY
Version 0.94:
Lots of changes and bugfixes. A huge thank you to Ryan Loudfoot who
has fixed bugs and worked out a new way to detect the sensors-program.
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
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

36
README
View File

@ -1,10 +1,38 @@
check_temp
A small Nagios plugin that checks the CPU (or M/B) temperature with lm-sensors.
It's written in Bash and uses some sed & awk.
Default is to check the CPU temperature but this can be changed to for example
It's written in Bash and uses *nix "sensors" and some sed & awk.
Default is to check the CPU temperature but this can be changed to, for example,
the motherboard temperature with a "--sensor" argument.
The plugin complies with the guidelines, for example uses -w -c -v arguments
etc. It also does some basic sanity checks and has a exit 3 catchall.
etc. It also does some basic sanity checks and has a exit 3 catch-all.
The plugin were submitted to Nagios Exchange in 2011.
The plugin was submitted to Nagios Exchange in 2011.
Known forks of check_temp:
There is a very good Perl fork of check_temp written by Chad Columbus. It's
available on Nagios Exchange at
http://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_temp-2Epl/details
Required:
1) Install lm-sensors:
a) On Debian/Ubuntu... apt-get install lm-sensors
b) On OpenSUSE etc... zypper in sensors
2) Run sensors-detect:
sudo sensors-detect
Let it check for any sensors that you feel are necessary, or all. You can just
press <ENTER> to have it use the default option for each check. There is a
warning in the manpages (man sensors-detect) that there are (some rare)
hardware sensors that may lock up or even be permanently damaged, so be aware
of that.
**********
MAKE SURE YOU TYPE "YES" TO THE LAST OPTION: "Do you want to add these lines automatically to /etc/modules? (yes/NO)"
**********
3) Restart module-init-tools service (On Debian/Ubuntu)
a) /etc/init.d/module-init-tools restart
or
b) service module-init-tools restart

7
THANKS
View File

@ -1,9 +1,12 @@
check_temp THANKS file
check_temp was originally written by Jack-Benny Persson.
Some kind people has been contributing by reporting problems, suggesting
Some kind people have been contributing by reporting problems, suggesting
improvements or submitting code.
Here is a list of these kind people.
Chad Columbus ccolumbu@hotmail.com
Ryan Loudfoot elyrith@gmail.com
Nikodimos kikniknik on Github
Shakalandy shakalandy on Github
Onkobu Tanaake onkobu on Github

View File

@ -24,22 +24,33 @@
# #
# Nagios plugin to monitor CPU and M/B temperature with sensors. #
# Written in Bash (and uses sed & awk). #
# Version 0.2: Line 98, fixed the missing "-n" option (Thanks to Chad who #
# pointed this out for me). Also added a "shopt -s extglob". (Thx to Chad) #
# Version 0.5: Line 162, fixed a typo (EXIT_UNKNOWN to STATE_UNKNOWN) #
# Latest version of check_temp can be found at the below URL: #
# https://github.com/jackbenny/check_temp #
# #
# If you are having problems getting it to work, check the instructions in #
# the README first. It walks you though install lm-sensors and getting it to #
# display sensor data. #
# #
###############################################################################
VERSION="Version 0.5"
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
VERSION="Version 1.2"
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se), (c) 2020 Onkobu Tanaake (oss@onkobutanaake.de)"
# Sensor program
SENSORPROG=/usr/bin/sensors
SENSORPROG=$(whereis -b -B /{bin,sbin,usr} /{bin,sbin,usr}/* -f sensors | awk '{print $2}')
# Exit codes
# 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
@ -48,32 +59,42 @@ 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 temperatur with the use of sensors\n"
echo "$AUTHOR"
echo "Monitor temperature with the use of sensors"
/bin/cat <<EOT
Options:
-h
-h, --help
Print detailed help screen
-V
-V, --version
Print version information
-v
-v, --verbose
Verbose output
--sensor WORD
-s, --sensor <WORD[,DISPLAY_NAME]>
Set what to monitor, for example CPU or MB (or M/B). Check sensors for the
correct word. Default is CPU.
-w INTEGER
Exit with WARNING status if above INTEGER degres
-c INTEGER
Exit with CRITICAL status if above INTEGER degres
correct word. Default is CPU. A different display name can be used in output,
by adding it next to sensor with a comma.
It can be used more than once, with different warning/critical thresholds optionally.
-w, --warning <INTEGER>
Exit with WARNING status if above INTEGER degrees
-c, --critical <INTEGER>
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
}
@ -85,14 +106,92 @@ thresh_warn=
# Critical threshold
thresh_crit=
# Hardware to monitor
sensor=CPU
default_sensor="CPU"
sensor_declared=false
STATE=$STATE_OK
# See if we have sensors program installed and can execute it
if [[ ! -x "$SENSORPROG" ]]; then
printf "\nIt appears you don't have sensors installed in $SENSORPROG\n"
exit $STATE_UNKOWN
echo "It appears you don't have lm-sensors installed. You may find help in the readme for this script."
exit $STATE_UNKNOWN
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
while [[ -n "$1" ]]; do
case "$1" in
@ -115,7 +214,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
@ -123,7 +222,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
@ -134,7 +233,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
@ -142,7 +241,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
@ -150,86 +249,47 @@ while [[ -n "$1" ]]; do
shift 2
;;
-?)
print_help
exit $STATE_OK
;;
--sensor)
-s | --sensor)
if [[ -z "$2" ]]; then
printf "\nOption $1 requires an argument"
echo "Option $1 requires an argument"
print_help
exit $STATE_UNKNOWN
fi
sensor=$2
sensor_declared=true
sensors_to_check="$2"
shift 2
;;
-n | --new-filter)
CLASSIC_FILTER=0
shift 1
;;
*)
printf "\nInvalid option '$1'"
echo "Invalid option '$1'"
print_help
exit $STATE_UNKNOWN
;;
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
# Check if a sensor were specified
if [[ -z "$sensor" ]]; then
# No sensor to monitor were specified
printf "\nNo sensor specified"
print_help
exit $STATE_UNKNOWN
fi
case "$STATE" in
"$STATE_OK") STATE_TEXT="OK" ;;
"$STATE_WARNING") STATE_TEXT="WARNING" ;;
"$STATE_CRITICAL") STATE_TEXT="CRITICAL" ;;
"$STATE_UNKNOWN") STATE_TEXT="UNKNOWN" ;;
esac
#Get the temperature
TEMP=`${SENSORPROG} | grep "$sensor Temp" | awk '{print $3}' | cut -c2-3`
# Check if the tresholds has been set correctly
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
# One or both thresholds were not specified
printf "\nThreshold 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"
print_help
exit $STATE_UNKNOWN
fi
# Verbose output
if [[ "$verbosity" -ge 2 ]]; then
/bin/cat <<__EOT
Debugging information:
Warning threshold: $thresh_warn
Critical threshold: $thresh_crit
Verbosity level: $verbosity
Current $sensor temperature: $TEMP
__EOT
printf "\n Temperature lines directly from sensors:\n"
${SENSORPROG} | grep "Temp"
printf "\n\n"
fi
# And finally check the temperature against our thresholds
if [[ "$TEMP" -gt "$thresh_crit" ]]; then
# Temperature is above critical threshold
echo "$sensor CRITICAL - Temperature is $TEMP"
exit $STATE_CRITICAL
elif [[ "$TEMP" -gt "$thresh_warn" ]]; then
# Temperature is above warning threshold
echo "$sensor WARNING - Temperature is $TEMP"
exit $STATE_WARNING
else
# Temperature is ok
echo "$sensor OK - Temperature is $TEMP"
exit $STATE_OK
fi
exit 3
OUTPUT_TEXT=$(echo $OUTPUT_TEXT | sed -e 's/, //')
echo "TEMPERATURE $STATE_TEXT - $OUTPUT_TEXT |$PERFDATA"
exit $STATE