This very rudimentary package attempts to create a single executable that exposes the NUT variables from a connected UPS as SNMP; essentially, what nut-snmpagent does, without Ruby or any other interpreted language (e.g. scripts et. al.) — but using the AgentX protocol instead.
- Network UPS Tools (NUT) installed, configured and running
- NUT-supported UPS connected to system and fully operational
- SNMP daemon (e.g. NET-SNMP 5.9 running on the same server, supporting the AgentX protocol
- A fairly recent Go compiler (requires at least modules to work)
$ git clone github.com/GwynethLlewelyn/go-nut-snmpagent
$ cd go-nut-snmpagent
$ go buildThis should leave a binary named go-nut-snmpagent on the same directory. By default, Go compiles binaries with debug data, so you might wish to run strip go-nut-snmpagent to make the binary smaller.
Then create a config.ini to override the defaults on config.main.ini, if you wish (e.g. authentication). You can see what options exist on that file, and set those that you wish or need.
You don't need to change anything on NUT. go-nut-snmpagent will simply connect to it and retrieve the data from the first UPS it can find there.
Of course, if you need authentication, then you might need to configure NUT to allow the agent to connect to it (optional, especially if both are running on the same system, in the same local network).
- On your
/etc/snmp/snmp.confjust make sure you have something like this:
com2sec notConfigUser default public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
access notConfigGroup "" any noauth exact systemview none none
view systemview included .1
master agentx
agentxperms 770 770 daemon users
-
Restart the SNMP server daemon (e.g.
sudo systemctl restart snmpdon mostsystemd-based Un*xes). -
Launch
$ ./go-nut-snmpagent. If all goes well, it should connect to the SNMP server and the NUT server, and start transcoding the information it gets from NUT into SNMP, automagically. -
Then try to do a
snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.318to see if you can get all the data via SNMP!
You might wish to add go-nut-snmpagent to systemd (on Linux, including the Raspberry Pi, Synology NAS, and many other embedded systems) or launchd (on macOS), or, if you're so bold, launch it as a service under Windows. Appropriate defaults are found on the /scripts directory (Windows instructions not included, since I have no clue how that works).
TODO: add more scripts for older methods (e.g. /etc/init.d//etc/rc.d or similar Jurassic setups).
See the top of the go-nut-snmpagent.go file (or go.mod).
Direct compilation tested so far on macOS Big Sur (Intel amd64), RaspberryOS (Debian) on a Rasperry Pi Zero W 2 (ARM aarch64), and on a Synology NAS DS218play (ARM aarch64).
All contributions/submissions are most welcome! Just fork the project on Github and submit a PR. If I get more than one contributor, I'll add an automated task to credit you here :-)
Special thanks to @luizluca for his outstanding work of creating nut-snmpagent (using a lot of tools, some Ruby and some shell scripting), on which some of this code is based on. @luizluca actually uses an older mechanism to communicate with the SNMP server daemon; we use AgentX.
And, of course, thanks to all those nice people out there writing Go libraries to read INI files (@unknwon), access NUT, and talk SNMP, all with native Go libraries!
Gopher image generated by gopherize.me, inspired by the Gopher mascot designed by Renee French.
Not likely, but I'd love to do a standalone SNMP version, possibly even bypassing NUT. NUT is great, don't get me wrong, and has been well-tested for as long as I can remember, but on embedded systems, the less processes spawned, the merrier!