[Plug-In] SNMP


257 posts in this topic Last Reply

Recommended Posts

19 hours ago, kubed_zero said:

https://github.com/coppit/unraid-snmp/blob/master/snmp.plg#L197 The old version of the plugin (still linked in the first post of this topic) read from /usr/local/emhttp/plugins/snmp/snmpd.conf which sounds to be the issue you're facing. Are you using my latest version of the plugin, 2020.11.20, installed from Community Applications or https://github.com/kubedzero/unraid-snmp? It will start SNMP with the config file at /etc/snmp/snmpd.conf. 

 

Configuring the SNMP configuration via a GUI setting could be nice, please submit a PR! 

 

I simply searched in CA for "snmp" (from kubedzero version 2020.12.20) Is that not the current version? I will try to manually install the plg file.

 

edit:

Same after a manuall install (from https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/snmp.plg):

 

plugin: installing: https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/snmp.plg
plugin: downloading https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/snmp.plg
plugin: downloading: https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/snmp.plg ... done
plugin: downloading: https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/packages/perl-5.32.0-x86_64-1.txz ... done

+==============================================================================
| Skipping package perl-5.32.0-x86_64-1 (already installed)
+==============================================================================

plugin: downloading: https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/packages/libnl-1.1.4-x86_64-3.txz ... done

+==============================================================================
| Installing new package /boot/config/plugins/snmp/libnl-1.1.4-x86_64-3.txz
+==============================================================================

Verifying package libnl-1.1.4-x86_64-3.txz.
Installing package libnl-1.1.4-x86_64-3.txz:
PACKAGE DESCRIPTION:
# libnl (netlink socket library)
#
# libnl is a library for applications dealing with netlink sockets.
# The library provides an interface for raw netlink messaging and
# various netlink family specific interfaces.
#
# Homepage: http://people.suug.ch/~tgr/libnl/
#
#
Executing install script for libnl-1.1.4-x86_64-3.txz.
Package libnl-1.1.4-x86_64-3.txz installed.
plugin: downloading: https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/packages/net-snmp-5.9-x86_64-1.txz ... done

+==============================================================================
| Installing new package /boot/config/plugins/snmp/net-snmp-5.9-x86_64-1.txz
+==============================================================================

Verifying package net-snmp-5.9-x86_64-1.txz.
Installing package net-snmp-5.9-x86_64-1.txz:
PACKAGE DESCRIPTION:
# net-snmp (Simple Network Management Protocol tools)
#
# Various tools relating to the Simple Network Management Protocol:
#
# An extensible agent
# An SNMP library
# Tools to request or set information from SNMP agents
# Tools to generate and handle SNMP traps
# A version of the UNIX 'netstat' command using SNMP
# A graphical Perl/Tk/SNMP based mib browser
#
Executing install script for net-snmp-5.9-x86_64-1.txz.
Package net-snmp-5.9-x86_64-1.txz installed.
plugin: downloading: https://raw.githubusercontent.com/kubedzero/unraid-snmp/main/packages/unraid-snmp-2020.12.20-x86_64-1.txz ... done

+==============================================================================
| Installing new package /boot/config/plugins/snmp/unraid-snmp-2020.12.20-x86_64-1.txz
+==============================================================================

Verifying package unraid-snmp-2020.12.20-x86_64-1.txz.
Installing package unraid-snmp-2020.12.20-x86_64-1.txz:
PACKAGE DESCRIPTION:
# unraid-snmp
#
# unraid-snmp assists with installing a custom extension of net-snmp
# and configuring it for use on Unraid.
#
# nano /etc/snmp/snmpd.conf # edit config
# bash /etc/rc.d/rc.snmpd restart # stop and start daemon
# tail -f /var/log/snmpd.log # tail logs
#
# https://github.com/kubedzero/unraid-snmp
#
Executing install script for unraid-snmp-2020.12.20-x86_64-1.txz.
Set permissions and move into dir /usr/local/emhttp/plugins/snmp/
Set shell script executable permissions
Set read only permissions for other files
Checking if /etc/rc.d/rc.snmpd exists before editing
Stop SNMP daemon if it is currently running
Shutting down snmpd: DONE
Replace default snmpd.conf with our own, backing up the original
SNMP logging flag already present in rc.snmpd, skipping modification
Restart SNMP daemon now that we've adjusted how rc.snmpd starts it
Starting snmpd: /usr/sbin/snmpd -LF w /var/log/snmpd.log -A -p /var/run/snmpd -a -c /usr/local/emhttp/plugins/snmp/snmpd.conf
PID of started SNMP daemon is 4184
Package unraid-snmp-2020.12.20-x86_64-1.txz installed.

+==============================================================================
| Testing SNMP by listing mounts, /boot should be present
+==============================================================================

snmpwalk -v 2c localhost -c public hrFSMountPoint
SNMP appears to be working. Output:
HOST-RESOURCES-MIB::hrFSMountPoint.1 = STRING: "/mnt/disk1"
[..]

+==============================================================================
| Other SNMP Examples
+==============================================================================

Here are how sharefree lines look:
snmpwalk -v 2c -c public localhost 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."sharefree"'
[..]

Here are how all custom extensions look:
snmpwalk -v 2c -c public localhost nsExtendOutLine
NET-SNMP-EXTEND-MIB::nsExtendOutLine."cpumhz".1 = STRING: 2713.370 MHz
NET-SNMP-EXTEND-MIB::nsExtendOutLine."meminfo".1 = STRING: MemTotal: 33567850496
[..]

+==============================================================================
| snmp version 2020.12.20 has been installed.
+==============================================================================

plugin: snmp.plg installed

 

I have never developed something for Unraid but I will look into it to see if I can create a PR

Edited by mattie112
Link to post
  • Replies 256
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Created a pull request for the Coppit package on GitHub https://github.com/coppit/unraid-snmp/pull/6 but it doesn't seem like they've been active since August 2018 on here or on GitHub.   Wi

SNMP is a standard way to get raw data from devices, for monitoring purposes. With this package, you can hook your UNRAID server up to a monitor, and track things like network usage, cpu activity, eve

ok so I installed it, but important question: where can I set the SNMP community string?

Posted Images

Yes that is the current version.

 

Simple Network Management Protocol (SNMP) is a widely used protocol for monitoring the health and welfare of electronics. This Unraid plugin installs and configures SNMP for basic use with tools such as Observium and Grafana.

Support Thread

kubedzero

2020.12.20 

 

 

Link to post
20 hours ago, mattie112 said:

So should I then edit that file? Or can we make a change to choose what file to use?

You will have to edit /etc/snmp/snmpd.conf, but changes will not be persistent. You will need to copy a version to the boot drive and copy in the go file. You will also need to restart snmpd once the file is copied.

 

So in go file something like this before the GUI start.

 

cp /boot/config/snmpd.conf /etc/snmp/snmpd.conf

/etc/rc.d/rc.snmpd restart

 

 

 

 

Link to post

Yes thank you I understand that, however the snmpd process is not using that file, it is using `/usr/local/emhttp/plugins/snmp/snmpd.conf`

 

Te /etc/rc.d/rc.snmpd contains:

 

#!/bin/sh
#
# rc.snmpd      This shell script takes care of starting and stopping
#               the net-snmp SNMP daemon

OPTIONS="-LF w /var/log/snmpd.log -A -p /var/run/snmpd -a"

start() {
        if [ -x /usr/sbin/snmpd -a -f /usr/local/emhttp/plugins/snmp/snmpd.conf ]; then
                echo -n "Starting snmpd: "
                /usr/sbin/snmpd $OPTIONS -c /usr/local/emhttp/plugins/snmp/snmpd.conf
                echo " /usr/sbin/snmpd $OPTIONS -c /usr/local/emhttp/plugins/snmp/snmpd.conf"
        fi
}

stop() {
        # Stop daemons.
        COUNT=0
        echo -n "Shutting down snmpd: "
        while `killall snmpd 2>/dev/null`; do
                echo -n "."
                sleep 1
                COUNT=$((COUNT+1))
                if [ $COUNT -ge 30 ]; then
                        killall -9 snmpd
                        sleep 1
                        break
                fi
        done
        echo " DONE"
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        start
        ;;
  condrestart)
        if [ -f /var/run/snmpd ]; then
            stop
            start
        fi
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart}"
        ;;
esac

 

Edited by mattie112
Link to post
3 minutes ago, mattie112 said:

 

I simply searched in CA for "snmp" (from kubedzero version 2020.12.20) Is that not the current version? I will try to manually install the plg file.

That is the current version. Also, what version of Unraid are you running? The next thing I'd try is a reboot of Unraid to see if that helps. 

I have a suspicion that if you ran "head -15 /etc/rc.d/rc.snmpd" (which prints out the first 15 lines of the file, which is the part we care about) you might see a different start command than what it should be. Again, the old version of the plugin would modify this to point at the /usr/local/emhttp/plugins/snmp/snmpd.conf file by doing an in-place string replacement, but the new version does not. A reboot would fix this as the file is recreated at boot, which would be another reason for trying to fix this by rebooting
 

start() {
	if [ -x /usr/sbin/snmpd -a -f /etc/snmp/snmpd.conf ]; then
		echo -n "Starting snmpd: "
		/usr/sbin/snmpd $OPTIONS -c /etc/snmp/snmpd.conf
		echo " /usr/sbin/snmpd $OPTIONS -c /etc/snmp/snmpd.conf"
	fi
}

 

Link to post
2 minutes ago, kubed_zero said:

That is the current version. Also, what version of Unraid are you running? The next thing I'd try is a reboot of Unraid to see if that helps. 

I have a suspicion that if you ran "head -15 /etc/rc.d/rc.snmpd" (which prints out the first 15 lines of the file, which is the part we care about) you might see a different start command than what it should be. Again, the old version of the plugin would modify this to point at the /usr/local/emhttp/plugins/snmp/snmpd.conf file by doing an in-place string replacement, but the new version does not. A reboot would fix this as the file is recreated at boot, which would be another reason for trying to fix this by rebooting
 


start() {
	if [ -x /usr/sbin/snmpd -a -f /etc/snmp/snmpd.conf ]; then
		echo -n "Starting snmpd: "
		/usr/sbin/snmpd $OPTIONS -c /etc/snmp/snmpd.conf
		echo " /usr/sbin/snmpd $OPTIONS -c /etc/snmp/snmpd.conf"
	fi
}

 

 

Heh that's funny, after removing the plugin this file remained on the filesystem. I manually removed the file, then reinstalled the plugin and yes it is now /etc/snmp/snmpd.conf

 

So yeah: a reboot would also fix this I guess :)

 

Thanks and I will look into how things work with Unraid plugins to see if I can add somekind of config options to the UI (I will also be feeding it some custom config for snmp v3 as everything in my network uses that). But for now I can overwrite the conf file on boot as suggested.

Link to post

@kubed_zero

 

I'm looking into editing the plugin and so far I managed to add a text field on the settings, compile and install the plugin and see that the value is written to /boot/config/plugins/snmp/snmp.cfg

 

So here come my (noob) questions:

 

How / when is this file used? I see that on install it copies /usr/local/emhttp/plugins/snmp/snmpd.conf to /etc/snmp/snmpd.conf but I don't see this file mentioned?

 

When is this file created? Is a plugin "installed" again on boot?

 

Do the current settings work? (just to know where to look). I would assume that the doinst.sh should overwrite the snmpd.conf with whatever exists in /boot/config/plugins/snmp/snmp.cfg (and also when saving the settings).

 

When saving the settings I see a form submit to '/update.php'. Is this an unraid file/feature? I don't see it in this repo.

 

Is there any way to quickly test things? It takes some time to compile & install the plugin.

 

Sorry for the questions but this is for me the quickest way to help I can find out a lot but I need some pointers before I spend an entire day and only get frustrated :)

Link to post

/boot/config/plugins/snmp/snmp.cfg is read from and written to by the SNMP settings page https://github.com/kubedzero/unraid-snmp/blob/main/source/usr/local/emhttp/plugins/snmp/snmp.page#L18

 

It then gets read any time the disk_temps.sh script gets run https://github.com/kubedzero/unraid-snmp/blob/main/source/usr/local/emhttp/plugins/snmp/disk_temps.sh#L72

 

/boot/config/plugins/snmp/snmp.cfg is not guaranteed to exist, so the disk_temps.sh script has to handle if the file is missing. 

 

___

 

As for  /usr/local/emhttp/plugins/snmp/snmpd.conf, it gets extracted to here from the .txz during Unraid SNMP package installation. Then during package installation, it copies over / overwrites /etc/snmp/snmpd.conf https://github.com/kubedzero/unraid-snmp/blob/main/source/install/doinst.sh#L38.

 

This is done because it's easier to follow than doing hacky text replacement in /etc/rc.d/rc.snmpd to point at /usr/local/emhttp/plugins/snmp/snmpd.conf instead of /etc/snmp/snmpd.conf (the default). I also wanted to keep changes to /etc/rc.d/rc.snmpd to a minimum, since it's installed by the untouched Slackware snmp .txz and not *our* wrapper unraid-snmp

 

 

> I see a form submit to '/update.php'. Is this an unraid file/feature

Yes, I figured out its use by looking at other plugins with settings pages. Unfortunately there isn't much documentation for plugin creators.

 

 

> Is there any way to quickly test things?

Theoretically, if you wanted to make the SNMP config file configurable, you'd add a text field in the Settings page. Then from there you have a variety of choices, but no matter what you'd have to stop SNMP and then start it again with the correct parameters. I imagine that would be done by either triggering a shell script from the Settings page, or trying to do it all within the Settings page. You'd also have to do error handling for when the file being pointed to isn't present. You'd also have to handle boot scenarios since the unraid-snmp package reinstalls at boot time, meaning it would have to read the /boot/config/plugins/snmp/snmp.cfg if it exists, try to get the alternate location for etc/snmp/snmpd.conf, make the appropriate modifications, and then continue installation/starting of SNMP

Link to post
13 hours ago, mattie112 said:

quickly test things

For page and php changes I use winscp to copy files from my local github clone to my test server. Just replacing files in usr/local/emhttp/plugin/plugin name

 

 

Link to post

Ah yes thanks for the suggestions, I was thinking of rebuilding/reinstalling the plugin after changes but I can just mount the 'installed' directory and work from there.

 

I will look into this this weekend :) Might first go for a version to just change the snmp community or something to keep it simple :)

 

And I now also understand the 'unsafe temperature'. I thought this was a setting that needed to be written to the snmpd.conf so that was why I was so confused about "where does he write the conf file". It is simply never written :)

Edited by mattie112
Link to post

Oh wow the documentation is really terrible / non existing but helping at other plugins works :)

 

So:

I have managed to trigger a file of my own when submitting the form (might need to implement the current 'write settings' flow or perhaps also all the update file). So yeah now that I am in PHP context I can really do anything I need. I can write files and restart the service for example. First version might be a bit rough as I have no idea what the expected flow is but I think I can at least create something that would function. I will create a PR if I have something that works :)

Link to post
  • 2 weeks later...
1 hour ago, mattie112 said:

Allright, I hope I have done everything right but here it is :)

 

https://github.com/kubedzero/unraid-snmp/pull/1

Looks great, thanks a ton! From an initial look through, I have a couple minor comments that I need to post (consolidate PHP into the .page file, lower/camel case variable naming) but the comment lines and general look and feel are fantastic.

 

I realize there's no documented testing procedure, so I also want to give it a thorough run of different scenarios myself in terms of testing. Maybe I can even make a doc based on it 🤩  Fresh install, uninstall and reinstall, reboot, upgrade, *removal* of the custom config (does the default come back?), pre-population of the default config, a couple other things along those lines that will hopefully ensure it's resilient. 

 

I'm in the middle of another project so I hope to look at this within the next 3-4 days. 

Link to post

Thanks! Comments are welcome!

 

I have tried the following:

 

- clean install from my plugin, it starts with default

- change the config and reboot -> new config is restored

 

- update from your version

- as long as you don't save the config once through the UI it won't do anything

- as soon as you save it works like above

 

If you manually remove the config it should restore the default config the next boot.

 

btw: I use the snmpd.conf from the plugin as default. It will also use the contents of that file when you click on 'defaults' in the UI.

 

Oh and I added the 'run_before_save' on purpose. If I add the php to the .page itself it will get executed also on first load of the UI. Not only when the form is submitted but hey I'm open to suggestions, I simply could not really find what the expected way was to do this... :) 

 

Thanks for looking into it, no rush it works great for me at the moment :)

 

(And now I only need to test if snmp v3 auth works so that's really why I simply added the entire file instead of simply a user/pwd input field as the amount of options/config would be quite large in that case)

Link to post

@mattie112

 

I have done a quick test with the new package and have been able to update the location etc. Looks good 🙂

 

How are you making it persistent in your testing for reboots?

Edited by SimonF
Link to post
4 minutes ago, mattie112 said:

Upon reboot the "doinst.sh" should be exeuted, that file checks if we have a snmpd.conf on our /boot and if so it will copy it to /etc/snmp/snmpd.conf

 

Does that not work for you?

 

https://github.com/kubedzero/unraid-snmp/pull/1/files#diff-1fb19f48fc458b0bcde23e89158f1de55b789b97f62ba8e059ec029afaad9726R38

No as the plugin file is still pointing to the old package.

 

Have you updated your vers of the plg file for testing?

 

<!ENTITY pluginpkg "unraid-snmp-&pluginver;-x86_64-1.txz">

<!ENTITY pluginpkgmd5 "946e75bfef443c03b04cef44f63ed3d6">

Link to post
7 minutes ago, SimonF said:

No as the plugin file is still pointing to the old package.

 

Have you updated your vers of the plg file for testing?

 

<!ENTITY pluginpkg "unraid-snmp-&pluginver;-x86_64-1.txz">

<!ENTITY pluginpkgmd5 "946e75bfef443c03b04cef44f63ed3d6">

 

Whoops I think you are correct, I did change the "pluginver" there and probably manually added my version .txz to the flash. The .plg file should be in flash/config/plugins/snmp.plg

 

I'm currently running a backup so I can't reboot it atm but I can try to remove it all and then manually reinstall just to verify my flow again.

 

edit:

the txz file should be in: flash\config\plugins\snmp

Edited by mattie112
Link to post
28 minutes ago, mattie112 said:

 

Whoops I think you are correct, I did change the "pluginver" there and probably manually added my version .txz to the flash. The .plg file should be in flash/config/plugins/snmp.plg

 

I'm currently running a backup so I can't reboot it atm but I can try to remove it all and then manually reinstall just to verify my flow again.

 

edit:

the txz file should be in: flash\config\plugins\snmp

Have renamed your package to unraid-snmp-2021.04.06-x86_64-1.txz on the flash drive.

and updated .plg to 2021.04.06

 

Changes remain after reboot.

 

 

Edited by SimonF
Link to post

Hi @kubed_zero

 

Not sure if you want to look at the removal process, but other plugins I have seen, including my own don't remove the config files from the flash, they just remove the packages. If user removes plugin and install again at a later stage it will remember their last setup.

 

As it removes the /snmp dir it will remove the configs

 

 

 

Edited by SimonF
Link to post
6 hours ago, mattie112 said:

@kubed_zero did you manage to have a look at it? I have it running now and made some changes every couple of days. Also rebooted my server a couple of times and it seem to work like a charm here :)

I'm looking at it now. Just merged it to the test branch and am testing a couple things out. Also going through your notes, they are super helpful! Glad to hear you're using the UI customization of snmpd.conf (and thank you again for contributing!), I'm sure others will have similar findings! 

 

5 hours ago, SimonF said:

Hi @kubed_zero

 

Not sure if you want to look at the removal process, but other plugins I have seen, including my own don't remove the config files from the flash, they just remove the packages. If user removes plugin and install again at a later stage it will remember their last setup.

 

As it removes the /snmp dir it will remove the configs

 

 

 

 

Yes, this is by design! I am a big proponent of uninstallers removing all traces, rather than leaving the user to find what was left behind and what wasn't. Some other plugins do this as well: https://github.com/jbrodriguez/unbalance/blob/master/plugin/template.plg#L88 and  https://github.com/dlandon/open.files/blob/master/open.files.plg#L163 for example. Meanwhile, and as you've noted, others remove only some of the files under the boot directory https://github.com/dmacias72/unRAID-NerdPack/blob/master/plugin/NerdPack.plg#L292 and https://github.com/StevenDTX/unRAID-open-vm-tools/blob/master/openVMTools_compiled.plg#L275

I'll keep it as-is for now but will definitely think more on it. Thanks for the call-out! 

Link to post

Thanks! I got some e-mails from github so I figured you were looking into it :) If you need some changes let me know.

 

And about the uninstaller:

It seems kinda strange for an uninstaller to leave traces. I would also preferer it to delete everything it created. You might debate on if it needs to delete an entire directory or only the files it created in a directory. I would normally only remove->reinstall a plugin if I wanted to start with a clean state.

 

But then again if everybody does that on Unraid..... Would be great if there where some guidelines from Limetech on how to develop a plugin and about this kind of stuff.

Link to post
  • 4 weeks later...

Sorry it took so long! Thanks to @mattie112 I've just released update 2021.05.21 to main. If there are any bugs, it's probably due to my fiddling with the PR's code 😜

 

In essence, this update modifies the SNMP installer script to look on the /boot drive for an SNMP config file to use, preferring that over the bundled config if it exists. This means that even without using the UI, you can get a custom SNMP file to load up without any adjustments to the go file or anything else.

 

The other, much more headache-causing section of the update is a new part of the SNMP settings page to customize the SNMP config, save it to the /boot drive AND overwrite the actively-used config, and then restart SNMP to apply the changes. A Default button is also provided to restore the SNMP config to the default file that ships with this plugin. 

 

Oh, I also tweaked the uninstall code to better clean up after itself. It seemed that the `rm` commands weren't working as expected with an asterisk, so I've updated it to properly clear everything out.

 

As always, please enjoy and let me know if any issues arise. And again, thanks to @mattie112 for suggesting, implementing, and providing debugging help for this much-desired feature.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.