From 5ec0d0c8ee894840a59223204e45b0716ce965a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Thu, 20 Feb 2020 15:55:29 +0100 Subject: [PATCH] Manage case of scan doesn't return any result --- xymon/plugins/client/ext/smart | 92 ++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/xymon/plugins/client/ext/smart b/xymon/plugins/client/ext/smart index 775b3d5..0db51a4 100755 --- a/xymon/plugins/client/ext/smart +++ b/xymon/plugins/client/ext/smart @@ -87,56 +87,60 @@ if test -f /tmp/dscan; then rm -f -- /tmp/dscan; fi smartctl --scan > /tmp/dscan # TODO: Test if the file is not empty +if test -s /tmp/dscan; then + while IFS= read -r LINE; do + ## Get device path + DISK=$(echo "${LINE}" | cut -d" " -f1) + ## Try to determine the best type + SCANNED_TYPE=$(echo "${LINE}" | cut -d" " -f3) + choose_correct_type "${DISK}" "${SCANNED_TYPE}" -while IFS= read -r LINE; do - ## Get device path - DISK=$(echo "${LINE}" | cut -d" " -f1) - ## Try to determine the best type - SCANNED_TYPE=$(echo "${LINE}" | cut -d" " -f3) - choose_correct_type "${DISK}" "${SCANNED_TYPE}" + ## If no correct type was found for this device + if [ -z "${TYPE}" ]; then + [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART is not fully supported." + DRES=$(printf '%s' "${SMART_SUPPORT_MSG}") + DCODE="2" + TYPE="unsupported" + else + [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART seems fully supported, proceed normally." + ### Get SMART Health Status and return code + DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}") + DCODE=$? + fi - ## If no correct type was found for this device - if [ -z "${TYPE}" ]; then - [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART is not fully supported." - DRES=$(printf '%s' "${SMART_SUPPORT_MSG}") - DCODE="2" - TYPE="unsupported" - else - [ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : SMART seems fully supported, proceed normally." - ### Get SMART Health Status and return code - DRES=$(/usr/sbin/smartctl -H -d "${TYPE}" -n standby "${DISK}") - DCODE=$? - fi + DSTBY=$(( DCODE & 2 )) + DFAIL=$(( DCODE & 8 )) + DWARN=$(( DCODE & 32 )) - DSTBY=$(( DCODE & 2 )) - DFAIL=$(( DCODE & 8 )) - DWARN=$(( DCODE & 32 )) + ## Give a weight to each to color to easily get the page status + 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 - ## Give a weight to each to color to easily get the page status - 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 + echo "${COLOR} $DISK ${TYPE}" - echo "${COLOR} $DISK ${TYPE}" + { + echo "${COLOR} $DISK ${TYPE}" | cut -c2- + echo "" + echo "$DRES" | grep -v -E "^smartctl|^Copyright|^$|^===" + echo "------------------------------------------------------------" + echo "" + echo "" + } >>/tmp/dres + done < /tmp/dscan > /tmp/dcheck - { - echo "${COLOR} $DISK ${TYPE}" | cut -c2- - echo "" - echo "$DRES" | grep -v -E "^smartctl|^Copyright|^$|^===" - echo "------------------------------------------------------------" - echo "" - echo "" - } >>/tmp/dres -done < /tmp/dscan >/tmp/dcheck +else + echo "1&red Error while scanning devices with smartctl" > /tmp/dcheck +fi # Set the global color according to the highest alert COLOR=$(< /tmp/dcheck awk '{print $1}' | sort | uniq | head -1 | cut -c3-)