SNMP Binding don't receive TRAP commands

Hi,

I’m trying to use the new SNMP Binding for the DAEnetIP2 v2 Relay Board.

I followed the docu: SNMP Binding and polling with the GET command and sending with the SET comand works so far. Only receiving TRAP commands don’t work.

I’m using:

  • Raspberry Pi 3+
  • Openhabian with Openhab 2.5.5-1 (Release Build)
  • new SNMP Binding
  • DAEnetIP2 v2 Relay Board

The Relay Board uses SNMP v1 and is configured as:

  • Agent Port: 161
  • Read-only Community: public
  • Read-write Community: public
  • Trap Receiver IP Address: 192.168.1.211 (Openhab IP)
  • Trap Receiver Port: tried with 162 and 8162
  • Trap Community: public

For checking the correct behaviour I installed snmptrapd
With: sudo snmptrapd -f -Lo -c /etc/snmp/snmptrapd.conf

I received the TRAP which looks ok (configured relay board at port 162):

2020-05-24 13:47:33 192.168.1.216(via UDP: [192.168.1.216]:65534->[192.168.1.211]:162) TRAP, SNMP v1, community public
        iso.3.6.1.4.1.42505.9 Enterprise Specific Trap (0) Uptime: 0:02:21.81
        iso.3.6.1.4.1.42505.9.2.3.1 = INTEGER: 51

Unfortunately I don’t get a responce in Openhab.
I also activated the debug Logging via: log:set debug org.openhab.binding.snmp
But in the openhab 2 Log Viewer I don’t receive anything. (GET and SET still working)

My config are (for OH relay board port configured at 8162) :

snmp.cfg

# Configuration for the SNMP Binding
#
# Port used for receiving traps.
# This setting defaults to 0 (disabled / not receiving traps)
port=8162

SNMP.things

Thing snmp:target:DAEnetIP2v2 [ hostname="192.168.1.216", protocol="v1", refresh="20", community="public" ] {
    Channels:
		Type switch : port5pin1		[ oid=".1.3.6.1.4.1.42505.9.2.2.1.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin2		[ oid=".1.3.6.1.4.1.42505.9.2.2.2.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin3		[ oid=".1.3.6.1.4.1.42505.9.2.2.3.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin4		[ oid=".1.3.6.1.4.1.42505.9.2.2.4.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin5		[ oid=".1.3.6.1.4.1.42505.9.2.2.5.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin6		[ oid=".1.3.6.1.4.1.42505.9.2.2.6.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin7		[ oid=".1.3.6.1.4.1.42505.9.2.2.7.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
		Type switch : port5pin8		[ oid=".1.3.6.1.4.1.42505.9.2.2.8.0", mode="READ_WRITE", datatype="INT32", onvalue="1", offvalue="0" ]
	       
                 Type number : ADC1lowT		[ oid=".1.3.6.1.4.1.42505.9.2.3.1", mode="TRAP" , datatype="INT32" ]
}

SNMP.items

// *********** Ausgaenge des DAEnetIP2v2 Relay Borad ****************
Switch  Port5Pin1 "Port5.1 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin1" }
Switch  Port5Pin2 "Port5.2 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin2" }
Switch  Port5Pin3 "Port5.3 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin3" }
Switch  Port5Pin4 "Port5.4 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin4" }
Switch  Port5Pin5 "Port5.5 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin5" }
Switch  Port5Pin6 "Port5.6 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin6" }
Switch  Port5Pin7 "Port5.7 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin7" }
Switch  Port5Pin8 "Port5.8 [%d]" { channel="snmp:target:DAEnetIP2v2:port5pin8" }

// *********** Eingaenge des DAEnetIP2v2 Relay Borad ****************
Number ADC1lowT "Trap Adc 1 low [%d]" { channel="snmp:target:DAEnetIP2v2:ADC1lowT" }

SNMP.sitemap

Frame label="SNMP"
	{
		Switch item=Port5Pin1
		Switch item=Port5Pin2
		Switch item=Port5Pin3
		Switch item=Port5Pin4
		Switch item=Port5Pin5
		Switch item=Port5Pin6
		Switch item=Port5Pin7
		Switch item=Port5Pin8
	
		Text item=ADC1lowT
    }

In the Basic UI the Text item ADC1lowT which references to the TRAP channel shows only “-”

For me it looks like that OH don’t listen to the TRAP port or don’t get access to it? (but I get no error message)
Have i configured something wrong?
Unfortunately i don’t know how to debug it.

Thanks in advise
David

Try running the snmptrapd as the user who runs openhab (usually openhab) and see if you still receive the trap.

Thanks for your fast help.

So I tried it with:

sudo -H -u openhab bash -c 'sudo snmptrapd -f -Lo -c /etc/snmp/snmptrapd.conf'

And it worked also:

2020-05-24 19:06:56 192.168.1.216(via UDP: [192.168.1.216]:65534->[192.168.1.211]:162) TRAP, SNMP v1, community public
iso.3.6.1.4.1.42505.9 Enterprise Specific Trap (0) Uptime: 0:59:03.51
iso.3.6.1.4.1.42505.9.2.3.1 = INTEGER: 51

Than I configured snmptrapd to listen on port 8162 (configured in OH)
an the same as the above it works.

What I noticed snmptrapd only worked with sudo rights. I don’t know what rights openhab or snmp binding has?

Also a different in the OIDs I use:
The OID from the things ( .1.3.6.1.4.1.42505.9.2.3.1 ) differs at the first position from the snmptrapd read one ( iso.3.6.1.4.1.42505.9.2.3.1 )
This “iso” is replaced by “.1”. Idon’t know if this ok or not. But OH don’t allow the “iso”

Yeah. If you use sudo it‘ll always work. If it doesn‘t work without sudo rights, it‘s a security issue and you have to fix that.

Thanks for the info.

I was a bit too general with the meaning about sudo rights. If I use port 8162 snmptrapd don’t need sudo rights at openhab user.

Then I set the logging level from DEBUG to the higest possible ALL
But regarding traps I can’t see anything while the system is running.

Whenn the system (whole raspberry) boots there are some interresting logs at the beginning:

2020-05-26 21:00:02.060 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'SNMP.things'
2020-05-26 21:00:53.555 [DEBUG] [inding.snmp.internal.SnmpServiceImpl] - initialized SNMP at 0.0.0.0/0
2020-05-26 21:00:53.573 [DEBUG] [inding.snmp.internal.SnmpServiceImpl] - initialized SNMP at 0.0.0.0/0
2020-05-26 21:00:54.205 [hingStatusInfoChangedEvent] - 'snmp:target:DAEnetIP2v2' changed from UNINITIALIZED to INITIALIZING
2020-05-26 21:00:54.240 [hingStatusInfoChangedEvent] - 'snmp:target:DAEnetIP2v2' changed from INITIALIZING to UNKNOWN
2020-05-26 21:00:54.252 [hingStatusInfoChangedEvent] - 'snmp:target:DAEnetIP2v2' changed from UNKNOWN to ONLINE
2020-05-26 21:00:54.315 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - can''t process command REFRESH to snmp:target:DAEnetIP2v2:ADC1lowT: no writable channel found

and of course several of these:
 
2020-05-26 21:00:54.319 [TRACE] [inding.snmp.internal.SnmpServiceImpl] - send GET[requestID=1747560766, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.4.1.42505.9.2.2.1.0 = Null; 1.3.6.1.4.1.42505.9.2.2.5.0 = Null; 1.3.6.1.4.1.42505.9.2.2.8.0 = Null; 1.3.6.1.4.1.42505.9.2.2.3.0 = Null; 1.3.6.1.4.1.42505.9.2.2.6.0 = Null; 1.3.6.1.4.1.42505.9.2.2.2.0 = Null; 1.3.6.1.4.1.42505.9.2.2.7.0 = Null; 1.3.6.1.4.1.42505.9.2.2.4.0 = Null]] to CommunityTarget[address=192.168.1.216/161,version=0,timeout=1500,retries=2,securityLevel=1,securityModel=1,securityName=public,preferredTransports=null]
2020-05-26 21:00:54.472 [TRACE] [ding.snmp.internal.SnmpTargetHandler] - snmp:target:DAEnetIP2v2 received RESPONSE[requestID=1747560770, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.4.1.42505.9.2.2.8.0 = 0]]

The warning about my trap channel ADC1lowT with “no writable channel found” don’t looks good.
I’m not sure what is the issue here. Resp. how I can solve the problem.

This is interesting. Are you sure you configured the SNMP port? /0 looks like it’s still at the default 0 which means “do not receive traps”.

Yes, this is realy confusing. In the snmp.cfg the port is configured.

# Configuration for the SNMP Binding
#
# Port used for receiving traps.
# This setting defaults to 0 (disabled / not receiving traps)
port=8162

Is there a way to check if the file is used?
Can I set the port also in the .things file too? I didn’t found anything like that in the docu.

Try setting it in PaperUI

2 Likes

It workts :partying_face:

In the Paper UI the TRAP Port was set to 0. (under Configuration/Bindings/SNMP Binding)
So it seams that the snmp.cfp config is not used by openhab.

I configured the port in the Paper UI and everything works fine.
So with the configuration from the first post and the port configured in paper UI it runs.

@J-N-K Thank you very much for this perfect help.

2 Likes