SNMP monitoring for network devices

I have been playing with the SNMP binding for openHAB and have achieved some good results.
I’ll layout some examples below. (I’ll edit and add more detail as I get time)

When debugging SNMP OIDs I use Ireasoning MIB Free to poll the OID or do a walk and find the ones I need.

SECURITY! it is best practice to think of the community string as a password. I have replaced my actual strings with public and private for these posts but at work I use a 16 character random generated password and at home I use something a “little” less extreme. Any device on the network can issue a command to SNMP and if the device is setup with common names it is easier for someone to hack the machine.

At my work where I have an openHAB system running to monitor alot of different systems, currently employed are MQTT, Modbus/TCP, SNMP, and Mail.

MQTT monitors arduino ethernet devices placed in the server rooms to send info on temp, humidity air conditioner power status and weather the door is open or closed.

Mail is used for error reporting within the rules in case something goes wrong.

Modbus/TCP monitors various temperature & pressure senders as well as control light stacks and temperature controllers.

SNMP monitors the Printers toner lvls and places it in one neat window.

Group Printer <printer>
Group Jerry_Printer	"Jerry's Xerox 7100N"			<_7100n> (Printer)
Group ATAL_Printer	"ATAL Xerox 7100N"			<_7100n> (Printer)
Group AR_Printer	"Accounts Receivable Xerox 4250"	<_4250> (Printer)
Group HR_Printer	"Human Resource Xerox 4250"		<_4250> (Printer)
Group CS_Printer	"Customer Service Xerox 4250"		<_4250> (Printer)
Group CFO_Printer	"Chief Financial Officer Xerox 4250"	<_4250> (Printer)
Group ENG1_Printer	"Upstairs Engineering HP 5520"		<_4250> (Printer)

Number Jerry_Printer_K_T 	"Jerry's Black Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[]"}
Number Jerry_Printer_C_T 	"Jerry's Cyan Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[]"}
Number Jerry_Printer_M_T 	"Jerry's Magenta Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[]"}
Number Jerry_Printer_Y_T 	"Jerry's Yellow Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[]"}
Number ATAL_Printer_K_T 	"ATAL Black Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[]"}
Number ATAL_Printer_C_T 	"ATAL Cyan Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[]"}
Number ATAL_Printer_M_T 	"ATAL Magenta Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[]"}
Number ATAL_Printer_Y_T 	"ATAL Yellow Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[]"}
Number AR_Printer_1 		"AR Black Toner [%d%%]"		<_4250>		(AR_Printer)	{ snmp="<[]"}
Number HR_Printer_1 		"HR Black Toner [%d%%]"		<_4250>		(HR_Printer)	{ snmp="<[]"}
Number CS_Printer_1 		"CS Black Toner [%d%%]"		<_4250>		(CS_Printer)	{ snmp="<[]"}
Number CFO_Printer_1 		"CFO Black Toner [%d%%]"	<_4250>		(CFO_Printer)	{ snmp="<[]"}
String LBL_Printer_1 		"Assembly Label Printer Status [%s]"	<_4250>	(Printer)	{ http="<[*?Error Message</B></TD><TD height=20>(.*?)</TD>.*)]"}
Number ENG1_Printer_K_T 	"Upstairs Engineering Black Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[]"}
Number ENG1_Printer_C_T 	"Upstairs Engineering Cyan Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[]"}
Number ENG1_Printer_M_T 	"Upstairs Engineering Magenta Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[]"}
Number ENG1_Printer_Y_T 	"Upstairs Engineering Yellow Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[]"}

my JS example for converting the value from the SNMP query to a precentage is here. “25000” is the max lvl of the toner


(function(i){ return Math.round(i / 25000 * 100); })(input)

In the sitemap all I had to place was 2 lines because the groups break it down for me.

	Frame label="Printers"	{
	Group item=Printer label="Printer Status"


At home I use SNMP as well but for turning on and off ports on a managed switch. The Switch group displays a count of active ports. I would like to be able to have an item that has the item name the the status as text and the on/off switch to turn it on or off.

Ports 1 and 2 I have not adding switching to because one is in from my wifi router and the other is connected to my OpenHAB machine. If I was to turn either of them off I would lose control of OpenHAB

Group network "Network Items" (All) 
Group:Switch:OR(ON, OFF) ports "Switch Ports [(%d)]"	<port>	(network)

Switch Switch_PortEnable01 "Port 01 [%s]" <port> (ports)	{ snmp="<[]" }
Switch Switch_PortEnable02 "Port 02 [%s]" <port> (ports)	{ snmp="<[]" }
Switch Switch_PortEnable03 "Port 03 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable04 "Port 04 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable05 "Lisa's Laptop (Port-5) [%s]" <port> (ports,FF_Bed)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable06 "Port 06 [%s]" <port> (ports,FF_Bed)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable07 "Port 07 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable08 "Port 08 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable09 "Port 09 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable10 "Port 10 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable11 "Port 11 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable12 "Port 12 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable13 "Port 13 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable14 "Port 14 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable15 "Port 15 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable16 "Port 16 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable17 "Port 17 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable18 "Port 18 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable19 "Port 19 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable20 "Port 20 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable21 "Port 21 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable22 "Port 22 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable23 "Port 23 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }
Switch Switch_PortEnable24 "Port 24 [%s]" <port> (ports)	{ snmp="<[] >[OFF:] >[ON:]" }

So I ran into a learning experience with network printers and SNMP. Windows automatically uses SNMP “public” read access to determine whether or not the printer is online. I found the answer in this blog post. No one could print at work because all the machines thought the printers where offline. Rather than reconfigure all the machines at work, 100+! I changed the read access of the handful printers back to public. Though it was a fun start to my morning at work. :sweat:

I found another good use for snmp. I have a samsung tv that turns it’s ethernet port off when it is turned off. I use the snmp active check in my ethernet switch to tell me when the tv is on.

/* TV's */
Rollershutter volume      "Familyroom TV [%s]"	<speaker>	(SF_Family, Volume, TV)   {samsungtv="UP:Familyroom:KEY_VOLUP, DOWN:Familyroom:KEY_VOLDOWN, STOP:Familyroom:KEY_MUTE"}
Switch	TVPower			"Familyroom TV [%s]" (SF_Family, Power, TV)		{snmp="<[]", samsungtv="OFF:Familyroom:KEY_POWEROFF"}



Hi David, any chance you can see what I’m doing wrong here?

This is what my item looks like in the items files… I’ve replaced the community with XXXXXX just for posting purposes.

Number QNAP_CPULoad “Scarlet CPU Load (1min) [%.2f]” (NetworkPresence) {snmp="<[]"}

I can use MIB and get the true value but openHAB just doesn’t seem to ever get updated. You got any pointers maybe?

it could be you are defining a float for it try [%s] for string or try other types like [&d]. I used

Number	ProcessorLoad1	"Processor 1 Load [%d%%]"	(computer)	{ snmp="<[]"}
Number	ProcessorLoad2	"Processor 2 Load [%d%%]"	(computer)	{ snmp="<[]"}

for my windows machine

doh I see it you need to add the last number hrProcessorLoad.768

Number QNAP_CPULoad "Scarlet CPU Load (1min) [%d%%]" (NetworkPresence)	{snmp="<[]"}

Ahhhh thanks @LeXLuther422, so if there is a number here then I need to include it… That seems to work now!

Hi David, I’ve got things working pretty well now so thanks soooo much!
One issue I’m having is getting the total HDD size and free HDD size. I think the issue could be something like the number format or something…

This is what it looks like in MIB Browser.

This is what my item looks like…

Number QNAP_HDSize “Scarlet HD Total [%.0f]” (ScarletServer) {snmp="<[]"}

I’m 99.99% sure I have the OID correct based on my learnings from you, so I’m suspecting some sort of data type issue?

I don’t have that specific MIB available to me.
for my windows machine I have to read the total blocks used multiply it by block size to get total used.
for percentage I have to divide total size by total used.
I would play around with the Type in the description float is the hardest number type for a computer to compute. I would try [%d] or make it a string and see if it reads that way.

Number QNAP_HDSize "Scarlet HD Total [%d]" (ScarletServer) {snmp="<[]"}
String QNAP_HDSize "Scarlet HD Total [%s]" (ScarletServer) {snmp="<[]"}

In the events log of OpenHAB I can’t see my item actually being updated at all so it’s probably not an issue with the way it’s being displayed. There is a “OctetString” OID which gives me “5.34 TB” and I can show that in openHAB, but I was hoping to do a calc on total vs free to get a percentage… But the number “Counter64” values just don’t seem to be getting top OpenHAB at all…

I am able to get an exception

org.snmp4j.MessageException: Counter64 encountered in SNMPv1 PDU (RFC 2576 ?
        at org.snmp4j.PDUv1.decodeBER(
        at org.snmp4j.MessageDispatcherImpl.dispatchMessage(
        at org.snmp4j.MessageDispatcherImpl.processMessage(
        at org.snmp4j.MessageDispatcherImpl.processMessage(
        at org.snmp4j.transport.AbstractTransportMapping.fireProcessMessage(
        at org.snmp4j.transport.DefaultUdpTransportMapping$

Isn’t that counter64 is only available in snmp v2 or v3? and you are poling with v1. Dont know if that can be changed in Openhab.

This post was flagged by the community and is temporarily hidden.