GoSNMP is a very fun package to play with and learn about Go. It is easy to use and it can be made into doing something usefull quickly. The examples in the repo are clear and SNMP offers a fun way to play with channels and retrieving information from devices.

I came up with a few short examples that I stored here. Retrieving SNMP information for 20.000 devices using channels was particularly insightfull and gratifying. I had read about the how and why Go routines are very efficient, but seeing the information for all 20.000 devices appear in 5 seconds was mind blowing. Even more so given the amount of code involved. The following code was all that is required to start the go routines:

for _, targetDev := range devices {
	go GetSnmpDevInfo(targetDev, snmpString, c)

That was it. What this says is to iterate a slice of devices, and for every targetDev in the slice, start a go routine and execute GetSnmpDevInfo.

The go routines then do the work and output everything to a channel. After this, the following code is used to read from the channel:

for range devices {
	result := <-c

The GetSnmpDevInfo function itself did not require any special care.

The previous code snippets are from this script. In case you have not played with Go that much, the readme contains some notes on how to run the example.