added smart monitoring
This commit is contained in:
128
driveAtlas.sh
128
driveAtlas.sh
@ -32,23 +32,33 @@ get_drives_info() {
|
||||
done
|
||||
}
|
||||
|
||||
# Get physical slot mapping from system
|
||||
get_physical_mapping() {
|
||||
local -A drive_map
|
||||
|
||||
# Map NVMe drives
|
||||
local nvme_info=$(ls -l /dev/disk/by-path/pci-0000:0d:00.0* 2>/dev/null)
|
||||
for nvme in $(echo "$nvme_info" | awk -F'/' '{print $NF}'); do
|
||||
drive_map[11]=$(get_drive_smart_info "$nvme")
|
||||
done
|
||||
|
||||
# Map SATA hot-swap bays using sg_ses or other tools
|
||||
# Map SATA hot-swap bays
|
||||
local hotswap_info=$(ls -l /dev/disk/by-path/pci-0000:0c:00.0-ata-* 2>/dev/null)
|
||||
for drive in $(echo "$hotswap_info" | awk -F'/' '{print $NF}'); do
|
||||
local bay=$(echo "$drive" | grep -o 'ata-[0-9]' | cut -d- -f2)
|
||||
if [[ -n "$bay" ]]; then
|
||||
drive_map[$bay]=$(get_drive_smart_info "$drive")
|
||||
fi
|
||||
done
|
||||
|
||||
# Map USB devices
|
||||
local usb_info=$(ls -l /dev/disk/by-path/pci-0000:0b:00.0-usb* 2>/dev/null)
|
||||
|
||||
# Use smartctl to get drive details
|
||||
for drive in $(echo "$hotswap_info" | awk -F'/' '{print $NF}'); do
|
||||
local smart_info=$(get_drive_smart_info "$drive")
|
||||
local size=$(get_drive_details "$drive")
|
||||
# Map drive details to physical location
|
||||
local usb_info=$(ls -l /dev/disk/by-path/pci-0000:0b:00.0-usb* 2>/dev/null | awk -F'/' '{print $NF}')
|
||||
local usb_count=1
|
||||
for usb in $(echo "$usb_info"); do
|
||||
drive_map["usb$usb_count"]=$(get_drive_smart_info "$usb")
|
||||
((usb_count++))
|
||||
done
|
||||
|
||||
echo "$(declare -p drive_map)"
|
||||
}
|
||||
|
||||
declare -A DRIVE_MAPPINGS=(
|
||||
@ -59,10 +69,9 @@ declare -A DRIVE_MAPPINGS=(
|
||||
pci-0000:0c:00.0-ata-4:4
|
||||
pci-0000:0d:00.0-nvme-1:11
|
||||
"
|
||||
["large1"]=""
|
||||
["medium1"]=""
|
||||
)
|
||||
|
||||
|
||||
build_drive_map() {
|
||||
local host=$(hostname)
|
||||
local drive_map=()
|
||||
@ -140,45 +149,35 @@ medium1='''
|
||||
'''
|
||||
|
||||
generate_medium2_layout() {
|
||||
# USB Section
|
||||
eval "$(get_physical_mapping)"
|
||||
|
||||
# USB Section with dynamic mapping
|
||||
printf " External USB [0b:00.0]\n"
|
||||
printf " ┌────────┐ ┌────────┐\n"
|
||||
usb_drives=$(ls -l /dev/disk/by-path/pci-0000:0b:00.0-usb* 2>/dev/null | awk -F'/' '{print $NF}')
|
||||
if [ -n "$usb_drives" ]; then
|
||||
read -r drive1 drive2 <<< $(echo "$usb_drives")
|
||||
printf " │ %-6s │ │ %-6s │\n" "${drive1:-EMPTY}" "${drive2:-EMPTY}"
|
||||
fi
|
||||
printf " │ %-6s │ │ %-6s │\n" "${drive_map[usb1]:-EMPTY}" "${drive_map[usb2]:-EMPTY}"
|
||||
printf " └────────┘ └────────┘\n\n"
|
||||
|
||||
# Main chassis
|
||||
|
||||
# Rest of chassis layout with enhanced drive info
|
||||
printf "┌──────────────────────────────────────────────────────────────┐\n"
|
||||
printf "│ B650D4U3-2Q/BCM │\n"
|
||||
printf "│ │\n"
|
||||
printf "│ NVMe [0d:00.0] Bay 11 │\n"
|
||||
printf "│ NVMe [0d:00.0] Bay 11 │\n"
|
||||
printf "│ ┌────────┐ │\n"
|
||||
printf "│ │ %-6s │ │\n" "${drive_map[11]:-nvme0n1}"
|
||||
printf "│ │ %-6s │ │\n" "${drive_map[11]:-EMPTY}"
|
||||
printf "│ └────────┘ │\n"
|
||||
printf "│ │\n"
|
||||
printf "│ Front Hot-swap Bays [0c:00.0] │\n"
|
||||
printf "│ ┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐┌────────┐ │\n"
|
||||
|
||||
# Show slot numbers and drives
|
||||
for bay in {1..10}; do
|
||||
local drive="EMPTY"
|
||||
for mapping in "${drive_map[@]}"; do
|
||||
if [[ $mapping == "$bay:"* ]]; then
|
||||
drive="${mapping#*:}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
printf "│ │%-2d:%-4s │" "$bay" "$drive"
|
||||
printf "│ │%-2d:%-4s │" "$bay" "${drive_map[$bay]:-EMPTY}"
|
||||
done
|
||||
|
||||
printf " │\n"
|
||||
printf "│ └────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘ │\n"
|
||||
printf "└──────────────────────────────────────────────────────────────┘\n"
|
||||
}
|
||||
|
||||
|
||||
microGeneric='''
|
||||
┌─┐ ┌─┐
|
||||
┌└─┘──└─┘┐
|
||||
@ -227,54 +226,35 @@ map_drives_to_layout() {
|
||||
esac
|
||||
}
|
||||
|
||||
#get_drive_details() {
|
||||
# local position=$1
|
||||
# # Get drive info from lsblk and nvme list
|
||||
# local drive_info=$(lsblk -d -o NAME,SIZE,TYPE | grep "disk")
|
||||
# local nvme_info=$(sudo nvme list 2>/dev/null)
|
||||
#
|
||||
# # Map position to drive using DRIVE_PATHS
|
||||
# local drive_path=$(echo "$DRIVE_PATHS" | grep "position$position" || echo "")
|
||||
#
|
||||
# if [ -z "$drive_path" ]; then
|
||||
# echo "[EMPTY]"
|
||||
# return
|
||||
# fi
|
||||
#
|
||||
# local device_name=$(basename $(readlink -f "$drive_path"))
|
||||
# local size=$(echo "$drive_info" | grep "$device_name" | awk '{print $2}')
|
||||
#
|
||||
# echo "$device_name $size"
|
||||
#}
|
||||
|
||||
# Enhanced Drive Information Function
|
||||
|
||||
update_ascii_layout() {
|
||||
local layout="$1"
|
||||
|
||||
for i in {1..9}; do
|
||||
local drive_details=$(get_drive_details $i)
|
||||
if [[ "$drive_details" == "[EMPTY]" ]]; then
|
||||
layout=${layout//│ $i │/│ [EMPTY] │}
|
||||
else
|
||||
layout=${layout//│ $i │/│ $drive_details │}
|
||||
fi
|
||||
done
|
||||
|
||||
# Update NVMe slots in motherboard
|
||||
local nvme1=$(get_drive_details "nvme0")
|
||||
local nvme2=$(get_drive_details "nvme1")
|
||||
layout=${layout//│M1│/│${nvme1:0:3}│}
|
||||
layout=${layout//│M2│/│${nvme2:0:3}│}
|
||||
|
||||
echo "$layout"
|
||||
}
|
||||
|
||||
DRIVE_PATHS=$(get_drives_info | awk '{print $1, $2}')
|
||||
|
||||
# Initialize array for "not found" messages
|
||||
not_found=()
|
||||
|
||||
|
||||
echo -e "\n=== Drive Details with SMART Status ===\n"
|
||||
printf "%-15s %-10s %-8s %-8s %-20s %-30s\n" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
|
||||
# For SATA drives
|
||||
lsblk -d -o NAME | grep -v "nvme" | grep -v "rbd" | while read device; do
|
||||
size=$(get_drive_details "$device")
|
||||
smart_info=$(get_drive_smart_info "$device")
|
||||
IFS='|' read -r type temp health model <<< "$smart_info"
|
||||
printf "%-15s %-10s %-8s %-8s %-20s %-30s\n" "/dev/$device" "$size" "$type" "$temp" "$health" "$model"
|
||||
done
|
||||
|
||||
# For NVMe drives
|
||||
if [ -n "$nvme_drives" ]; then
|
||||
while read -r line; do
|
||||
device=$(echo "$line" | awk '{print $1}' | sed 's/.*\///')
|
||||
size=$(echo "$line" | awk '{print $6}')
|
||||
smart_info=$(get_drive_smart_info "$device")
|
||||
IFS='|' read -r type temp health model <<< "$smart_info"
|
||||
printf "%-15s %-10s %-8s %-8s %-20s %-30s\n" "/dev/$device" "$size" "$type" "$temp" "$health" "$model"
|
||||
done <<< "$nvme_drives"
|
||||
fi
|
||||
|
||||
# Show NVMe Drives only if present
|
||||
nvme_drives=$(sudo nvme list | grep "^/dev")
|
||||
if [ -n "$nvme_drives" ]; then
|
||||
|
||||
Reference in New Issue
Block a user