diff --git a/packages/unraid-snmp-2023.02.19-x86_64-1.txz b/packages/unraid-snmp-2023.02.19-x86_64-1.txz new file mode 100644 index 0000000..a34dbca Binary files /dev/null and b/packages/unraid-snmp-2023.02.19-x86_64-1.txz differ diff --git a/snmp.plg b/snmp.plg index 5ed3541..f122b5a 100644 --- a/snmp.plg +++ b/snmp.plg @@ -5,7 +5,7 @@ - + @@ -26,7 +26,7 @@ - + ]> ## SNMP +### 2023.02.19 +- Adjusted CPU MHz script to more succinctly retrieve data +- Adjusted plugin PLG install script to read the `rocommunity` string from the `/etc/snmp/snmpd.conf` SNMP daemon config file when testing install success/failure. Thanks @cjhammel for the suggestion! + ### 2023.02.18 - Adjusted CPU MHz script to source from `/proc/cpuinfo` instead of `lscpu` to improve compatibility. Thanks @mattie112 @MVLP @irishjd for the help! @@ -185,7 +189,7 @@ # NOTE: Modified bash for embedding in XML with ampersand-semicolon placeholders # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ -# exit script early if we encounter an error +# Exit script early if we encounter an error set -e echo "" @@ -194,8 +198,21 @@ echo "| Testing SNMP by listing mounts, /boot should be present" echo "+==============================================================================" echo "" -printf "snmpwalk -v 2c localhost -c public hrFSMountPoint\n" -results=$(snmpwalk -v 2c localhost -c public hrFSMountPoint 2>&1) || printf "snmpwalk failure" +# Get the Read-Only Community string from the config file +community=$(grep "rocommunity" --max-count 1 "/etc/snmp/snmpd.conf" | awk '{print $2}') +# Clean newlines, carriage returns, spaces, and tabs +community=${community//[$'\t\r\n ']} + +# If the Community cannot be read, default to "public" +if [[ -z "$community" ]] +then + echo "Read-Only Community String not found in /etc/snmp/snmpd.conf. Defaulting to test with public." + community="public" +fi + +# Print out the command used to test SNMP functionality, and then run/evaluate the command +printf "snmpwalk -v 2c localhost -c $community hrFSMountPoint\n" +results=$(snmpwalk -v 2c localhost -c $community hrFSMountPoint 2>&1) || printf "snmpwalk failure" if [[ "$results" =~ "/boot" ]] then echo "SNMP appears to be working. Output:" @@ -213,12 +230,12 @@ echo "+========================================================================= echo "" printf "Here are how sharefree lines look:\n" -printf "snmpwalk -v 2c -c public localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine.\"sharefree\"'\n" -snmpwalk -v 2c -c public localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."sharefree"' +printf "snmpwalk -v 2c -c $community localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine.\"sharefree\"'\n" +snmpwalk -v 2c -c $community localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."sharefree"' printf "\nHere are how all custom extensions look:\n" -printf "snmpwalk -v 2c -c public localhost nsExtendOutLine\n" -snmpwalk -v 2c -c public localhost nsExtendOutLine +printf "snmpwalk -v 2c -c $community localhost nsExtendOutLine\n" +snmpwalk -v 2c -c $community localhost nsExtendOutLine echo "" @@ -238,7 +255,7 @@ exit 0 # NOTE: Modified bash for embedding in XML with ampersand-semicolon placeholders # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ -# exit script early if we encounter an error +# Exit script early if we encounter an error set -e echo "" @@ -272,13 +289,13 @@ echo "Starting TXZ package removal" # Read through package removal lines, uninstalling each while IFS= read -r line do - # if line is empty, skip to the next iteration + # If line is empty, skip to the next iteration [ -z "$line" ] && continue - # remove the directory path and extension, leaving just the package name + # Remove the directory path and extension, leaving just the package name pkg_name="$(basename $line .txz)" - # perform the package removal + # Perform the package removal removepkg "$pkg_name" done < <(printf '%s\n' "$pkgs_to_remove") @@ -287,7 +304,7 @@ printf "\nTXZ package removal done. Starting directory and file removal\n" # Read through package removal lines, uninstalling each while IFS= read -r line do - # if line is empty, skip to the next iteration + # If line is empty, skip to the next iteration [ -z "$line" ] && continue echo "Deleting $line" diff --git a/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh b/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh index a62f878..503a8fe 100755 --- a/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh +++ b/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh @@ -6,10 +6,10 @@ # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ set -euo pipefail -# Print out /proc/cpuinfo, find the first line with the +# Find the first line in /proc/cpuinfo with the # MHz (it repeats for each installed processor), and grab the number to store as a variable # Relevant cpuinfo output: cpu MHz : 4199.992 -cpuinfo_mhz=$(cat /proc/cpuinfo | grep "cpu MHz" --max-count 1 | awk '{print $4}') +cpuinfo_mhz=$(grep "cpu MHz" --max-count 1 /proc/cpuinfo | awk '{print $4}') # Exit if MHz is empty or non-numeric, otherwise print and exit # https://www.geekpills.com/operating-system/linux/bash-check-integer-or-float