Skip to content

Commit

Permalink
Script para verificar la temperatura en unidades HDD/SSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
mggimenez committed May 28, 2024
1 parent 89f3a86 commit 144202c
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 0 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,67 @@ Check the memory used by a Docker container.



# check_hdd_temp.sh

Es un programa (script) para verificar para verificar la temperatura utilizada por una unidad de almacenamiento HDD/SSD.


## Invocación del programa

Desde una terminal el programa puede invocarse de la siguiente manera:

<pre>
/usr/lib64/nagios/plugins/check_hdd_temp.sh --device /dev/sda
</pre>

Una vez ejecutado el script devolverá los siguientes datos:

<pre>
Temp OK: the /dev/sda drive is at 24°C. | TEMP=24;80;100;0;0
</pre>


## Ayuda en línea

El programa cuenta con una ayuda en línea para permitirle al usuario conocer sus capacidades. La ayuda en línea puede invocarse de la siguiente manera:

<pre>
~ # /usr/lib64/nagios/plugins/check_hdd_temp.sh --help
check_hdd_temp.sh:
Checks the temperature used by an HDD/SSD storage drive.

Uso:
/usr/lib64/nagios/plugins/check_hdd_temp.sh [-h|--help]
/usr/lib64/nagios/plugins/check_hdd_temp.sh [-c|--critical] CRITICAL [-d|--device] HDD/SSD [-w|--warning] WARNING

--help, -h
Show this help.

--critical, -c
Parameter to pass critical temperature in degrees Celsius value.

CRITICAL
Critical temperature in degrees Celsius.


--device, -d
Parameter to indicate the HDD/SSD storage unit to monitor.

HDD/SSD
HDD/SSD storage drive, for example /dev/sda.


--warning, -w
Parameter to pass warning temperature in degrees Celsius value.

WARNING
Warning temperature in degrees Celsius.

</pre>




# check_nvme_temp.sh

Es un programa (script) para verificar para verificar la temperatura utilizada por una unidad de almacenamiento NVME.
Expand Down
226 changes: 226 additions & 0 deletions plugins/check_hdd_temp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
#!/bin/bash
#
# check_nvme_temp.sh: script para verificar la temperatura utilizada por una
# unidad de almacenamiento HDD/SDD.
#
# (C) 2023 Martin Andres Gomez Gimenez <[email protected]>
# Distributed under the terms of the GNU General Public License v3
#



# Default values.
CRITICAL="100"
WARNING="80"
PERFDATA="TEMP=0;0;0;0;0"



# no_parameters()
# Función para alertar la falta de parámetros obligatorios.
#
function no_parameters() {
echo "ERROR: the number of parameters is insufficient. See"
echo " $(basename ${0}) --help"
echo ""
}



# Función para mostrar ayuda de uso.
#
function usage () {
local PROG_NAME=$(basename $0)
local PROG_PATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,')
echo "${PROG_NAME}:"
echo "Checks the temperature used by an HDD/SSD storage drive."
echo ""
echo " Uso: "
echo " ${PROG_PATH}/${PROG_NAME} [-h|--help]"
echo " ${PROG_PATH}/${PROG_NAME} [-c|--critical] CRITICAL [-d|--device] HDD/SSD [-w|--warning] WARNING"
echo ""
echo " --help, -h"
echo " Show this help."
echo ""
echo " --critical, -c"
echo " Parameter to pass critical temperature in degrees Celsius value."
echo ""
echo " CRITICAL"
echo " Critical temperature in degrees Celsius."
echo ""
echo ""
echo " --device, -d"
echo " Parameter to indicate the NVME storage unit to monitor."
echo ""
echo " HDD/SSD"
echo " HDD/SSD storage drive, for example /dev/sda."
echo ""
echo ""
echo " --warning, -w"
echo " Parameter to pass warning temperature in degrees Celsius value."
echo ""
echo " WARNING"
echo " Warning temperature in degrees Celsius."
echo ""
}



# parameters()
# Verifica el correcto pasaje de parámetros.
#
function parameters() {
local OPT=$(getopt \
--options c:d:hw: \
--longoptions critical:,device:,help,warning: \
--name '$(basename ${0})' \
-- "${@}")

if [ $? -ne 0 ]; then
echo 'Error in parameters...' >&2
exit 1
fi

eval set -- "${OPT}"

while true; do

case "$1" in

-c | --critical )
CRITICAL=${2}
shift 2
continue
;;

-d | --device )
DEVICE="${2}"
shift 2
continue
;;

-h | --help )
usage
exit
;;

-w | --warning )
WARNING=${2}
shift 2
continue
;;

-- )
shift
break
;;

* )
echo "Error in parameters. See:"
echo " $(basename ${0}) --help"
echo ""
exit 1
;;
esac

shift
done

}


# Función para informar el estado de los servicios monitoreados en Icinga2.
# STATUS: código de estado a informar.
#
function status() {
local STATE=${1}

case ${STATE} in
0 )
STATUS="OK"
echo "Temp ${STATUS}: the ${DEVICE} drive is at ${TEMP}°C. | ${PERFDATA}"
return 0
;;
1 )
STATUS="WARNING"
echo "Temp ${STATUS}: the ${DEVICE} drive is at ${TEMP}°C. | ${PERFDATA}"
return 1
;;
2 )
STATUS="CRITICAL"
echo "Temp ${STATUS}: the ${DEVICE} drive is at ${TEMP}°C. | ${PERFDATA}"
return 2
;;
* )
STATUS="UNKNOWN"
echo "Temp ${STATUS}. | ${PERFDATA}"
return 3
;;
esac

}



# check_device()
# Verifica que se trata de un dispositivo especial de bloque.
function check_device() {
if [ ! -b $DEVICE ];then
echo "UNKNOWN: ${DEVICE} is not a block special file"
return 3
fi
}



# hddtemp_installed()
# Función para determinar si hddmp está instalado.
hddtemp_installed() {
if [[ ! -x /usr/bin/hddtemp ]]; then
echo "hddtemp is not installed on this system."
return 3
fi
}



# get_hddtemp()
# Función para obtener la temperatura del dispositivo.
function get_hddtemp() {
TEMP=$(/usr/bin/hddtemp ${DEVICE} -n)

case "${TEMP}" in
[0-9]* )
;;
* )
echo "UNKNOWN: Could not get temperature from: $DEVICE"
return 3
;;
esac

}



# Verificación de parámetros.
if [ "${#}" == "0" ]; then
no_parameters
status 4
exit
else
parameters "${@}"
check_device "${DEVICE}"
hddtemp_installed
fi

get_hddtemp
PERFDATA="TEMP=${TEMP};${WARNING};${CRITICAL};0;0"

if [ "${TEMP}" -ge "${CRITICAL}" ]; then
status 2
elif [ "${TEMP}" -ge "${WARNING}" ]; then
status 1
else
status 0
fi

6 changes: 6 additions & 0 deletions sudoers.d/check_hdd_temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
icinga ALL=(root) NOPASSWD: /usr/lib/nagios/plugins/check_hdd_temp.sh
icinga ALL=(root) NOPASSWD: /usr/lib64/nagios/plugins/check_hdd_temp.sh

nagios ALL=(root) NOPASSWD: /usr/lib/nagios/plugins/check_hdd_temp.sh
nagios ALL=(root) NOPASSWD: /usr/lib64/nagios/plugins/check_hdd_temp.sh

0 comments on commit 144202c

Please sign in to comment.