Skip to content

Commit

Permalink
Update plugin from 2023.02.19 to 2023.04.20 to fix a regression intro…
Browse files Browse the repository at this point in the history
…duced in SNMP 5.9.3 causing additional log output
  • Loading branch information
kubedzero committed Apr 20, 2023
1 parent 4c6217c commit 9029531
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
Binary file added packages/unraid-snmp-2023.04.20-x86_64-1.txz
Binary file not shown.
17 changes: 13 additions & 4 deletions snmp.plg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!ENTITY author "kubedzero">
<!ENTITY gitbranch "main">

<!ENTITY pluginver "2023.02.19">
<!ENTITY pluginver "2023.04.20">
<!ENTITY minosver "6.11.0">

<!ENTITY githuburl "https://raw.githubusercontent.com/&author;/unraid-snmp/&gitbranch;">
Expand All @@ -26,7 +26,7 @@
<!ENTITY perlpkgmd5 "311457f731863e98552ea7bebd620d13">

<!ENTITY pluginpkg "unraid-snmp-&pluginver;-x86_64-1.txz">
<!ENTITY pluginpkgmd5 "beea9b6971199717133bf4a2e0a6223a">
<!ENTITY pluginpkgmd5 "27df0bfd67fb265c91047ce083b17a42">
]>

<PLUGIN name="&name;"
Expand All @@ -40,6 +40,13 @@
<CHANGES>
## 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!
Expand Down Expand Up @@ -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 ""
Expand All @@ -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"
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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"
Expand Down
32 changes: 11 additions & 21 deletions source/install/doinst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/usr/local/emhttp/plugins/snmp/cpu_mhz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions source/usr/local/emhttp/plugins/snmp/disk_free_space.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
10 changes: 5 additions & 5 deletions source/usr/local/emhttp/plugins/snmp/disk_temps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)"
Expand Down Expand Up @@ -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=""
Expand All @@ -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
Expand Down Expand Up @@ -156,7 +156,7 @@ function update_cache_file {
}

# Call the function defined above.
# </dev/null provides empty input. I'm not sure why we need this
# </dev/null provides empty input. I'm not sure why this is needed
# >>$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
Expand Down
2 changes: 1 addition & 1 deletion source/usr/local/emhttp/plugins/snmp/share_free_space.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/usr/local/emhttp/plugins/snmp/snmp.page
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Custom snmpd.conf contents:
</form>


<!-- Javascript block where we can define various JS code -->
<!-- Javascript block where various JS code can be defined -->
<!-- Create a function called setDefaults that resets the form values -->
<!-- It finds form values by their ID -->
<script type="text/javascript">
Expand Down

0 comments on commit 9029531

Please sign in to comment.