From 67d4b763246bc817f6968a89cbba0a4f76cb4690 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 10:48:51 -0500 Subject: [PATCH] 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. https://code.lotusguild.org/LotusGuild/proxDoc/issues/12 Co-Authored-By: Claude Opus 4.5 --- proxDoc.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/proxDoc.sh b/proxDoc.sh index e5aba17..c370cd3 100755 --- a/proxDoc.sh +++ b/proxDoc.sh @@ -7,6 +7,18 @@ VERSION="1.1.0" ################### 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 ################### @@ -113,7 +125,7 @@ get_disk_health() { if ! timeout $CMD_TIMEOUT smartctl -H "/dev/$disk"; then log_message warn "smartctl timed out or failed for /dev/$disk" fi - done < <(lsblk -d -o name | grep -E '^sd|^nvme') + done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN") else log_message warn "smartctl not found. Install smartmontools for disk health monitoring" fi @@ -181,7 +193,7 @@ get_hardware_info() { echo -e "${GREEN}BIOS Version:${NC} $(dmidecode -s bios-version)" echo -e "\n${GREEN}=== PCI Devices ===${NC}" # 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() { @@ -358,7 +370,7 @@ get_physical_interfaces() { [[ "$iface" == "lo" ]] && continue # Skip virtual/firewall interfaces - [[ "$iface" =~ ^(veth|fwbr|fwln|fwpr|tap) ]] && continue + [[ "$iface" =~ $VIRTUAL_IFACE_PATTERN ]] && continue # This is a physical interface echo "$iface" @@ -369,9 +381,9 @@ get_hba_info() { echo -e "\n${GREEN}=== HBA/Storage Controller Information ===${NC}" # 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" } - /RAID|SAS|SATA|SCSI|Mass storage|Serial Attached|Fibre Channel|NVMe/ { + $0 ~ pattern { for (i=1; i<=NF; i++) { if ($i ~ /^Slot:/) slot = substr($i, 7) if ($i ~ /^Class:/) class = substr($i, 8) @@ -390,7 +402,7 @@ get_hba_info() { # Show detailed info for storage controllers 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}" lspci -vvs "$ctrl" 2>/dev/null | grep -E "^\s+(Subsystem|LnkSta|Kernel driver)" | head -5 done @@ -541,7 +553,7 @@ quick_health_check() { else echo -e "/dev/$disk: ${YELLOW}check timed out or unavailable${NC}" fi - done < <(lsblk -d -o name | grep -E '^sd|^nvme') + done < <(lsblk -d -o name | grep -E "$DISK_DEVICE_PATTERN") fi # Node Exporter