2020-05-28 06:01:50 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-05-28 09:35:11 +02:00
|
|
|
# shellcheck disable=SC2028
|
2020-05-28 06:01:50 +02:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# This check_hpraid is a fork from check_cciss v0.15 written by Simone Rosa.
|
2020-05-28 09:35:11 +02:00
|
|
|
# Fork written by Evolix and for Evolix usage (Debian only).
|
2020-05-29 02:43:15 +02:00
|
|
|
# Usage of old tools and drivers were removed to use only the smartpqi or hpsa drivers and the ssacli tool from HP.
|
2020-05-28 09:35:11 +02:00
|
|
|
# Tools not used on Debian were also removed.
|
|
|
|
# Linting tool shellcheck was used to use a better bash coding style.
|
|
|
|
# Upstream at:
|
2020-05-28 06:01:50 +02:00
|
|
|
# https://gitea.evolix.org/evolix/ansible-roles/src/branch/stable/nagios-nrpe/files/plugins
|
|
|
|
# Source of the fork:
|
|
|
|
# https://exchange.nagios.org/directory/Plugins/Hardware/Storage-Systems/RAID-Controllers/check_cciss--2D-HP-and-Compaq-Smart-Array-Hardware-status/details
|
2020-05-28 08:33:00 +02:00
|
|
|
#
|
|
|
|
# Licence: GPLv2
|
2020-05-28 06:01:50 +02:00
|
|
|
# Description:
|
|
|
|
#
|
|
|
|
# This plugin checks hardware status for Smart Array Controllers,
|
|
|
|
# using HPE Smart Storage Administrator. It should support Debian 9 and over.
|
|
|
|
# (Array, controller, cache, battery, etc...)
|
|
|
|
#
|
2020-06-16 03:36:24 +02:00
|
|
|
# Known working RAID controllers:
|
|
|
|
#
|
|
|
|
# - Adaptec Smart Storage PQI 12G SAS/PCIe 3 (rev 01)
|
|
|
|
# | Smart Array P408i-a SR Gen10
|
|
|
|
# | Smart Array E208i-a SR Gen10
|
|
|
|
#
|
|
|
|
#
|
2020-05-28 06:01:50 +02:00
|
|
|
# NOTE:
|
|
|
|
#
|
|
|
|
# You need to install the proprietary tool HPE Smart Storage Administrator (ssacli) from:
|
|
|
|
# https://downloads.linux.hpe.com/SDR/repo/mcp
|
|
|
|
# Also NRPE need to launch ssacli as root.
|
|
|
|
#
|
|
|
|
# Please add this line to /etc/sudoers :
|
|
|
|
# --------------------------------------------------
|
|
|
|
# nagios ALL=NOPASSWD: /usr/sbin/ssacli
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
2020-06-16 03:53:00 +02:00
|
|
|
# ./check_hpraid
|
2020-05-28 06:01:50 +02:00
|
|
|
# ----------------
|
|
|
|
# RAID OK
|
|
|
|
#
|
2020-06-16 03:53:00 +02:00
|
|
|
# ./check_hpraid -v
|
2020-05-28 06:01:50 +02:00
|
|
|
# -------------------
|
|
|
|
# RAID OK: Smart Array 6i in Slot 0 array A logicaldrive 1 (67.8 GB, RAID 1+0, OK)
|
|
|
|
# [Controller Status: OK Cache Status: OK Battery Status: OK]
|
|
|
|
#
|
|
|
|
# RAID CRITICAL - HP Smart Array Failed: Smart Array 6i in Slot 0 (Embedded) \
|
|
|
|
# array A logicaldrive 1 (33.9 GB, RAID 1, Interim Recovery Mode) \
|
|
|
|
# physicaldrive 1:0 (port 1:id 0 , Parallel SCSI, --- GB, Failed)
|
|
|
|
#
|
|
|
|
# RAID WARNING - HP Smart Array Rebuilding: Smart Array 6i in Slot 0 (Embedded) \
|
|
|
|
# array A logicaldrive 1 (33.9 GB, RAID 1, Recovering, 26% complete) \
|
|
|
|
# physicaldrive 1:0 (port 1:id 0 , Parallel SCSI, 36.4 GB, Rebuilding)
|
|
|
|
#
|
2020-06-16 03:53:00 +02:00
|
|
|
# ./check_hpraid -v -p
|
2020-05-28 06:01:50 +02:00
|
|
|
# --------------------
|
|
|
|
# RAID OK: Smart Array 6i in Slot 0 (Embedded) array A logicaldrive 1 (33.9 GB, RAID 1, OK)
|
|
|
|
# physicaldrive 2:0 (port 2:id 0 , Parallel SCSI, 36.4 GB, OK)
|
|
|
|
# physicaldrive 2:1 (port 2:id 1 , Parallel SCSI, 36.4 GB, OK)
|
|
|
|
# physicaldrive 1:5 (port 1:id 5 , Parallel SCSI, 72.8 GB, OK, spare)
|
|
|
|
# [Controller Status: OK Cache Status: OK Battery/Capacitor Status: OK]
|
|
|
|
#
|
|
|
|
# RAID CRITICAL - HP Smart Array Failed: Smart Array 6i in Slot 0 (Embedded) \
|
|
|
|
# array A logicaldrive 1 (33.9 GB, RAID 1, Interim Recovery Mode) \
|
|
|
|
# physicaldrive 1:0 (port 1:id 0 , Parallel SCSI, --- GB, Failed) \
|
|
|
|
# physicaldrive 1:1 (port 1:id 1 , Parallel SCSI, 36.4 GB, OK)
|
|
|
|
#
|
|
|
|
# RAID WARNING - HP Smart Array Rebuilding: Smart Array 6i in Slot 0 (Embedded) \
|
|
|
|
# array A logicaldrive 1 (33.9 GB, RAID 1, Recovering, 26% complete) \
|
|
|
|
# physicaldrive 1:0 (port 1:id 0 , Parallel SCSI, 36.4 GB, Rebuilding) \
|
|
|
|
# physicaldrive 1:1 (port 1:id 1 , Parallel SCSI, 36.4 GB, OK)
|
|
|
|
#
|
2020-06-16 03:53:00 +02:00
|
|
|
# ./check_hpraid -v -b
|
2020-05-28 06:01:50 +02:00
|
|
|
# ----------------
|
|
|
|
#
|
|
|
|
# RAID OK: Smart Array 6i in Slot 0 (Embedded) array A logicaldrive 1 (33.9 GB, RAID 1, OK) [Controller Status: OK]
|
|
|
|
#
|
|
|
|
# [insted of]
|
|
|
|
# RAID CRITICAL - HP Smart Array Failed: Smart Array 6i in Slot 0 (Embedded) \
|
|
|
|
# Controller Status: OK Cache Status: Temporarily Disabled \
|
|
|
|
# Battery/Capacitor Status: Failed (Replace Batteries/Capacitors)
|
|
|
|
|
2020-05-28 09:35:11 +02:00
|
|
|
PROGNAME=$(basename "$0")
|
2020-05-29 02:43:15 +02:00
|
|
|
NAGIOS_PLUGINS="/usr/lib/nagios/plugins"
|
2020-05-28 09:35:11 +02:00
|
|
|
REVISION="0.16-evolix"
|
2020-05-28 06:01:50 +02:00
|
|
|
DEBUG="0"
|
|
|
|
VERBOSE="0"
|
|
|
|
ssacli=$(command -v ssacli)
|
|
|
|
PHYSICAL_DRIVE=0
|
|
|
|
|
2020-05-28 09:35:11 +02:00
|
|
|
# shellcheck source=/dev/null
|
2020-05-28 06:01:50 +02:00
|
|
|
. ${NAGIOS_PLUGINS}/utils.sh
|
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
echo ""
|
|
|
|
echo "Usage: $PROGNAME [-v] [-p] [-e <number>] [-E <name>] [-b] [-s] [-d]"
|
|
|
|
echo "Usage: $PROGNAME [-h]"
|
|
|
|
echo "Usage: $PROGNAME [-V]"
|
|
|
|
echo ""
|
|
|
|
echo " -v = show status and informations about RAID"
|
|
|
|
echo " -p = show detail for physical drives"
|
|
|
|
echo " -e <number> = exclude slot number"
|
|
|
|
echo " -b = exclude battery/capacitor/cache status check"
|
|
|
|
echo " -d = use for debug (command line mode)"
|
|
|
|
echo " -h = help information"
|
|
|
|
echo " -V = version information"
|
|
|
|
echo ""
|
|
|
|
echo " ============="
|
|
|
|
}
|
|
|
|
|
|
|
|
print_help() {
|
2020-05-28 09:35:11 +02:00
|
|
|
print_revision "$PROGNAME" "$REVISION"
|
2020-05-28 06:01:50 +02:00
|
|
|
echo ""
|
|
|
|
print_usage
|
|
|
|
echo ""
|
|
|
|
echo "This plugin checks hardware status for Smart Array Controllers,"
|
|
|
|
echo "using HPE Smart Storage Administrator."
|
|
|
|
echo ""
|
|
|
|
support
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts "N:cvpbsde:Vh" options
|
|
|
|
do
|
|
|
|
case $options in
|
|
|
|
N) ;;
|
|
|
|
c) ;;
|
|
|
|
v) VERBOSE=1;;
|
|
|
|
p) PHYSICAL_DRIVE=1;;
|
|
|
|
d) DEBUG=1;;
|
|
|
|
e) EXCLUDE_SLOT=1
|
|
|
|
excludeslot="$OPTARG";;
|
|
|
|
b) EXCLUDE_BATTERY=1;;
|
2020-05-28 09:35:11 +02:00
|
|
|
V) print_revision "$PROGNAME" "$REVISION"
|
2020-05-28 06:01:50 +02:00
|
|
|
exit 0;;
|
|
|
|
h) print_help
|
|
|
|
exit 0;;
|
|
|
|
\?) print_usage
|
|
|
|
exit 0;;
|
|
|
|
*) print_usage
|
|
|
|
exit 0;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-05-29 02:43:15 +02:00
|
|
|
# Check if smartpqi or hpsa driver is loaded
|
2020-05-28 06:01:50 +02:00
|
|
|
# https://manpages.debian.org/buster/manpages/smartpqi.4.en.html
|
2020-05-29 02:43:15 +02:00
|
|
|
if [ -d /sys/bus/pci/drivers/smartpqi ] || [ -d /sys/bus/pci/drivers/hpsa ]; then
|
2020-05-28 06:01:50 +02:00
|
|
|
driverPresent='YES.'
|
|
|
|
else
|
|
|
|
driverPresent='No!'
|
|
|
|
fi
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
2020-05-29 02:43:15 +02:00
|
|
|
echo "### Check if \"HP Smart Array\" driver is present >>>\n${driverPresent}\n"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
if [[ "$driverPresent" == "No!" ]]; then
|
|
|
|
echo "RAID UNKNOWN - HP Smart Array not found"
|
2020-05-28 09:35:11 +02:00
|
|
|
exit "$STATE_UNKNOWN"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if "HP Array Utility CLI" is present
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
|
|
|
echo "### Check if \"ssacli\" is present >>>\n"
|
|
|
|
fi
|
2020-05-28 09:35:11 +02:00
|
|
|
if [ ! -x "$ssacli" ]; then
|
|
|
|
if [ -x "$ssacli" ]; then
|
2020-05-28 06:01:50 +02:00
|
|
|
if [ "$DEBUG" = "1" ]; then
|
|
|
|
echo "### \"ssacli\" is present >>>\n"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "ERROR: ssacli tools should be installed and with right sudoers/permissions (see the notes above)"
|
2020-05-28 09:35:11 +02:00
|
|
|
exit "$STATE_UNKNOWN"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if "HP Controller" work correctly
|
2020-05-28 09:35:11 +02:00
|
|
|
check=$(sudo -u root "$ssacli" controller all show status 2>&1)
|
2020-05-28 06:01:50 +02:00
|
|
|
status=$?
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "### Check if \"HP Controller\" work correctly >>>\n""${check}""\n"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
if test ${status} -ne 0; then
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "RAID UNKNOWN - $ssacli did not execute properly : ""${check}"
|
|
|
|
exit "$STATE_UNKNOWN"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Get "Slot" & exclude slot needed
|
|
|
|
EXCLUDE_SLOT=${EXCLUDE_SLOT:-0}
|
|
|
|
if [ "$EXCLUDE_SLOT" = "1" ]; then
|
2020-05-28 09:35:11 +02:00
|
|
|
slots=$(grep -E -o "Slot \w" <<< "$check" | awk '{print $NF}' | grep -v "$excludeslot")
|
2020-05-28 06:01:50 +02:00
|
|
|
else
|
2020-05-28 09:35:11 +02:00
|
|
|
slots=$(grep -E -o "Slot \w" <<< "$check" | awk '{print $NF}')
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "### Get \"Slot\" & exclude slot not needed >>>\n""${slots}""\n"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
2020-05-28 09:35:11 +02:00
|
|
|
|
2020-05-28 06:01:50 +02:00
|
|
|
for slot in $slots; do
|
|
|
|
# Get "logicaldrive" for slot
|
2020-05-29 02:43:15 +02:00
|
|
|
set +e
|
2020-05-28 09:35:11 +02:00
|
|
|
check2b=$(sudo -u root "$ssacli" controller slot="$slot" logicaldrive all show 2>&1)
|
2020-05-28 06:01:50 +02:00
|
|
|
status=$?
|
|
|
|
if test ${status} -ne 0; then
|
2020-05-29 02:43:15 +02:00
|
|
|
# Skip empty slots
|
|
|
|
if grep -q "The specified device does not have any logical drives." <<< "$check2b"; then
|
|
|
|
break
|
|
|
|
fi
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "RAID UNKNOWN - $ssacli did not execute properly : ""${check2b}"
|
|
|
|
exit "$STATE_UNKNOWN"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
2020-05-29 02:43:15 +02:00
|
|
|
set -e
|
2020-05-28 06:01:50 +02:00
|
|
|
check2=${check2:-}
|
|
|
|
check2="$check2$check2b"
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "### Get \"logicaldrive\" for slot >>>\n""${check2b}""\n"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Get "physicaldrive" for slot
|
2020-05-28 09:35:11 +02:00
|
|
|
if [ "$PHYSICAL_DRIVE" = "1" ] || [ "$DEBUG" = "1" ]; then
|
|
|
|
check2b=$(sudo -u root "$ssacli" controller slot="$slot" physicaldrive all show | sed -e 's/\?/\-/g' 2>&1 | grep "physicaldrive")
|
2020-05-28 06:01:50 +02:00
|
|
|
else
|
2020-05-28 09:35:11 +02:00
|
|
|
check2b=$(sudo -u root "$ssacli" controller slot="$slot" physicaldrive all show | sed -e 's/\?/\-/g' 2>&1 | grep "physicaldrive" | (grep "\(Failure\|Failed\|Rebuilding\)" || true))
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
status=$?
|
2020-05-28 09:35:11 +02:00
|
|
|
if [ "$PHYSICAL_DRIVE" = "1" ] || [ "$DEBUG" = "1" ]; then
|
2020-05-28 06:01:50 +02:00
|
|
|
if test ${status} -ne 0; then
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "RAID UNKNOWN - $ssacli did not execute properly : ""${check2b}"
|
|
|
|
exit "$STATE_UNKNOWN"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
check2="$check2$check2b"
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
2020-05-28 09:35:11 +02:00
|
|
|
echo "### Get \"physicaldrive\" for slot >>>\n""${check2b}""\n"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Check STATUS
|
|
|
|
if [ "$DEBUG" = "1" ]; then
|
|
|
|
echo "### Check STATUS >>>"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Omit battery/capacitor/cache status check if requested
|
|
|
|
EXCLUDE_BATTERY=${EXCLUDE_BATTERY:-0}
|
|
|
|
if [ "$EXCLUDE_BATTERY" = "1" ]; then
|
2020-06-16 03:57:18 +02:00
|
|
|
check=$(grep -v 'Battery/Capacitor Status: Failed (Replace Batteries/Capacitors)' <<< "$check")
|
|
|
|
check=$(grep -v 'Cache Status: Temporarily Disabled' <<< "$check")
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
|
2020-06-16 03:36:24 +02:00
|
|
|
check=${check:-}
|
|
|
|
check2=${check2:-}
|
|
|
|
check3=${check3:-}
|
2020-05-28 09:35:11 +02:00
|
|
|
if grep -qiE Failed <<< "$check"; then
|
|
|
|
echo "RAID CRITICAL - HP Smart Array Failed: ${check}"
|
|
|
|
exit "$STATE_CRITICAL"
|
|
|
|
elif grep -qiE Disabled <<< "$check"; then
|
|
|
|
echo "RAID CRITICAL - HP Smart Array Problem: ${check}"
|
|
|
|
exit "$STATE_CRITICAL"
|
|
|
|
elif grep -qiE Failed <<< "$check2"; then
|
|
|
|
echo "RAID CRITICAL - HP Smart Array Failed: ${check2}"
|
|
|
|
exit "$STATE_CRITICAL"
|
|
|
|
elif grep -qiE Failure <<< "$check2"; then
|
|
|
|
echo "RAID WARNING - Component Failure: ${check2}"
|
|
|
|
exit "$STATE_WARNING"
|
|
|
|
elif grep -qiE Rebuild <<< "$check2"; then
|
|
|
|
echo "RAID WARNING - HP Smart Array Rebuilding: ${check2}"
|
|
|
|
exit "$STATE_WARNING"
|
|
|
|
elif grep -qiE Recover <<< "$check2"; then
|
|
|
|
echo "RAID WARNING - HP Smart Array Recovering: ${check2}"
|
|
|
|
exit "$STATE_WARNING"
|
|
|
|
elif grep -qiE "Cache Status: Temporarily Disabled" <<< "$check"; then
|
|
|
|
echo "RAID WARNING - HP Smart Array Cache Disabled: ${check}"
|
|
|
|
exit "$STATE_WARNING"
|
|
|
|
elif grep -qiE FIRMWARE <<< "$check"; then
|
|
|
|
echo "RAID WARNING - ${check}"
|
|
|
|
exit "$STATE_WARNING"
|
2020-05-28 06:01:50 +02:00
|
|
|
else
|
2020-05-28 09:35:11 +02:00
|
|
|
if [ "$DEBUG" = "1" ] || [ "$VERBOSE" = "1" ]; then
|
|
|
|
check3=$(grep -E Status <<< "$check")
|
|
|
|
echo "RAID OK: ${check2} [${check3}]"
|
2020-05-28 06:01:50 +02:00
|
|
|
else
|
|
|
|
echo "RAID OK"
|
|
|
|
fi
|
2020-05-28 09:35:11 +02:00
|
|
|
exit "$STATE_OK"
|
2020-05-28 06:01:50 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-28 09:35:11 +02:00
|
|
|
exit "$STATE_UNKNOWN"
|