#!/bin/bash # Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2 # This file is part of Checkmk (https://checkmk.com). It is subject to the terms and # conditions defined in the file COPYING, which is part of this source code package. # Reason for this no-op: shellcheck disable=... before the first command disables the error for the # entire script. : # Disable unused variable error (needed to keep track of version) # shellcheck disable=SC2034 CMK_VERSION="2.5.0p19" # Function to replace "if type [somecmd]" idiom # 'command -v' tends to be more robust vs 'which' and 'type' based tests inpath() { command -v "${1:?No command to test}" >/dev/null 2>&1 } # This will be called on LSI based raidcontrollers and accesses # the SMART data of SATA disks attached to a SAS Raid HBA via # SCSI protocol interface. megaraid_info() { #PDINFO=$(MegaCli -PDlist -a0) if [ -z "$1" ]; then PDINFO=$(megacli -PDlist -a0 -NoLog) else PDINFO=$($1 -PDlist -a0 -NoLog) fi echo "$PDINFO" | while read -r line; do case "$line" in # FIRST LINE "Enclosure Device ID"*) #Enclosure Device ID: 252 ENC=$(echo "$line" | awk '{print $4}') unset SLOT LOG_DEV_ID VEND MODEL ;; "Slot Number"*) #Slot Number: 7 SLOT=$(echo "$line" | awk '{print $3}') ;; # Identify the logical device ID. smartctl needs it to access the disk. "Device Id"*) #Device Id: 19 LOG_DEV_ID=$(echo "$line" | awk '{print $3}') ;; "PD Type"*) #PD Type: SATA VEND=$(echo "$line" | awk '{print $3}') ;; # This is the last value, generate output here "Inquiry Data"*) #Inquiry Data: WD-WCC1T1035197WDC WD20EZRX-00DC0B0 80.00A80 # $4 seems to be better for some vendors... wont be possible to get this perfect. MODEL=$(echo "$line" | awk '{print $3}') # /dev/sdc ATA SAMSUNG_SSD_830 5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - smartctl -d megaraid,"${LOG_DEV_ID}" -v 9,raw48 -A /dev/sg0 | grep Always | grep -v -E '^190(.*)Temperature(.*)' | sed "s|^|Enc${ENC}/Slot${SLOT} $VEND $MODEL |" ;; esac done } # Only handle always updated values, add device path and vendor/model if inpath smartctl >/dev/null 2>&1; then # # if the 3ware-utility is found # get the serials for all disks on the controller # if inpath tw_cli >/dev/null 2>&1; then # support for only one controller at the moment TWAC=$(tw_cli show | awk 'NR < 4 { next } { print $1 }' | head -n 1) # - add a trailing zero to handle case of unused slot # trailing zeros are part of the device links in /dev/disk/by-id/... anyway # - only the last 9 chars seem to be relevant # (hopefully all this doesn't change with new kernels...) eval "$(tw_cli /"$TWAC" show drivestatus | grep -E '^p[0-9]' | awk '{print $1 " " $7 "0"}' | while read -r twaminor serial; do twaminor=${twaminor#p} serial=${serial:(-9)} serial=AMCC_${serial}00000000000 echo "$serial=$twaminor" done)" else echo "tw_cli not found" >&2 fi INPATH_UDEVADM=$(inpath udevadm && echo "udevadm_present") echo '<<>>' SEEN= # don't use brace expansion here to stay POSIX conform for D in /dev/disk/by-id/scsi-* /dev/disk/by-id/ata-* /dev/disk/by-id/nvme-*; do [ "$D" != "${D%scsi-\*}" ] && continue [ "$D" != "${D%ata-\*}" ] && continue [ "$D" != "${D%nvme-\*}" ] && continue [ "$D" != "${D%-part*}" ] && continue N=$(readlink "$D") N=${N##*/} if [ -r /sys/block/"$N"/device/vendor ]; then VEND=$(tr -d ' ' /dev/null # Call MegaRaid submodule if conditions are met if type MegaCli >/dev/null 2>&1; then MegaCli_bin="MegaCli" elif type MegaCli64 >/dev/null 2>&1; then MegaCli_bin="MegaCli64" elif type megacli >/dev/null 2>&1; then MegaCli_bin="megacli" else MegaCli_bin="unknown" fi if [ "$MegaCli_bin" != "unknown" ]; then megaraid_info "$MegaCli_bin" fi else echo "ERROR: smartctl not found" >&2 fi