diff --git a/packages/unraid-snmp-2023.04.20-x86_64-1.txz b/packages/unraid-snmp-2023.04.20-x86_64-1.txz new file mode 100644 index 0000000..45d05d2 Binary files /dev/null and b/packages/unraid-snmp-2023.04.20-x86_64-1.txz differ diff --git a/snmp.plg b/snmp.plg index f122b5a..b771590 100644 --- a/snmp.plg +++ b/snmp.plg @@ -5,7 +5,7 @@ - + @@ -26,7 +26,7 @@ - + ]> ## SNMP +### 2023.04.20 +- Fixed a regression in unraid-snmp that prevented the `/etc/rc.d/rc.snmpd` file from being updated correctly. + - This regression caused extra logs in `/var/log/snmpd.log` + - This regression is caused by the update from `net-snmp-5.9` to `net-snmp-5.9.3` + - NOTE: `ps -ef | grep snmp` can be used to confirm the flags were set correctly. They should be `/usr/sbin/snmpd -A -p /var/run/snmpd -LF 0-5 /var/log/snmpd.log -c /etc/snmp/snmpd.conf` + - Thanks @irishjd and @Uncore for the help! + ### 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! @@ -189,7 +196,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 an error is encountered set -e echo "" @@ -201,6 +208,7 @@ echo "" # 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 +# https://stackoverflow.com/questions/19345872/how-to-remove-a-newline-from-a-string-in-bash community=${community//[$'\t\r\n ']} # If the Community cannot be read, default to "public" @@ -255,7 +263,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 an error is encountered set -e echo "" @@ -283,6 +291,7 @@ dirs_files_to_remove=" /etc/snmp/ /var/lib/net-snmp/ /var/log/snmpd.log +/etc/default/snmpd " echo "Starting TXZ package removal" diff --git a/source/install/doinst.sh b/source/install/doinst.sh index 42d31bc..97aaac9 100755 --- a/source/install/doinst.sh +++ b/source/install/doinst.sh @@ -52,34 +52,24 @@ if [[ -f /etc/rc.d/rc.snmpd ]]; then fi - # Define the additional flags we want to add into the SNMP daemon startup - # Spaces at end of string to separate from other flags + echo "Writing extra SNMPD_OPTIONS into /etc/default/snmpd to configure logging" + # Define the additional flags to be added into the SNMP daemon startup # 1=a=alert, 2=c=crit, 3=e=err, 4=w=warn, 5=n=notice, 6=i=info, 7=d=debug - new_flags="-LF 0-5 /var/log/snmpd.log " + # Write these flags into /etc/default/snmpd. As of SNMP 5.9.3, this file + # is sourced and merged with the default flags inside /etc/rc.d/rc.snmpd upon startup. + # -A appends rather than truncates the log file + # -p /var/run/snmpd creates a PID file, used later on to determine if it's running + # https://tldp.org/LDP/abs/html/internal.html#SOURCEREF + # https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash + echo 'SNMPD_OPTIONS="-A -p /var/run/snmpd -LF 0-5 /var/log/snmpd.log"' > /etc/default/snmpd - # Get existing OPTIONS from file, keeping only what's in double quotes - # https://stackoverflow.com/questions/35636323/extracting-a-string-between-two-quotes-in-bash - options=$(grep "OPTIONS=" /etc/rc.d/rc.snmpd | cut -d'"' -f 2) - # Check that new flags haven't already been added - if [[ $options != *"-L"* ]]; then - # Concatenate the new flags with the old - options=$new_flags$options - echo "Editing SNMP startup options in rc.snmpd to be [$options]" - # Replace the line beginning with OPTIONS= with a custom set - # Use a custom delimiter | to avoid collisions of sed and variable use of / - # Escape the start quote and end quote when we recreate the line - # https://stackoverflow.com/questions/9366816/sed-fails-with-unknown-option-to-s-error - sed --in-place=.bak --expression "s|^OPTIONS=.*|OPTIONS=\"$options\"|" /etc/rc.d/rc.snmpd - else - echo "SNMP logging flag already present in rc.snmpd, skipping modification" - fi - - echo "Restart SNMP daemon now that we've adjusted how rc.snmpd starts it" + echo "Start SNMP daemon back up now that snmpd.conf and /etc/default/snmpd modifications are done" # Make sure error logging is going to STDOUT so it prints in install logs bash /etc/rc.d/rc.snmpd start 2>&1 # Wait for daemon startup to complete by watching for PID file # Send error output of "No such file or directory" to /dev/null + # NOTE: ps -ef | grep snmp can be used to confirm the flags were set correctly count=0 sleep 2 while [[ -z "$(cat /var/run/snmpd 2> /dev/null)" ]]; do diff --git a/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh b/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh index 503a8fe..cbfeb66 100755 --- a/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh +++ b/source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh @@ -26,5 +26,5 @@ else fi fi -# Exit with an error, as we only get here if there was an issue +# Exit with an error, as this can only be reached in the event of an issue exit 1 \ No newline at end of file diff --git a/source/usr/local/emhttp/plugins/snmp/disk_free_space.sh b/source/usr/local/emhttp/plugins/snmp/disk_free_space.sh index ebc70fa..2169b51 100755 --- a/source/usr/local/emhttp/plugins/snmp/disk_free_space.sh +++ b/source/usr/local/emhttp/plugins/snmp/disk_free_space.sh @@ -6,10 +6,10 @@ # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ set -euo pipefail -# Run df with only the columns we want, mount point and available kibibytes +# Run df with only the desired columns, mount point and available kibibytes df_output=$(df --output=target --output=avail) -# Filter the output to only the lines we want, those with /boot or /mnt/disk* or /mnt/cache +# Filter the output to only the desired lines, those with /boot or /mnt/disk* or /mnt/cache # https://phoenixnap.com/kb/grep-multiple-strings filtered_df_lines=$(grep -e '/mnt/disk[0-9]' -e '/mnt/cache' -e '/boot' <<< "$df_output") diff --git a/source/usr/local/emhttp/plugins/snmp/disk_temps.sh b/source/usr/local/emhttp/plugins/snmp/disk_temps.sh index f74d537..3ae907c 100755 --- a/source/usr/local/emhttp/plugins/snmp/disk_temps.sh +++ b/source/usr/local/emhttp/plugins/snmp/disk_temps.sh @@ -28,7 +28,7 @@ mkdir -p "$working_dir" # Check if cache file has been modified in the last five minutes if [[ -n $(find $working_dir -name $cache_file_name -mmin -5) ]] then - # Output to the log file that we used cached values + # Output to the log file that cached values were used in place of fresh values echo "Valid cached values served at $(date)" >> "$cache_log_full_path" # Output the cached information cat "$cache_file_full_path" @@ -39,7 +39,7 @@ fi # Define the function which will poll the disks' state in another PID function update_cache_file { # Attempt to get lock file handle/descriptor 200. - # -n ensures we fail immediately if we can't immediately lock + # -n ensures an immediate exit/failure if a lock can't be immediately acquired if ! flock -n 200 then echo "PID $$ couldn't acquire lock on $cache_lock_full_path at $(date)" @@ -77,7 +77,7 @@ function update_cache_file { if [[ "${UNSAFETEMP:-}" -eq "1" ]] then echo "Disk temp retrieval may wake disks from STANDBY" - # Set the command-modifying var we'll use later to an empty string + # Set the command-modifying var to an empty string. It will be used later # NOTE: WD disks need to be spun up for attributes to show # NOTE: Disks may be forced out of STANDBY to report attributes standby_check="" @@ -86,7 +86,7 @@ function update_cache_file { standby_check="--nocheck standby" fi - # Remove the cache file before we start writing to it + # Remove the cache file before it gets written to rm -f "$cache_file_full_path" # Iterate through each model/address pair @@ -156,7 +156,7 @@ function update_cache_file { } # Call the function defined above. -# >$cache_log_full_path redirects all STDOUT to a file # 2>&1 redirects STDERR (2) into STDOUT (1) # 200>$filename I think executes the function under file handle 200 on the given filename diff --git a/source/usr/local/emhttp/plugins/snmp/share_free_space.sh b/source/usr/local/emhttp/plugins/snmp/share_free_space.sh index c755712..d1c554f 100755 --- a/source/usr/local/emhttp/plugins/snmp/share_free_space.sh +++ b/source/usr/local/emhttp/plugins/snmp/share_free_space.sh @@ -5,7 +5,7 @@ # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ set -euo pipefail -# Define the input file from which we will read Share name and free KB +# Define the input file from which Share name and free KB will be read shares_ini=/var/local/emhttp/shares.ini # Check that the file exists and is non-empty and exit otherwise diff --git a/source/usr/local/emhttp/plugins/snmp/snmp.page b/source/usr/local/emhttp/plugins/snmp/snmp.page index 3b37bdb..8663d1c 100644 --- a/source/usr/local/emhttp/plugins/snmp/snmp.page +++ b/source/usr/local/emhttp/plugins/snmp/snmp.page @@ -81,7 +81,7 @@ Custom snmpd.conf contents: - +