Skip to content

Commit

Permalink
Update plugin from 2023.02.18 to 2023.02.19 to optimize CPU MHz readi…
Browse files Browse the repository at this point in the history
…ng and read Community string from config
  • Loading branch information
kubedzero committed Feb 20, 2023
1 parent bd6d9e9 commit 4c6217c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
Binary file added packages/unraid-snmp-2023.02.19-x86_64-1.txz
Binary file not shown.
45 changes: 31 additions & 14 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.18">
<!ENTITY pluginver "2023.02.19">
<!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 "9bab622c5c286b7ab00f02369140034b">
<!ENTITY pluginpkgmd5 "beea9b6971199717133bf4a2e0a6223a">
]>

<PLUGIN name="&name;"
Expand All @@ -40,6 +40,10 @@
<CHANGES>
## 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!

Expand Down Expand Up @@ -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 ""
Expand All @@ -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>&amp;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>&amp;1) || printf "snmpwalk failure"
if [[ "$results" =~ "/boot" ]]
then
echo "SNMP appears to be working. Output:"
Expand All @@ -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 ""
Expand All @@ -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 ""
Expand Down Expand Up @@ -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" ] &amp;&amp; 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 &lt; &lt;(printf '%s\n' "$pkgs_to_remove")

Expand All @@ -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" ] &amp;&amp; continue

echo "Deleting $line"
Expand Down
4 changes: 2 additions & 2 deletions source/usr/local/emhttp/plugins/snmp/cpu_mhz.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

# 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
Expand Down

0 comments on commit 4c6217c

Please sign in to comment.