Extract magic strings into named constants
Define pattern constants at the top of the script for: - VIRTUAL_IFACE_PATTERN: virtual/firewall interface patterns - STORAGE_CONTROLLER_PATTERN: HBA/storage controller detection - DISK_DEVICE_PATTERN: disk device name patterns - EXCLUDED_PCI_PATTERN: PCI devices to exclude from listing This improves maintainability and makes patterns easier to modify. #12 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
26
proxDoc.sh
26
proxDoc.sh
@@ -7,6 +7,18 @@ VERSION="1.1.0"
|
|||||||
###################
|
###################
|
||||||
readonly CMD_TIMEOUT=30 # Default timeout in seconds for external commands
|
readonly CMD_TIMEOUT=30 # Default timeout in seconds for external commands
|
||||||
|
|
||||||
|
###################
|
||||||
|
# Pattern Constants
|
||||||
|
###################
|
||||||
|
# Virtual/firewall interface patterns to skip
|
||||||
|
readonly VIRTUAL_IFACE_PATTERN="^(veth|fwbr|fwln|fwpr|tap)"
|
||||||
|
# Storage controller patterns for HBA detection
|
||||||
|
readonly STORAGE_CONTROLLER_PATTERN="RAID|SAS|SATA|SCSI|Mass storage|Serial Attached|Fibre Channel|NVMe"
|
||||||
|
# Disk device patterns
|
||||||
|
readonly DISK_DEVICE_PATTERN="^sd|^nvme"
|
||||||
|
# PCI devices to exclude from hardware info
|
||||||
|
readonly EXCLUDED_PCI_PATTERN="Host bridge|PCI bridge|ISA bridge|SMBus|IOMMU|Dummy|USB controller|Audio device|Encryption controller|Multimedia controller"
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# Color Definitions
|
# Color Definitions
|
||||||
###################
|
###################
|
||||||
@@ -113,7 +125,7 @@ get_disk_health() {
|
|||||||
if ! timeout $CMD_TIMEOUT smartctl -H "/dev/$disk"; then
|
if ! timeout $CMD_TIMEOUT smartctl -H "/dev/$disk"; then
|
||||||
log_message warn "smartctl timed out or failed for /dev/$disk"
|
log_message warn "smartctl timed out or failed for /dev/$disk"
|
||||||
fi
|
fi
|
||||||
done < <(lsblk -d -o name | grep -E '^sd|^nvme')
|
done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN")
|
||||||
else
|
else
|
||||||
log_message warn "smartctl not found. Install smartmontools for disk health monitoring"
|
log_message warn "smartctl not found. Install smartmontools for disk health monitoring"
|
||||||
fi
|
fi
|
||||||
@@ -181,7 +193,7 @@ get_hardware_info() {
|
|||||||
echo -e "${GREEN}BIOS Version:${NC} $(dmidecode -s bios-version)"
|
echo -e "${GREEN}BIOS Version:${NC} $(dmidecode -s bios-version)"
|
||||||
echo -e "\n${GREEN}=== PCI Devices ===${NC}"
|
echo -e "\n${GREEN}=== PCI Devices ===${NC}"
|
||||||
# Show interesting devices, exclude bridges, infrastructure, and integrated motherboard devices
|
# Show interesting devices, exclude bridges, infrastructure, and integrated motherboard devices
|
||||||
lspci | grep -v -E "Host bridge|PCI bridge|ISA bridge|SMBus|IOMMU|Dummy|USB controller|Audio device|Encryption controller|Multimedia controller"
|
lspci | grep -v -E "$EXCLUDED_PCI_PATTERN"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_motherboard_info() {
|
get_motherboard_info() {
|
||||||
@@ -358,7 +370,7 @@ get_physical_interfaces() {
|
|||||||
[[ "$iface" == "lo" ]] && continue
|
[[ "$iface" == "lo" ]] && continue
|
||||||
|
|
||||||
# Skip virtual/firewall interfaces
|
# Skip virtual/firewall interfaces
|
||||||
[[ "$iface" =~ ^(veth|fwbr|fwln|fwpr|tap) ]] && continue
|
[[ "$iface" =~ $VIRTUAL_IFACE_PATTERN ]] && continue
|
||||||
|
|
||||||
# This is a physical interface
|
# This is a physical interface
|
||||||
echo "$iface"
|
echo "$iface"
|
||||||
@@ -369,9 +381,9 @@ get_hba_info() {
|
|||||||
echo -e "\n${GREEN}=== HBA/Storage Controller Information ===${NC}"
|
echo -e "\n${GREEN}=== HBA/Storage Controller Information ===${NC}"
|
||||||
|
|
||||||
# Find RAID, SAS, SATA, SCSI, and storage controllers
|
# Find RAID, SAS, SATA, SCSI, and storage controllers
|
||||||
lspci -vmm 2>/dev/null | awk '
|
lspci -vmm 2>/dev/null | awk -v pattern="$STORAGE_CONTROLLER_PATTERN" '
|
||||||
BEGIN { RS=""; FS="\n" }
|
BEGIN { RS=""; FS="\n" }
|
||||||
/RAID|SAS|SATA|SCSI|Mass storage|Serial Attached|Fibre Channel|NVMe/ {
|
$0 ~ pattern {
|
||||||
for (i=1; i<=NF; i++) {
|
for (i=1; i<=NF; i++) {
|
||||||
if ($i ~ /^Slot:/) slot = substr($i, 7)
|
if ($i ~ /^Slot:/) slot = substr($i, 7)
|
||||||
if ($i ~ /^Class:/) class = substr($i, 8)
|
if ($i ~ /^Class:/) class = substr($i, 8)
|
||||||
@@ -390,7 +402,7 @@ get_hba_info() {
|
|||||||
|
|
||||||
# Show detailed info for storage controllers
|
# Show detailed info for storage controllers
|
||||||
echo -e "\n${GREEN}=== Storage Controller Details ===${NC}"
|
echo -e "\n${GREEN}=== Storage Controller Details ===${NC}"
|
||||||
for ctrl in $(lspci | grep -iE "RAID|SAS|SATA|SCSI|Mass storage|NVMe" | awk '{print $1}'); do
|
for ctrl in $(lspci | grep -iE "$STORAGE_CONTROLLER_PATTERN" | awk '{print $1}'); do
|
||||||
echo -e "\n${GREEN}Controller $ctrl:${NC}"
|
echo -e "\n${GREEN}Controller $ctrl:${NC}"
|
||||||
lspci -vvs "$ctrl" 2>/dev/null | grep -E "^\s+(Subsystem|LnkSta|Kernel driver)" | head -5
|
lspci -vvs "$ctrl" 2>/dev/null | grep -E "^\s+(Subsystem|LnkSta|Kernel driver)" | head -5
|
||||||
done
|
done
|
||||||
@@ -541,7 +553,7 @@ quick_health_check() {
|
|||||||
else
|
else
|
||||||
echo -e "/dev/$disk: ${YELLOW}check timed out or unavailable${NC}"
|
echo -e "/dev/$disk: ${YELLOW}check timed out or unavailable${NC}"
|
||||||
fi
|
fi
|
||||||
done < <(lsblk -d -o name | grep -E '^sd|^nvme')
|
done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Node Exporter
|
# Node Exporter
|
||||||
|
|||||||
Reference in New Issue
Block a user