Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52670df1be | |||
| fcb2be369d | |||
|
|
aa68be9a5a | ||
|
|
615089a044 | ||
|
|
75b4a1c6d6 | ||
|
|
32252b61ea | ||
|
|
b2e2301067 | ||
| dc34595ff0 | |||
|
|
b8f3e6a283 | ||
|
|
6b1c3b0d95 | ||
|
|
664cac6965 | ||
|
|
bf12a45ab9 | ||
| a8382bf6c5 | |||
| 85be1e7ccd | |||
|
|
c19869c89f | ||
|
|
39313dffac | ||
| f2acaea98b | |||
| 41d103ab22 | |||
| c594f1768f | |||
|
|
877d08b166 | ||
|
|
0fe7e5aa90 | ||
| e9c10b3f54 | |||
|
|
6df8362ab0 | ||
| 95a7d33142 | |||
|
|
92a9b70125 | ||
|
|
7e33e13abc | ||
| 3223933494 | |||
|
|
add8a481c7 | ||
| 37b8e9db82 | |||
|
|
e4228c22e5 | ||
|
|
3c8ab0cdc2 | ||
| 844218b7d5 | |||
| dc66a71fce |
25
HISTORY
Normal file
25
HISTORY
Normal file
@@ -0,0 +1,25 @@
|
||||
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.
|
||||
36
README
36
README
@@ -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
|
||||
|
||||
4
THANKS
4
THANKS
@@ -1,9 +1,9 @@
|
||||
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
|
||||
|
||||
@@ -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"
|
||||
VERSION="Version 0.94"
|
||||
AUTHOR="(c) 2011 Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
||||
|
||||
# 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,15 +59,15 @@ 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:
|
||||
@@ -71,9 +82,9 @@ Options:
|
||||
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
|
||||
Exit with WARNING status if above INTEGER degrees
|
||||
-c INTEGER
|
||||
Exit with CRITICAL status if above INTEGER degres
|
||||
Exit with CRITICAL status if above INTEGER degrees
|
||||
EOT
|
||||
}
|
||||
|
||||
@@ -89,8 +100,8 @@ sensor=CPU
|
||||
|
||||
# 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
|
||||
|
||||
# Parse command line options
|
||||
@@ -115,7 +126,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 +134,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 +145,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 +153,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,14 +161,14 @@ while [[ -n "$1" ]]; do
|
||||
shift 2
|
||||
;;
|
||||
|
||||
-?)
|
||||
-\?)
|
||||
print_help
|
||||
exit $STATE_OK
|
||||
;;
|
||||
|
||||
--sensor)
|
||||
if [[ -z "$2" ]]; then
|
||||
printf "\nOption $1 requires an argument"
|
||||
echo "Option $1 requires an argument"
|
||||
print_help
|
||||
exit $STATE_UNKNOWN
|
||||
fi
|
||||
@@ -166,7 +177,7 @@ while [[ -n "$1" ]]; do
|
||||
;;
|
||||
|
||||
*)
|
||||
printf "\nInvalid option '$1'"
|
||||
echo "Invalid option '$1'"
|
||||
print_help
|
||||
exit $STATE_UNKNOWN
|
||||
;;
|
||||
@@ -177,32 +188,34 @@ done
|
||||
# Check if a sensor were specified
|
||||
if [[ -z "$sensor" ]]; then
|
||||
# No sensor to monitor were specified
|
||||
printf "\nNo sensor specified"
|
||||
echo "No sensor specified"
|
||||
print_help
|
||||
exit $STATE_UNKNOWN
|
||||
fi
|
||||
|
||||
|
||||
#Get the temperature
|
||||
TEMP=`${SENSORPROG} | grep "$sensor Temp" | awk '{print $3}' | cut -c2-3`
|
||||
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 tresholds has been set correctly
|
||||
# Check if the thresholds have been set correctly
|
||||
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
|
||||
# One or both thresholds were not specified
|
||||
printf "\nThreshold not set"
|
||||
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
|
||||
printf "\nWarning temperature should be lower than critical"
|
||||
echo "Warning temperature should be lower than critical"
|
||||
print_help
|
||||
exit $STATE_UNKNOWN
|
||||
fi
|
||||
|
||||
|
||||
# Verbose output
|
||||
if [[ "$verbosity" -ge 2 ]]; then
|
||||
if [[ "$verbosity" -ge 1 ]]; then
|
||||
/bin/cat <<__EOT
|
||||
Debugging information:
|
||||
Warning threshold: $thresh_warn
|
||||
@@ -210,26 +223,34 @@ Debugging information:
|
||||
Verbosity level: $verbosity
|
||||
Current $sensor temperature: $TEMP
|
||||
__EOT
|
||||
printf "\n Temperature lines directly from sensors:\n"
|
||||
${SENSORPROG} | grep "Temp"
|
||||
printf "\n\n"
|
||||
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" -gt "$thresh_crit" ]]; then
|
||||
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"
|
||||
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"
|
||||
echo "$sensor WARNING - Temperature is $TEMP | $PERFDATA"
|
||||
exit $STATE_WARNING
|
||||
|
||||
else
|
||||
# Temperature is ok
|
||||
echo "$sensor OK - Temperature is $TEMP"
|
||||
echo "$sensor OK - Temperature is $TEMP | $PERFDATA"
|
||||
exit $STATE_OK
|
||||
fi
|
||||
exit 3
|
||||
|
||||
exit $STATE_UNKNOWN
|
||||
|
||||
Reference in New Issue
Block a user