forked from coppit/unraid-snmp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsnmp.plg
More file actions
342 lines (272 loc) · 12.5 KB
/
Copy pathsnmp.plg
File metadata and controls
342 lines (272 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "snmp">
<!ENTITY author "kubedzero">
<!ENTITY gitbranch "main">
<!ENTITY pluginver "2024.11.01">
<!ENTITY minosver "7.0.0-beta.1">
<!ENTITY githuburl "https://raw.githubusercontent.com/&author;/unraid-snmp/&gitbranch;">
<!ENTITY pluginurl "&githuburl;/snmp.plg">
<!ENTITY pkgurl "&githuburl;/packages">
<!ENTITY supporturl "https://forums.unraid.net/topic/39339-plug-in-snmp">
<!-- Defines the persistent (USB) directory where downloaded packages are cached -->
<!ENTITY usbcfgdir "/boot/config/plugins/&name;/">
<!ENTITY snmppkg "net-snmp-5.9.4-x86_64-5.txz">
<!ENTITY snmppkgmd5 "62f00b8f5612d0dbaba8d77196f5d857">
<!ENTITY libnlpkg "libnl-1.1.4-x86_64-5.txz">
<!ENTITY libnlpkgmd5 "ec5bae2158ff4e5f71c442f91fedfca9">
<!ENTITY perlpkg "perl-5.40.0-x86_64-2.txz">
<!ENTITY perlpkgmd5 "4195279ed3ac9ec49215ab3977cc7eee">
<!ENTITY pluginpkg "unraid-snmp-&pluginver;-x86_64-1.txz">
<!ENTITY pluginpkgmd5 "27df0bfd67fb265c91047ce083b17a42">
]>
<PLUGIN name="&name;"
author="&author;"
version="&pluginver;"
pluginURL="&pluginurl;"
support="&supporturl;"
min="&minosver;"
>
<CHANGES>
## SNMP
### 2024.11.01
- Updated minimum OS version from 6.11.0 to 7.0.0-beta.1 to address SSL library update causing error `libssl.so.1.1: cannot open shared object file: No such file or directory`
- Updated package versions
- `net-snmp-5.9-1` to `net-snmp-5.9.4-5`
- `perl-5.36.0-3` to `perl-5.40.0-2`
### 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!
### 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!
### 2023.02.12
- Adjusted README wording
- Updated package versions
- `libnl-1.1.4-3` to `libnl-1.1.4-5`
- `net-snmp-5.9-1` to `net-snmp-5.9.3-1`
- `perl-5.32.0-1` to `perl-5.36.0-3`
- Updated minimum OS version from 6.7.0 to 6.11.0. Packages `net-snmp` and `perl` now require `libc-2.34` or newer, which is only satisfied starting with Unraid 6.11.0's use of `libc-2.36`. Unraid 6.10.3 uses `libc-2.33` which will yield errors such as `/lib64/libc.so.6: version 'GLIBC_2.34' not found (required by /usr/lib64/perl5/CORE/libperl.so)`
### 2021.05.21
- Added customizable snmpd.conf to the SNMP Settings page. Thanks @Mattie112 for the contribution!
- Users can define a custom SNMP config at `/boot/config/plugins/snmp/snmpd.conf` that will automatically be picked up at boot/install time
- Tweaked the install script to avoid an early exit if the bundled snmpd.conf was missing
- Adjusted PLG uninstall process to properly remove `/etc/rc.d/rc.snmpd*`
- SNMP HDD/CPU/RAM/etc scripts now use `/bin/bash` as `/usr/bin/bash` just symlinks to it anyway
### 2020.12.20
- Add Dirty Memory reporting.
### 2020.11.20
- Repository branch references changed from "master" to "main"
- https://github.com/github/renaming
- Code and functionally identical to version 2020.10.04
### 2020.10.04
- Added `mem_info.sh` to print memory values in bytes
- Exposed in SNMP as `meminfo`
- Current memory values exported are MemTotal, MemFree, MemAvailable, Cached, Active, Inactive, Committed_AS
- Added Settings page to disable `--no-check standby` when getting disk temps
- Used in Unraid setups where disks are always reported to be in Standby
- Used in Unraid setups where disks don't need spinning up to get temperature
- State is stored between reboots in `/boot/config/plugins/snmp/snmp.cfg`
- The script `/usr/local/emhttp/plugins/snmp/disk_temps.sh` reads this config to change behavior
### 2020.09.20
- Bugfix: SMB and NFS permission denied errors after plugin install
- Unused scripts were present in `unraid-snmp-2020.09.19-x86_64-1.txz` and somehow interrupted server access
- Resolved by rebuilding the `.txz` to contain only used files
- Updated `slack-desc` formatting
- PLG tweak: moved forward slash into XML variable for `usbcfgdir`
### 2020.09.19
- Migrate SNMP plugin to .txz style install
- Optimized plugin removal for more complete cleanup
- Updated net-snmp from 5.8-5 to 5.9
- Updated libnl from 1.1.4 to 1.1.4-3
- Perl 5.32.0 declared as dependency instead of separate install.
- Plugin maintainer should keep the version in sync with Nerd Pack to avoid overwriting with an older version
- Install logging more clearly states usage of single and double quotes in sample calls
- Refactored `share_free_space.sh` for added clarity.
- Preexisting behavior: Outputs in bytes
- Refactored `drive_temps.sh`
- Changed name to `disk_temps.sh`
- Preexisting behavior: Five minute TTL cached results for rapid SNMP calls and large arrays
- New behavior: Avoids disk spinup, preferring to report standby "temperature" of -2
- New behavior: If an error is encountered during parsing, report a "temperature" of -1
- New behavior: Script originally output nothing if no cached results present. Now it reports whatever results were collected in the first 1000ms
- Added `disk_free_space.sh` to print free bytes in /boot, /mnt/disk*, /mnt/cache
- Exposed in SNMP as `diskfree`
- Added `cpu_mhz.sh` at request of forum user Max to output CPU speed in MHz
- Exposed in SNMP as `cpumhz`
- Tested with an Intel CPU virtualized under ESXi
### 2020.04.01
- Cache downloaded files on USB to support offline installation
- Add /mnt/disk up to 28 from 20 to provide 30 drive support
- Add MD5 for shell scripts
- Format plugin name in README to be in line with other plugins
- More consistent variable use and naming in .plg file
- Clearer install and uninstall logging
### 2019.05.28c
- Fix icon file
### 2019.05.28b
- Customized for the kubedzero repository
### 2019.05.28
- Updated plugin to work with 6.7.0, enforce minimum version
### 2018.07.22
- Fix bug with grep and "mostfree" allocator. https://github.com/coppit/unraid-snmp/pull/1
### 2017.02.07
- Drop all pretense of trying to keep up with nerd tools. Just require perl, and suggest that the user install nerd tools.
### 2016.02.28
- Bump the version of perl to match nerd tools.
### 2015.10.18
- Run temperature updates in the background
### 2015.09.06
- Move packages to github for better reliability
### 2015.09.05
- Add support for reporting share free space
### 2015.08.25
- Download and install the drive temp script (duh)
### 2015.08.24
- Added hard drive temperature capture
### 2015.08.23
- Reduced logging to "warning" level
### 2015.06.24
- Initial unRAID V6 release.
</CHANGES>
<!-- Download, cache and install dependent perl package shared with Nerd Pack -->
<FILE Name="&usbcfgdir;&perlpkg;" Run="upgradepkg --install-new">
<URL>&pkgurl;/&perlpkg;</URL>
<MD5>&perlpkgmd5;</MD5>
</FILE>
<!-- Download, cache and install dependent libnl package -->
<FILE Name="&usbcfgdir;&libnlpkg;" Run="upgradepkg --install-new">
<URL>&pkgurl;/&libnlpkg;</URL>
<MD5>&libnlpkgmd5;</MD5>
</FILE>
<!-- Download, cache and install the net-snmp package -->
<FILE Name="&usbcfgdir;&snmppkg;" Run="upgradepkg --install-new">
<URL>&pkgurl;/&snmppkg;</URL>
<MD5>&snmppkgmd5;</MD5>
</FILE>
<!-- Download, cache and install the Unraid Plugin package -->
<FILE Name="&usbcfgdir;&pluginpkg;" Run="upgradepkg --install-new">
<URL>&pkgurl;/&pluginpkg;</URL>
<MD5>&pluginpkgmd5;</MD5>
</FILE>
<!-- Test SNMP functionality -->
<FILE Run="/bin/bash">
<INLINE>
# 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 an error is encountered
set -e
echo ""
echo "+=============================================================================="
echo "| Testing SNMP by listing mounts, /boot should be present"
echo "+=============================================================================="
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"
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:"
echo "$results"
else
echo "Couldn't find /boot mount point. SNMP output:"
echo "$results"
exit 1
fi
echo ""
echo "+=============================================================================="
echo "| Other SNMP Examples"
echo "+=============================================================================="
echo ""
printf "Here are how sharefree lines look:\n"
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 $community localhost nsExtendOutLine\n"
snmpwalk -v 2c -c $community localhost nsExtendOutLine
echo ""
echo "+=============================================================================="
echo "| &name; version &pluginver; has been installed."
echo "+=============================================================================="
echo ""
exit 0
</INLINE>
</FILE>
<!-- The 'remove' script -->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
# 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 an error is encountered
set -e
echo ""
echo "+=============================================================================="
echo "| Uninstalling packages, removing directories and files"
echo "+=============================================================================="
echo ""
# Shut down the SNMP daemon. It emits its own STDOUT lines when done
/bin/bash /etc/rc.d/rc.snmpd stop
# Define packages to remove in a multi-line string in inverse order of installation
# NOTE: Skipping package removal of prereqs in Nerd Pack in case other plugins depend on them
pkgs_to_remove="
&pluginpkg;
&snmppkg;
&libnlpkg;
"
# Define directories and files to remove in a multi-line string
dirs_files_to_remove="
&usbcfgdir;
/usr/local/emhttp/plugins/snmp/
/etc/rc.d/rc.snmpd*
/etc/snmp/
/var/lib/net-snmp/
/var/log/snmpd.log
/etc/default/snmpd
"
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
[ -z "$line" ] && continue
# Remove the directory path and extension, leaving just the package name
pkg_name="$(basename $line .txz)"
# Perform the package removal
removepkg "$pkg_name"
done < <(printf '%s\n' "$pkgs_to_remove")
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
[ -z "$line" ] && continue
echo "Deleting $line"
# rm -rf "/path/to/prefix*" * expansion fails due to quotes, wrap in bash exec
bash -c "rm -rf $line"
done < <(printf '%s\n' "$dirs_files_to_remove")
printf "\nDirectory and file removal done"
echo ""
echo "+=============================================================================="
echo "| &name; has been uninstalled."
echo "+=============================================================================="
echo ""
exit 0
</INLINE>
</FILE>
</PLUGIN>