mirror of
https://github.com/Spearfoot/FreeNAS-scripts
synced 2025-12-10 05:13:53 +00:00
Enhancements for new SAS support
Added counts for the SATA and SAS drive lists and modified the code to gracefully emit either or both types in the report.
This commit is contained in:
146
smart_report.sh
146
smart_report.sh
@@ -10,7 +10,7 @@ smartctl=/usr/local/sbin/smartctl
|
||||
|
||||
freenashost=$(hostname -s | tr '[:lower:]' '[:upper:]')
|
||||
boundary="===== MIME boundary; FreeNAS server ${freenashost} ====="
|
||||
logfile="/tmp/smart_report.tmp"
|
||||
logfile="smart_report.tmp"
|
||||
subject="SMART Status Report for ${freenashost}"
|
||||
tempWarn=40
|
||||
tempCrit=45
|
||||
@@ -18,75 +18,54 @@ sectorsCrit=10
|
||||
testAgeWarn=1
|
||||
warnSymbol="?"
|
||||
critSymbol="!"
|
||||
Drive_count=0
|
||||
SATA_count=0
|
||||
SAS_count=0
|
||||
Drive_list=""
|
||||
SATA_list=""
|
||||
SAS_list=""
|
||||
|
||||
# We need a list of the SMART-enabled drives on the system. Choose one of these
|
||||
# three methods to provide the list. Comment out the two unused sections of code.
|
||||
|
||||
# 1. A string constant; just key in the devices you want to report on here:
|
||||
#drives="/dev/da1 /dev/da2 /dev/da3 /dev/da4 /dev/da5 /dev/da6 /dev/da7 /dev/da8 /dev/ada0"
|
||||
|
||||
# 2. A systcl-based technique suggested on the FreeNAS forum:
|
||||
#drives=$(for drive in $(sysctl -n kern.disks); do \
|
||||
#if [ "$("${"$smartctl"}" -i /dev/${drive} | grep "SMART support is: Enabled" | awk '{print $3}')" ]
|
||||
#then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
|
||||
|
||||
# 3. "$smartctl"-based functions:
|
||||
|
||||
# Get list of SMART-enabled drives
|
||||
get_smart_drives()
|
||||
{
|
||||
gs_smartdrives=""
|
||||
gs_drives=$("$smartctl" --scan | awk '{print $1}')
|
||||
|
||||
for gs_drive in $gs_drives; do
|
||||
gs_smart_flag=$("$smartctl" -i "$gs_drive" | grep -E "SMART support is:[[:blank:]]+Enabled" | awk '{print $4}')
|
||||
if [ "$gs_smart_flag" = "Enabled" ]; then
|
||||
gs_smartdrives="$gs_smartdrives $gs_drive"
|
||||
Drive_list="$Drive_list $gs_drive"
|
||||
Drive_count=$((Drive_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$gs_smartdrives"
|
||||
}
|
||||
|
||||
drives=$(get_smart_drives)
|
||||
|
||||
|
||||
# Checks whether it is a SATA disk
|
||||
# Get list of SATA disks
|
||||
get_sata_drives()
|
||||
{
|
||||
gsata_smartdrives=""
|
||||
|
||||
for drive in $drives; do
|
||||
for drive in $Drive_list; do
|
||||
gsata_smart_flag=$("$smartctl" -i "$drive" | grep -E "SATA Version is:[[:blank:]]" | awk '{print $4}')
|
||||
if [ "$gsata_smart_flag" = "SATA" ]; then
|
||||
gsata_smartdrives="$gsata_smartdrives $drive"
|
||||
SATA_list="$SATA_list $drive"
|
||||
SATA_count=$((SATA_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$gsata_smartdrives"
|
||||
}
|
||||
|
||||
satadrives=$(get_sata_drives)
|
||||
|
||||
|
||||
# Checks whether it is a SAS disk
|
||||
# Get list of SAS disks
|
||||
get_sas_drives()
|
||||
{
|
||||
gsas_smartdrives=""
|
||||
|
||||
for drive in $drives; do
|
||||
for drive in $Drive_list; do
|
||||
gsas_smart_flag=$("$smartctl" -i "$drive" | grep -E "Transport protocol:[[:blank:]]+SAS" | awk '{print $3}')
|
||||
if [ "$gsas_smart_flag" = "SAS" ]; then
|
||||
gsas_smartdrives="$gsas_smartdrives $drive"
|
||||
SAS_list="$SAS_list $drive"
|
||||
SAS_count=$((SAS_count + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$gsas_smartdrives"
|
||||
}
|
||||
|
||||
sasdrives=$(get_sas_drives)
|
||||
|
||||
# end of method 3.
|
||||
|
||||
### Fetch drive lists ###
|
||||
get_smart_drives
|
||||
get_sata_drives
|
||||
get_sas_drives
|
||||
|
||||
### Set email headers ###
|
||||
printf "%s\n" "To: ${email}
|
||||
@@ -100,20 +79,24 @@ Content-Transfer-Encoding: 7bit
|
||||
Content-Disposition: inline
|
||||
<html><head></head><body><pre style=\"font-size:14px; white-space:pre\">" > ${logfile}
|
||||
|
||||
if [ $Drive_count -eq 0 ]; then
|
||||
echo "##### No SMART-enabled disks found on this system #####" >> "$logfile"
|
||||
fi
|
||||
|
||||
###### summary sata ######
|
||||
###### Summary for SATA drives ######
|
||||
if [ $SATA_count -gt 0 ]; then
|
||||
(
|
||||
echo "########## SMART status report summary for all SATA drives on server ${freenashost} ##########"
|
||||
echo ""
|
||||
echo "+------+------------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+--------------+-----+"
|
||||
echo "+------+------------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+----+"
|
||||
echo "|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|Last|"
|
||||
echo "| |Number | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|Test|"
|
||||
echo "| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |Age |"
|
||||
echo "+------+------------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+--------------+-----+"
|
||||
echo "+------+------------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+----+"
|
||||
) >> "$logfile"
|
||||
|
||||
###### for each SATA drive ######
|
||||
for drive in $satadrives; do
|
||||
###### Detail information for each SATA drive ######
|
||||
for drive in $SATA_list; do
|
||||
(
|
||||
devid=$(basename "$drive")
|
||||
lastTestHours=$("$smartctl" -l selftest "$drive" | grep "# 1" | awk '{print $9}')
|
||||
@@ -145,45 +128,39 @@ for drive in $satadrives; do
|
||||
seekErrors="N/A";
|
||||
totalSeeks="N/A";
|
||||
}
|
||||
if (temp > tempWarn || temp > tempCrit)
|
||||
temp=temp"*"
|
||||
else
|
||||
temp=temp" "
|
||||
|
||||
if (reAlloc > 0 || reAlloc > sectorsCrit)
|
||||
reAlloc=reAlloc"*"
|
||||
if (temp > tempWarn || temp > tempCrit) temp=temp"*"
|
||||
|
||||
if (pending > 0 || pending > sectorsCrit)
|
||||
pending=pending"*"
|
||||
if (reAlloc > 0 || reAlloc > sectorsCrit) reAlloc=reAlloc"*"
|
||||
|
||||
if (offlineUnc > 0 || offlineUnc > sectorsCrit)
|
||||
offlineUnc=offlineUnc"*"
|
||||
if (pending > 0 || pending > sectorsCrit) pending=pending"*"
|
||||
|
||||
if (testAge > testAgeWarn)
|
||||
testAge=testAge"*"
|
||||
if (offlineUnc > 0 || offlineUnc > sectorsCrit) offlineUnc=offlineUnc"*"
|
||||
|
||||
if (testAge > testAgeWarn) testAge=testAge"*"
|
||||
|
||||
if (hiFlyWr == "") hiFlyWr="N/A";
|
||||
|
||||
if (cmdTimeout == "") cmdTimeout="N/A";
|
||||
printf "|%-6s|%-24s| %3s|%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%14s|%5s|\n",
|
||||
|
||||
printf "|%-6s|%-24s|%-4s|%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|%4s|\n",
|
||||
device, serial, temp, onHours, startStop, spinRetry, reAlloc, pending, offlineUnc,
|
||||
seekErrors, totalSeeks, hiFlyWr, cmdTimeout, testAge;
|
||||
}'
|
||||
) >> "$logfile"
|
||||
done
|
||||
(
|
||||
echo "+------+------------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+--------------+-----+"
|
||||
echo "+------+------------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+----+"
|
||||
) >> "$logfile"
|
||||
fi
|
||||
|
||||
###### Summary for SAS drives ######
|
||||
if [ $SAS_count -gt 0 ]; then
|
||||
(
|
||||
if [ $SATA_count -gt 0 ]; then
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
) >> "$logfile"
|
||||
fi
|
||||
|
||||
|
||||
###### summary sas ######
|
||||
(
|
||||
echo ""
|
||||
echo "########## SMART status report summary for all SAS drives on server ${freenashost} ##########"
|
||||
echo ""
|
||||
echo "+------+------------------------+----+-----+------+------+------+------+------+------+"
|
||||
@@ -193,8 +170,8 @@ done
|
||||
echo "+------+------------------------+----+-----+------+------+------+------+------+------+"
|
||||
) >> "$logfile"
|
||||
|
||||
###### for each SAS drive ######
|
||||
for drive in $sasdrives; do
|
||||
###### Detail information for each SAS drive ######
|
||||
for drive in $SAS_list; do
|
||||
(
|
||||
devid=$(basename "$drive")
|
||||
"$smartctl" -a "$drive" | \
|
||||
@@ -223,35 +200,38 @@ done
|
||||
(
|
||||
echo "+------+------------------------+----+-----+------+------+------+------+------+------+"
|
||||
) >> "$logfile"
|
||||
|
||||
|
||||
###### for SATA drives ######
|
||||
for drive in $satadrives; do
|
||||
brand=$("$smartctl" -i "$drive" | grep "Model Family" | sed "s/^.* //")
|
||||
if [ -z "$brand" ]; then
|
||||
brand=$("$smartctl" -i "$drive" | grep "Device Model" | sed "s/^.* //")
|
||||
fi
|
||||
serial=$("$smartctl" -i "$drive" | grep "Serial Number" | sed "s/^.* //")
|
||||
|
||||
if [ $SATA_count -gt 0 ] || [ $SAS_count -gt 0 ]; then
|
||||
|
||||
###### Emit SATA drive information ######
|
||||
for drive in $SATA_list; do
|
||||
brand=$("$smartctl" -i "$drive" | grep "Model Family" | awk '{print $3, $4, $5, $6, $7}')
|
||||
if [ -z "$brand" ]; then
|
||||
brand=$("$smartctl" -i "$drive" | grep "Device Model" | awk '{print $3, $4, $5, $6, $7}')
|
||||
fi
|
||||
serial=$("$smartctl" -i "$drive" | grep "Serial Number" | awk '{print $3}')
|
||||
(
|
||||
echo ""
|
||||
echo "########## SMART status report for $drive drive (${brand} : ${serial}) ##########"
|
||||
echo "########## SMART status for SATA drive $drive $serial (${brand}) ##########"
|
||||
"$smartctl" -n never -H -A -l error "$drive"
|
||||
"$smartctl" -n never -l selftest "$drive" | grep "# 1 \\|Num" | cut -c6-
|
||||
) >> "$logfile"
|
||||
done
|
||||
|
||||
###### for SAS drives ######
|
||||
for drive in $sasdrives; do
|
||||
###### Emit SAS drive information ######
|
||||
for drive in $SAS_list; do
|
||||
devid=$(basename "$drive")
|
||||
brand=$("$smartctl" -i "$drive" | grep "Product" | sed "s/^.* //")
|
||||
serial=$("$smartctl" -i "$drive" | grep "Serial number" | sed "s/^.* //")
|
||||
(
|
||||
echo ""
|
||||
echo "########## SMART status report for $drive drive (${brand} : ${serial}) ##########"
|
||||
echo "########## SMART status for SAS drive $drive $serial (${brand}) ##########"
|
||||
"$smartctl" -n never -H -A -l error "$drive"
|
||||
"$smartctl" -n never -l selftest "$drive" | grep "# 1 \\|Num" | cut -c6-
|
||||
) >> "$logfile"
|
||||
done
|
||||
fi
|
||||
|
||||
sed -i '' -e '/smartctl 7.*/d' "$logfile"
|
||||
sed -i '' -e '/smartctl 6.*/d' "$logfile"
|
||||
|
||||
Reference in New Issue
Block a user