2020-02-19 09:52:32 +01:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# NOTE: Must be run as root, so you probably need to setup sudo for this.
|
|
|
|
|
|
2020-02-19 18:32:30 +01:00
|
|
|
|
# Vars {{{
|
|
|
|
|
debug="0"
|
|
|
|
|
|
|
|
|
|
## Colors {{{
|
|
|
|
|
c_redb='\033[1;31m'
|
|
|
|
|
c_magentab='\033[1;35m'
|
|
|
|
|
c_reset='\033[0m'
|
|
|
|
|
## }}}
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
|
## Test if a disk really support SMART {{{
|
|
|
|
|
## Smartctl can give an health status even without a full support
|
|
|
|
|
## of SMART for some type (eg. scsi or megaraid).
|
|
|
|
|
## Exemple : SMART support is: Unavailable - device lacks SMART capability.
|
|
|
|
|
is_disk_support_smart() {
|
|
|
|
|
_disk="${1}"
|
|
|
|
|
_type="${2}"
|
|
|
|
|
|
|
|
|
|
_smarctl_support_result="/tmp/dsupport.$(basename "${_disk}")"
|
|
|
|
|
|
|
|
|
|
smart_support_msg=""
|
|
|
|
|
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − check if SMART is supported on : ${_disk}."
|
|
|
|
|
|
|
|
|
|
if test -f "${_smarctl_support_result}"; then rm -f "${_smarctl_support_result}"; fi
|
|
|
|
|
|
|
|
|
|
## Get only "support" lines from disk's informations
|
|
|
|
|
smartctl -d "${_type}" -i -- "${_disk}" | grep -E "^SMART support is:" -- > "${_smarctl_support_result}"
|
|
|
|
|
|
|
|
|
|
## Parse all "support" lines
|
|
|
|
|
while IFS= read -r _LINE; do
|
|
|
|
|
if ! printf -- '%s' "${_LINE}" | grep -q -E -- "(Enabled|Available)"
|
|
|
|
|
then
|
|
|
|
|
smart_support_msg="${_LINE}"
|
|
|
|
|
fi
|
|
|
|
|
done < "${_smarctl_support_result}"
|
|
|
|
|
|
|
|
|
|
if [ -z "${smart_support_msg}" ]; then
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − SMART seems fully supported on : ${_disk}."
|
|
|
|
|
else
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : is_disk_support_smart func − SMART is not fully supported on : ${_disk}. See smartctl informations :\n${smart_support_msg}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
rm -f -- "${_smarctl_support_result}"
|
|
|
|
|
}
|
|
|
|
|
## }}}
|
|
|
|
|
|
|
|
|
|
|
2020-02-19 09:52:32 +01:00
|
|
|
|
if test -f /tmp/dres; then rm -f /tmp/dres; fi
|
2020-02-19 16:00:36 +01:00
|
|
|
|
if test -f /tmp/dscan; then rm -f /tmp/dscan; fi
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 16:00:36 +01:00
|
|
|
|
# Get the list of all available devices
|
2020-02-19 11:18:25 +01:00
|
|
|
|
smartctl --scan > /tmp/dscan
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 16:00:36 +01:00
|
|
|
|
while IFS= read -r LINE; do
|
|
|
|
|
## Get device and type
|
2020-02-19 11:18:25 +01:00
|
|
|
|
DISK=$(echo "${LINE}" | cut -d" " -f1)
|
|
|
|
|
TYPE=$(echo "${LINE}" | cut -d" " -f3)
|
2020-02-19 16:00:36 +01:00
|
|
|
|
|
2020-02-19 18:32:30 +01:00
|
|
|
|
is_disk_support_smart "${DISK}" "${TYPE}"
|
|
|
|
|
|
2020-02-19 16:00:36 +01:00
|
|
|
|
## Get SMART Health Status and return code
|
2020-02-19 15:22:09 +01:00
|
|
|
|
DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}")
|
2020-02-19 09:52:32 +01:00
|
|
|
|
DCODE=$?
|
2020-02-19 15:23:28 +01:00
|
|
|
|
DSTBY=$(( DCODE & 2 ))
|
|
|
|
|
DFAIL=$(( DCODE & 8 ))
|
|
|
|
|
DWARN=$(( DCODE & 32 ))
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 16:00:36 +01:00
|
|
|
|
## Give a weight to each to color to easily get the page status
|
2020-02-19 09:52:32 +01:00
|
|
|
|
if test $DSTBY -ne 0
|
|
|
|
|
then
|
|
|
|
|
COLOR="4&clear"
|
|
|
|
|
elif test $DFAIL -ne 0
|
|
|
|
|
then
|
|
|
|
|
COLOR="1&red"
|
|
|
|
|
elif test $DWARN -ne 0
|
|
|
|
|
then
|
|
|
|
|
COLOR="2&yellow"
|
|
|
|
|
else
|
|
|
|
|
COLOR="3&green"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-02-19 11:18:25 +01:00
|
|
|
|
echo "${COLOR} $DISK ${TYPE}"
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 11:18:25 +01:00
|
|
|
|
echo "${COLOR} $DISK ${TYPE}" | cut -c2- >>/tmp/dres
|
2020-02-19 09:52:32 +01:00
|
|
|
|
echo "" >>/tmp/dres
|
2020-02-19 16:00:36 +01:00
|
|
|
|
echo "$DRES" | grep -v -E "^smartctl|^Copyright|^$|^===" >>/tmp/dres
|
2020-02-19 09:52:32 +01:00
|
|
|
|
echo "------------------------------------------------------------" >>/tmp/dres
|
|
|
|
|
echo "" >>/tmp/dres
|
|
|
|
|
echo "" >>/tmp/dres
|
2020-02-19 11:18:25 +01:00
|
|
|
|
done < /tmp/dscan >/tmp/dcheck
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 16:00:36 +01:00
|
|
|
|
# Set the global color according to the highest alert
|
2020-02-19 15:24:41 +01:00
|
|
|
|
COLOR=$(< /tmp/dcheck awk '{print $1}' | sort | uniq | head -1 | cut -c3-)
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 16:00:36 +01:00
|
|
|
|
$XYMON "${XYMSRV}" "status ${MACHINE}.smart ${COLOR} SMART health check
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
2020-02-19 15:24:41 +01:00
|
|
|
|
$(< /tmp/dcheck cut -c2-)
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
|
|
|
|
==================== Detailed status ====================
|
|
|
|
|
|
2020-02-19 15:22:09 +01:00
|
|
|
|
$(cat /tmp/dres)
|
2020-02-19 09:52:32 +01:00
|
|
|
|
"
|
|
|
|
|
|
2020-02-19 11:18:25 +01:00
|
|
|
|
rm -f /tmp/dres /tmp/dcheck /tmp/dscan
|
2020-02-19 09:52:32 +01:00
|
|
|
|
|
|
|
|
|
exit 0
|