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="<[192.168.1.94:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_7100.js)]"}
Number Jerry_Printer_C_T 	"Jerry's Cyan Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[192.168.1.94:public:1.3.6.1.2.1.43.11.1.1.9.1.4:60000:JS(C_7100.js)]"}
Number Jerry_Printer_M_T 	"Jerry's Magenta Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[192.168.1.94:public:1.3.6.1.2.1.43.11.1.1.9.1.3:60000:JS(M_7100.js)]"}
Number Jerry_Printer_Y_T 	"Jerry's Yellow Toner [%d%%]"	<_7100n>	(Jerry_Printer)	{ snmp="<[192.168.1.94:public:1.3.6.1.2.1.43.11.1.1.9.1.2:60000:JS(Y_7100.js)]"}
Number ATAL_Printer_K_T 	"ATAL Black Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[192.168.1.89:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_7100.js)]"}
Number ATAL_Printer_C_T 	"ATAL Cyan Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[192.168.1.89:public:1.3.6.1.2.1.43.11.1.1.9.1.4:60000:JS(C_7100.js)]"}
Number ATAL_Printer_M_T 	"ATAL Magenta Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[192.168.1.89:public:1.3.6.1.2.1.43.11.1.1.9.1.3:60000:JS(M_7100.js)]"}
Number ATAL_Printer_Y_T 	"ATAL Yellow Toner [%d%%]"	<_7100n>	(ATAL_Printer)	{ snmp="<[192.168.1.89:public:1.3.6.1.2.1.43.11.1.1.9.1.2:60000:JS(Y_7100.js)]"}
Number AR_Printer_1 		"AR Black Toner [%d%%]"		<_4250>		(AR_Printer)	{ snmp="<[192.168.1.101:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_4250.js)]"}
Number HR_Printer_1 		"HR Black Toner [%d%%]"		<_4250>		(HR_Printer)	{ snmp="<[192.168.1.102:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_4250.js)]"}
Number CS_Printer_1 		"CS Black Toner [%d%%]"		<_4250>		(CS_Printer)	{ snmp="<[192.168.1.98:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_4250.js)]"}
Number CFO_Printer_1 		"CFO Black Toner [%d%%]"	<_4250>		(CFO_Printer)	{ snmp="<[192.168.1.100:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_4250.js)]"}
String LBL_Printer_1 		"Assembly Label Printer Status [%s]"	<_4250>	(Printer)	{ http="<[http://192.168.1.92/info.html:60000:REGEX(.*?Error Message</B></TD><TD height=20>(.*?)</TD>.*)]"}
Number ENG1_Printer_K_T 	"Upstairs Engineering Black Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[192.168.1.99:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(_5520.js)]"}
Number ENG1_Printer_C_T 	"Upstairs Engineering Cyan Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[192.168.1.99:public:1.3.6.1.2.1.43.11.1.1.9.1.2:60000:JS(_5520.js)]"}
Number ENG1_Printer_M_T 	"Upstairs Engineering Magenta Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[192.168.1.99:public:1.3.6.1.2.1.43.11.1.1.9.1.3:60000:JS(_5520.js)]"}
Number ENG1_Printer_Y_T 	"Upstairs Engineering Yellow Toner [%d%%]"		<_7100n>	(ENG1_Printer)	{ snmp="<[192.168.1.99:public:1.3.6.1.2.1.43.11.1.1.9.1.4:60000:JS(_5520.js)]"}

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

K_7100.js

(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"
        }

8 Likes

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="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.1:10000:MAP(SwitchState.map)]" }
Switch Switch_PortEnable02 "Port 02 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.2:10000:MAP(SwitchState.map)]" }
Switch Switch_PortEnable03 "Port 03 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.3:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.3:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.3:1]" }
Switch Switch_PortEnable04 "Port 04 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.4:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.4:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.4:1]" }
Switch Switch_PortEnable05 "Lisa's Laptop (Port-5) [%s]" <port> (ports,FF_Bed)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.5:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.5:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.5:1]" }
Switch Switch_PortEnable06 "Port 06 [%s]" <port> (ports,FF_Bed)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.6:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.6:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.6:1]" }
Switch Switch_PortEnable07 "Port 07 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.7:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.7:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.7:1]" }
Switch Switch_PortEnable08 "Port 08 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.8:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.8:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.8:1]" }
Switch Switch_PortEnable09 "Port 09 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.9:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.9:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.9:1]" }
Switch Switch_PortEnable10 "Port 10 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.10:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.10:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.10:1]" }
Switch Switch_PortEnable11 "Port 11 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.11:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.11:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.11:1]" }
Switch Switch_PortEnable12 "Port 12 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.12:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.12:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.12:1]" }
Switch Switch_PortEnable13 "Port 13 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.13:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.13:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.13:1]" }
Switch Switch_PortEnable14 "Port 14 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.14:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.14:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.14:1]" }
Switch Switch_PortEnable15 "Port 15 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.15:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.15:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.15:1]" }
Switch Switch_PortEnable16 "Port 16 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.16:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.16:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.16:1]" }
Switch Switch_PortEnable17 "Port 17 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.17:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.17:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.17:1]" }
Switch Switch_PortEnable18 "Port 18 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.18:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.18:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.18:1]" }
Switch Switch_PortEnable19 "Port 19 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.19:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.19:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.19:1]" }
Switch Switch_PortEnable20 "Port 20 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.20:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.20:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.20:1]" }
Switch Switch_PortEnable21 "Port 21 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.21:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.21:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.21:1]" }
Switch Switch_PortEnable22 "Port 22 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.22:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.22:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.22:1]" }
Switch Switch_PortEnable23 "Port 23 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.23:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.23:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.23:1]" }
Switch Switch_PortEnable24 "Port 24 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.24:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.24:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.24:1]" }

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.
.ITEMS

/* 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="<[192.168.0.140:public:.1.3.6.1.2.1.2.2.1.8.10:10000:MAP(SwitchState.map)]", samsungtv="OFF:Familyroom:KEY_POWEROFF"}

SwitchState.map

1=ON
2=OFF
undefined=unknown
-=unknown

2 Likes

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="<[192.168.1.199:XXXXXX:.1.3.6.1.2.1.25.3.3.1.2:30000]"}

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="<[127.0.0.1:public:.1.3.6.1.2.1.25.3.3.1.2.6:60000]"}
Number	ProcessorLoad2	"Processor 2 Load [%d%%]"	(computer)	{ snmp="<[127.0.0.1:public:.1.3.6.1.2.1.25.3.3.1.2.7:60000]"}

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="<[192.168.1.199:XXXXXX:.1.3.6.1.2.1.25.3.3.1.2.768:30000]"}

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

@LeXLuther422
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="<[192.168.1.199:public:.1.3.6.1.4.1.24681.1.3.17.1.4.1:30000]"}

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="<[192.168.1.199:public:.1.3.6.1.4.1.24681.1.3.17.1.4.1:30000]"}
String QNAP_HDSize "Scarlet HD Total [%s]" (ScarletServer) {snmp="<[192.168.1.199:public:.1.3.6.1.4.1.24681.1.3.17.1.4.1:30000]"}

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 ?4.1.2.1)
        at org.snmp4j.PDUv1.decodeBER(PDUv1.java:195)
        at org.snmp4j.mp.MPv1.prepareDataElements(MPv1.java:194)
        at org.snmp4j.MessageDispatcherImpl.dispatchMessage(MessageDispatcherImpl.java:272)
        at org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl.java:368)
        at org.snmp4j.MessageDispatcherImpl.processMessage(MessageDispatcherImpl.java:328)
        at org.snmp4j.transport.AbstractTransportMapping.fireProcessMessage(AbstractTransportMapping.java:76)
        at org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(DefaultUdpTransportMapping.java:404)

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.