-
Notifications
You must be signed in to change notification settings - Fork 11
/
snmp.plg
291 lines (238 loc) · 6.87 KB
/
snmp.plg
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
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "snmp">
<!ENTITY author "coppit">
<!ENTITY version "2018.07.22">
<!ENTITY pluginURL "https://github.com/coppit/unraid-snmp/raw/master/snmp.plg">
<!ENTITY pkgversion "5.7.3">
<!ENTITY gitURL "https://raw.githubusercontent.com/&author;/unraid-snmp/master">
<!ENTITY plugdir "/usr/local/emhttp/plugins/&name;">
<!ENTITY pkgdir "/boot/packages">
<!ENTITY cfgdir "/boot/config/plugins/&name;">
<!ENTITY pkghost "&gitURL;/packages">
<!ENTITY snmppkg "net-snmp-&pkgversion;-x86_64-4.txz">
<!ENTITY snmppkgmd5 "b9ef68216b97cb5f0bcd9f3312e5941e">
<!ENTITY libnlpkg "libnl-1.1.4-x86_64-1.txz">
<!ENTITY libnlpkgmd5 "435837a5bf0401a937d6ec93e458333b">
<!ENTITY iconfile "snmp.png">
<!ENTITY iconfilemd5 "863e97dc0e59ae9352f558ee8e0d40a2">
<!ENTITY community "public">
<!ENTITY location "Here">
<!ENTITY contact "root@tower">
]>
<PLUGIN name="&name;"
author="&author;"
version="&version;"
pluginURL="&pluginURL;">
<CHANGES>
##&name;
###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>
<!--
This plugin provides SNMP support for unRAID systems.
-->
<!--
create plugin README.md file
-->
<FILE Name="&plugdir;/README.md">
<INLINE>
###SNMP###
Installs and configures SNMP, the Simple Network Management Protocol. SNMP can be used to expose server information to
monitoring tools like Observium.
</INLINE>
</FILE>
<!--
Check for prerequisites
-->
<FILE Run="/bin/bash">
<INLINE>
perl_path=$(which perl 2>/dev/null)
if [ ! -x "$perl_path" ] ; then
echo "This plugin requires perl. The easiest way to get it is to install NerdPack:"
echo "http://lime-technology.com/forum/index.php?topic=37541.0"
echo ""
echo "Exiting"
echo ""
echo ""
exit 1
fi
</INLINE>
</FILE>
<!--
Install prerequisites.
-->
<FILE Name="&pkgdir;/&libnlpkg;" Run="upgradepkg --install-new">
<URL>&pkghost;/&libnlpkg;</URL>
<MD5>&libnlpkgmd5;</MD5>
</FILE>
<!--
Get the package.
-->
<FILE Name="&pkgdir;/&snmppkg;" Run="upgradepkg --install-new">
<URL>&pkghost;/&snmppkg;</URL>
<MD5>&snmppkgmd5;</MD5>
</FILE>
<!--
Fetch an icon
-->
<FILE Name="&plugdir;/&iconfile;">
<URL>&gitURL;/&iconfile;</URL>
<MD5>&iconfilemd5;</MD5>
</FILE>
<!--
Fetch the drive temperature script
-->
<FILE Name="&plugdir;/drive_temps.sh">
<URL>&gitURL;/drive_temps.sh</URL>
</FILE>
<!--
Fetch the share free space script
-->
<FILE Name="&plugdir;/share_free_space.sh">
<URL>&gitURL;/share_free_space.sh</URL>
</FILE>
<!--
Set up the config file
-->
<FILE Name="&plugdir;/snmpd.conf">
<INLINE>
rocommunity &community;
syslocation &location;
syscontact &contact;
disk /mnt/disk1
disk /mnt/disk2
disk /mnt/disk3
disk /mnt/disk4
disk /mnt/disk5
disk /mnt/disk6
disk /mnt/disk7
disk /mnt/disk8
disk /mnt/disk9
disk /mnt/disk10
disk /mnt/disk11
disk /mnt/disk12
disk /mnt/disk13
disk /mnt/disk14
disk /mnt/disk15
disk /mnt/disk16
disk /mnt/disk17
disk /mnt/disk18
disk /mnt/disk19
disk /mnt/disk20
disk /mnt/cache
extend disktemp &plugdir;/drive_temps.sh
extend sharefree &plugdir;/share_free_space.sh
</INLINE>
</FILE>
<!--
Fix permissions on &plugdir;
-->
<FILE Run="/bin/bash">
<INLINE>
chmod o+rx &plugdir;
</INLINE>
</FILE>
<!--
Update rc.d to use our config file, restart snmpd, and test it
-->
<FILE Run="/bin/bash">
<INLINE>
echo "+=============================================================================="
echo "| Updating /etc/rc.d/rc.snmpd to use our config file, and to reduce logging"
echo "+=============================================================================="
bash /etc/rc.d/rc.snmpd stop
sed -i.old -e 's#/etc/snmp/snmpd.conf#&plugdir;/snmpd.conf#g' /etc/rc.d/rc.snmpd
sed -i.old -e 's#OPTIONS="#OPTIONS="-LF w /var/log/snmpd.log #g' /etc/rc.d/rc.snmpd
chmod a+x &plugdir;/drive_temps.sh
chmod a+x &plugdir;/share_free_space.sh
bash /etc/rc.d/rc.snmpd start
echo ""
echo ""
echo "+=============================================================================="
echo "| Testing SNMP by listing mounts"
echo "+=============================================================================="
RESULTS=$(snmpwalk -v 1 localhost -c public hrFSMountPoint 2>&1)
if [[ "$RESULTS" =~ "/boot" ]]
then
echo "Looks like snmpd is working... Output:"
echo "$RESULTS"
else
echo "Couldn't find /boot mount point in SNMP output. Output:"
echo "$RESULTS"
echo ""
echo ""
exit 1
fi
echo ""
echo "Here's what drive temperatures look like:"
echo snmpwalk -v 2c localhost -c public 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp"'
snmpwalk -v 2c localhost -c public 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."disktemp"'
echo ""
echo "Here's what share free space looks like:"
echo snmpwalk -v 2c localhost -c public 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."sharefree"'
snmpwalk -v 2c localhost -c public 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."sharefree"'
echo ""
echo ""
exit 0
</INLINE>
</FILE>
<!--
The 'post-install' script.
-->
<FILE Run="/bin/bash">
<INLINE>
echo ""
echo "-----------------------------------------------------------"
echo " &name; has been installed."
echo " Copyright 2015, David Coppit <[email protected]>"
echo " Version: &version;"
echo "-----------------------------------------------------------"
echo ""
</INLINE>
</FILE>
<!--
The 'remove' script.
-->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
echo "+=============================================================================="
echo "| Uninstalling packages"
echo "+=============================================================================="
# Delete the package, and any old package files too
rm -f $(ls &pkgdir;/&name;*.txz 2>/dev/null)
# Uninstall the package
removepkg $(basename &snmppkg; .txz) | grep -v -e ' --> Deleting'
# Don't uninstall the prerequisites, in case some other plug is using them. On reboot, they'll get "removed" if no plugin
# needs them, or will be re-downloaded and reinstalled by some plugin that does need them.
#removepkg $(basename &libnlpkg; .txz) | grep -v -e ' --> Deleting'
echo ""
echo ""
echo "+=============================================================================="
echo "| Deleting &plugdir;"
echo "+=============================================================================="
# Remove plugin.
rm -rf &plugdir;
echo ""
echo ""
</INLINE>
</FILE>
</PLUGIN>