#!/usr/bin/env bash # #SMARTEST - Proxmox SMART Monitoring for PRTG | v2.0 Mar 2025 # channel_id="2" output="/home/monitoring/prtgout.xml" log="/home/monitoring/prtg_smartest.log" active_disks="/home/monitoring/active_disks.txt" excluded_disks="/home/monitoring/excluded_disks.txt" disk_count_real="$(lsblk -d | tail -n +2 | wc -l)" disk_count_current="$(cat "$active_disks" | wc -l)" if [ ! -f "$active_disks" ] || [ ! -s "$active_disks" ]; then lsblk -d | awk '{print $1}' | tail -n +2 > "$active_disks" elif [ "$disk_count_real" -gt "$disk_count_current" ]; then lsblk -d | awk '{print $1}' | tail -n +2 > "$active_disks" echo "Disk(s) added" >> "$log" 2>&1 else echo "" > "$output" for disk in $(cat "$active_disks") do if grep "$disk" "$excluded_disks" >> "$log" 2>&1; then echo "$disk is excluded" >> "$log" 2>&1 elif [[ "$disk" == zd* ]]; then echo "$disk is a ZFS device node, excluding" >> "$log" 2>&1 elif [[ "$disk" == rbd* ]]; then echo "$disk is a Ceph device node, excluding" >> "$log" 2>&1 else smartresult=$(/usr/sbin/smartctl -a /dev/"$disk") if grep -E "OK|PASSED" <<< "$smartresult" >> "$log" 2>&1; then echo "$disk is okay" >> "$log" echo -e "\nchannel_$channel_id\n$disk SMART Status\n1\n0.5\nCustom\n\n1\n" >> "$output" channel_id=$((channel_id + 1)) if grep -i "Wear_Leveling_Count" <<< "$smartresult" >> "$log" 2>&1; then wlcresult=$(/usr/sbin/smartctl -a /dev/"$disk" | grep -i Wear_Leveling_Count | awk '{print $4}' | sed 's/^0*//') echo "$disk: $wlcresult% Lifetime remaining" >> "$log" 2>&1 echo -e "\nchannel_$channel_id\n$disk WLC Lifetime\n1\n25\n10\nCustom\n%\n$wlcresult\n" >> "$output" channel_id=$((channel_id + 1)) else echo "$disk: No WLC available" >> "$log" 2>&1 fi else echo "$disk: SMART failed" >> "$log" 2>&1 echo -e "\nchannel_$channel_id\n$disk SMART Status\n1\n0.5\nCustom\n\n0\n" >> "$output" fi fi done fi echo "" >> "$output" # EOF