snmp binding - problems getting snmp traps to openhab

1,040 views
Skip to first unread message

Lars Bretschneider

unread,
Apr 6, 2014, 6:37:26 AM4/6/14
to ope...@googlegroups.com
hi,

i upgraded from openhab version 1.3 to 1.5 and had to modfiy my configurations for snmp binding ... i do net get it running ...

my new system:

- snmp forwarder listening on 162
- forwards snmp traps to 10162
- openhab listens on 10162

root@openhab:~# netstat -lnp | grep 162
udp        0      0 0.0.0.0:162             0.0.0.0:*                           2659/snmptrapd 
udp6       0      0 :::10162                :::*                                2222/java      
root@openhab:~#

- openhab runs on user openhab

i try to send snmp trap from another machine to openhab-machine, directly to 10162 oder 162 with forwarding nothing works...

12:26:39.252491 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto UDP (17), length 97)
    openhab.seume70.efficient-energies.de.seume70.34183 > openhab.seume70.10162:  { SNMPv1 C=openhab { Trap(53)  E:prime.2.2.1.11.8 192.168.10.102 warmStart[specific-trap(1)!=0] 4530300 E:prime.2.2.1.11.8="20.1" } }
12:26:39.261794 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto UDP (17), length 95)
    openhab.seume70.efficient-energies.de.seume70.47436 > openhab.seume70.10162:  { SNMPv1 C=openhab { Trap(51)  E:prime.2.2.1.10.8 192.168.10.102 warmStart[specific-trap(1)!=0] 4530300 E:prime.2.2.1.10.8="52" } }

i´m using coimmunity string openhab as you may see in above telegrams
forwarded telegrams can´t be dumped ...

12:30:52.739871 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto UDP (17), length 97)
    openhab.seume70.efficient-energies.de.seume70.34630 > openhab.seume70.snmp-trap:  { SNMPv1 C=openhab { Trap(53)  E:prime.2.2.1.11.8 192.168.10.102 warmStart[specific-trap(1)!=0] 4555600 E:prime.2.2.1.11.8="20.0" } }
12:30:52.751321 IP (tos 0x0, ttl 63, id 0, offset 0, flags [none], proto UDP (17), length 95)
    openhab.seume70.efficient-energies.de.seume70.43475 > openhab.seume70.snmp-trap:  { SNMPv1 C=openhab { Trap(51)  E:prime.2.2.1.10.8 192.168.10.102 warmStart[specific-trap(1)!=0] 4555600 E:prime.2.2.1.10.8="52" } }


Apr  6 12:30:52 openhab snmptrapd[2659]: 2014-04-06 12:30:52 192.168.10.102(via UDP: [10.100.1.102]:52267->[10.100.60.10]) TRAP, SNMP v1, community openhab#012#011iso.3.6.1.4.1.47.2.2.1.10.6 Warm Start Trap (1) Uptime: 12:39:16.00#012#011iso.3.6.1.4.1.47.2.2.1.10.6 = STRING: "50"
Apr  6 12:30:52 openhab snmptrapd[2659]: 2014-04-06 12:30:52 192.168.10.102(via UDP: [10.100.1.102]:34630->[10.100.60.10]) TRAP, SNMP v1, community openhab#012#011iso.3.6.1.4.1.47.2.2.1.11.8 Warm Start Trap (1) Uptime: 12:39:16.00#012#011iso.3.6.1.4.1.47.2.2.1.11.8 = STRING: "20.0"
Apr  6 12:30:52 openhab snmptrapd[2659]: 2014-04-06 12:30:52 192.168.10.102(via UDP: [10.100.1.102]:43475->[10.100.60.10]) TRAP, SNMP v1, community openhab#012#011iso.3.6.1.4.1.47.2.2.1.10.8 Warm Start Trap (1) Uptime: 12:39:16.00#012#011iso.3.6.1.4.1.47.2.2.1.10.8 = STRING: "52"


How can i debug snmp binding ? does somebody know where is the error ?


i tried with different addresses and cumunity setting in my items-file nothing in event/openhab log ...

root@openhab:/home/openhab/server/configurations/items# cat ws444pc.items
Number WS444_Sensor0_Temperatur "Sensor 0 [%.1f °C]"    <temperature>    (Status)                { snmp="<[10.100.60.10:openhab:1.3.6.1.4.1.47.2.2.1.11.0:0]" }
Number WS444_Sensor0_Feuchte     "Sensor 0 [%.1f %%]"    <temperature>    (Status)                 { snmp="<[localhost:openhab:1.3.6.1.4.1.47.2.2.1.10.0:0]" }

Number WS444_Sensor1_Temperatur "Sensor 1 [%.1f °C]"    <temperature>    (Status)                { snmp="<[192.168.10.102:openhab:1.3.6.1.4.1.47.2.2.1.11.1:0]" }
Number WS444_Sensor1_Feuchte     "Sensor 1 [%.1f %%]"    <temperature>    (Status)                 { snmp="<[10.100.1.102:openhab:1.3.6.1.4.1.47.2.2.1.10.1:0]" }

nothing snmp related in openhab.log exept:

/var/log/openhab.log   [----]  0 L:[  1+ 8   9/643] *(665 /65547b) 0049 0x031
Listening for transport dt_socket at address: 8001
12:00:08.188 INFO  o.o.c.internal.CoreActivator[:61] - openHAB runtime has been started (v1.5.0).
12:00:12.236 INFO  o.o.i.s.i.DiscoveryServiceImpl[:72] - mDNS service has been started
12:00:14.278 INFO  o.o.io.rest.RESTApplication[:141] - Started REST API at /rest
12:00:19.377 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'demo.sitemap'
12:00:19.656 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'persistence.sitemap'
12:00:19.894 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'db4o.persist'
12:00:19.947 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'rrd4j.persist'
12:00:20.001 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'temperatur.items'
12:00:20.073 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'greent.items'
12:00:20.084 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'date.items'
12:00:20.094 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'kostal.items'
12:00:20.113 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'proplanta.items'
12:00:20.125 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'ws444pc.items'
12:00:20.207 INFO  o.o.m.c.i.ModelRepositoryImpl[:79] - Loading model 'gasbezug.items'
12:00:22.721 INFO  o.o.u.w.i.s.WebAppServlet[:79] - Started Classic UI at /openhab.app
12:00:27.901 INFO  o.o.c.s.AbstractActiveService[:169] - HTTP Refresh Service has been started
12:00:28.247 INFO  o.o.b.s.internal.SnmpBinding[:402] - Didn't find SNMP timeout or configuration is invalid -> timeout set to 1500
12:00:28.248 INFO  o.o.b.s.internal.SnmpBinding[:417] - Didn't find SNMP retries or configuration is invalid -> retries set to 0
12:00:28.253 INFO  o.o.c.s.AbstractActiveService[:169] - SNMP Refresh Service has been started
12:00:28.295 INFO  runtime.busevents[:26] - GasImpulse state updated to 0







spf

unread,
Jan 14, 2015, 4:53:02 PM1/14/15
to ope...@googlegroups.com
I have the snmp binding 1.61.1
I have a Denkovi relay board and have been trying to get the SNMP trap to function.
I am running windows 7 64 bit.
I have checked the port status and openhab is monitoring on port 162.

My items file is setup like this

Number Light_Switch_Garage "Garage Light Input" (FF_Garage, Lights) { snmp="<[192.168.0.101:public:.1.3.6.1.4.1.32111.1.6.5.1:0]" }

The trap packet hits the ethernet port.  I can see it in wireshark.  It is SNMP V2
I have run the startup in debugger  and there are no errors.
Also there is no update or change in the shell when the packet hits the port.

My first question:
Is my items file syntax correct?
My second question:
Does anyone out there use the snmp trap function successfully?

When I change the items file binding to polling from trap it works very well.

This is my first openhab experience so I am a nube.
Thanks for any help on this.



snmpv2trap.pcapng

ge...@ge-volution.eu

unread,
Jan 15, 2015, 10:34:46 AM1/15/15
to ope...@googlegroups.com
Check out the bottom section of the SNMP binding Wiki where they talk about OpenHAB not having the access to bind to port 162.  This could perhaps be your problem.

I looked at using this SNMP binding a couple years ago now (man how time flies), but there was no SET or TRAP implemented so I just did my sets using the exec binding and net-snmp tools.

spf

unread,
Jan 15, 2015, 5:35:23 PM1/15/15
to ope...@googlegroups.com
I hadn't considered that that because I am using a windows operating system.  The note at the bottom said that port 162 is not available in linux due to only being able to be bound by privileged users.  Are there any other cases where port 162 was not usable in a windows operating system?

Greg Eva

unread,
Jan 16, 2015, 5:42:31 AM1/16/15
to ope...@googlegroups.com
You might try using netstat or procmon or something to verify that OpenHAB has been able to bind to UDP 162 and is listening on it.

                                                                           

Greg Eva
iNum : +833 51 00 09 90 28 81

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/GbKeqyk1izk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab/27149407-f419-4e7c-b334-4f1c5e4177c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

spf

unread,
Feb 24, 2015, 4:26:13 PM2/24/15
to ope...@googlegroups.com
I tried Netstat and SNMP.exe is on port 161 and Java.exe is on port 162.   Is this correct or what you would expect?

Greg Eva

unread,
Feb 26, 2015, 6:18:26 AM2/26/15
to ope...@googlegroups.com
Yes; this seems to be OK.

UDP port 161 is used by an SNMP agent to listen for poll requests.
UDP 162 is used as an SNMP trap listener to listen for incomfing traps.

As you are trying to get the traps in OpenHAB, it would make sense to me that Java has bound the UDP/162 port.


                                                                           

Greg Eva
iNum : +833 51 00 09 90 28 81

fabian....@gmail.com

unread,
Aug 7, 2015, 5:05:06 AM8/7/15
to openhab
Hi,

'God, I have the same problem. I'm running Rasberry PI, OpenHAB 1.7.1 SNMP binding 1.7.1, Denkovi relay board and trying to get SNMP trap funcion on port 162. Regular SNMP SET, GET works perfectly but TRAP isn't.
OpenHAB runs with root permission, JAVA is listening on port 162.

root@raspberrypi:/home/pi# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:8443            0.0.0.0:*               LISTEN      11002/java
tcp        0      0 0.0.0.0:2020            0.0.0.0:*               LISTEN      2099/sshd
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      11002/java
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1880/dhclient
udp        0      0 192.168.1.137:123       0.0.0.0:*                           2048/ntpd
udp        0      0 127.0.0.1:123           0.0.0.0:*                           2048/ntpd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           2048/ntpd
udp        0      0 0.0.0.0:162             0.0.0.0:*                           11002/java
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           11002/java
udp        0      0 0.0.0.0:36258           0.0.0.0:*                           1880/dhclient


Simple SNMP GET - this is working well.
Item defintions:   Number DAE_DI6_GET   "Value [%s]" { snmp="<[192.168.1.100:public:.1.3.6.1.4.1.42505.1.2.1.1.7.6:1]"}

Result:
root@raspberrypi:/home/pi# tcpdump port 162
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
08:49:19.241293 IP raspberrypi.snmp-trap > 192.168.1.100.snmp:  GetRequest(34)  E:42505.1.2.1.1.7.6
08:49:19.254689 IP 192.168.1.100.snmp > raspberrypi.snmp-trap:  GetResponse(40)  E:42505.1.2.1.1.7.6.0=0

OpenHAB Log:
2015-08-07 08:54:41.575 [INFO ] [runtime.busevents             ] - DAE_DI6_GET state updated to 0
2015-08-07 08:54:42.576 [INFO ] [runtime.busevents             ] - DAE_DI6_GET state updated to 0
2015-08-07 08:54:43.579 [INFO ] [runtime.busevents             ] - DAE_DI6_GET state updated to 0

It works prefect.


But TRAP - no answer, not working:
Item defintions: Number DAE_DI6_TRAP "Value [%s]" { snmp="<[192.168.1.100:public:.1.3.6.1.4.1.42505.1.2.1.1.7.6:0]"}

Here's the TRAP message from relay board:
root@raspberrypi:/home/pi# tcpdump port 162
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
08:51:09.517537 IP 192.168.1.100.65534 > raspberrypi.snmp-trap:  Trap(52)  E:42505.1 192.168.1.100 enterpriseSpecific s=1 4280843 E:42505.1.2.1.1.7.6=1

OpenHAB Log:
nothing happens.

You have been solved? How did you do it? Anyone have any ideas?
I have no idea where he could be a problem. I tried to generate custom trap messege with another application, but I have not been success.
I think I already tried almost everything. Have I tried is Windows environments too.


Thanks for your help, best regards,
Gyula
Message has been deleted
Message has been deleted

spf

unread,
Aug 7, 2015, 7:23:27 AM8/7/15
to ope...@googlegroups.com
I am not aware of a resolution to the SNMP trap function not working properly yet

fabian....@gmail.com

unread,
Aug 8, 2015, 3:53:32 PM8/8/15
to openhab
Too bad. I was hoping that solved. I have to look to other solutions. Thanks.

Fábián Gyula

unread,
Aug 16, 2015, 3:23:15 AM8/16/15
to ope...@googlegroups.com
I completed the challenge with other solution. Sum it all:
- receive TRAP from my device by SNMP daemon with SNMPTRAPD
- create custom sh script which called from SNMPTRAPD
- OpenHAB REST API by called from custom sh script
- using OpenHAB rules to handle states and events

Here's my "bread board" developer configuration. Maybe it will help to everyone.
It works like a charm!


snmptrapd.conf
______________________________________

authCommunity log,execute,net public
traphandle default /opt/openhab/snmp_trap.sh




etc/default/snmpd
______________________________________

# This file controls the activity of snmpd and snmptrapd

# Don't load any MIBs by default.
# You might comment this lines once you have the MIBs downloaded.
export MIBS=

# snmpd control (yes means start daemon).
SNMPDRUN=yes

# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'

# snmptrapd control (yes means start daemon).  As of net-snmp version
# 5.0, master agentx support must be enabled in snmpd before snmptrapd
# can be run.  See snmpd.conf(5) for how to do this.
TRAPDRUN=yes

# snmptrapd options (use syslog).
TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'

# create symlink on Debian legacy location to official RFC path
SNMPDCOMPAT=yes



/opt/openhab/snmp_trap.sh
______________________________________

#!/bin/bash

#OpenHAB config
openhab_host=127.0.0.1:8080
openhab_user=User1
openhab_pass=Pass123

#DAE config
dae1_ip=192.168.1.100
dae1_name=DAE_B1

dae2_ip=192.168.1.101
dae2_name=DAE_B2

dae3_ip=192.168.1.102
dae3_name=DAE_B3



#read snmptrap input to vars
read host
read ip
vars=

while read oid val
  do
  if [ "$vars" = "" ]
  then
    vars="$oid = $val"
  else
    vars="$vars, $oid = $val"
  fi
done


regex_inid_val="1.2.1.1.7.([0-9]{1,2}) = ([0-1]{1})"
regex_ip="3.6.1.6.3.18.1.3.0 = ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})"

if [[ $vars =~ $regex_ip ]];
then snmp_ip=${BASH_REMATCH[1]};
fi

if [ $snmp_ip = $dae1_ip ]; then daeip=$dae1_ip; daename=$dae1_name;fi;
if [ $snmp_ip = $dae2_ip ]; then daeip=$dae2_ip; daename=$dae2_name;fi;
if [ $snmp_ip = $dae3_ip ]; then daeip=$dae2_ip; daename=$dae3_name;fi;

if [[ $vars =~ $regex_inid_val ]];
then
    curl --silent -H "Content-Type: text/plain" http://$openhab_user:$openhab_pass@$openhab_host/rest/items/$daename'_DI'${BASH_REMATCH[1]} -d "ON"
    #echo Found! regex1: ${BASH_REMATCH[1]} regex2: ${BASH_REMATCH[2]} vars: $vars > /opt/openhab/snmp_handle.out;
else echo Regex not found: $vars > /opt/openhab/snmp_handle.out;
fi




default.items
______________________________________

Switch DAE_B1_Switch0 "Switch0 [%s]" (DAEs) { snmp="<[192.168.1.100:read:.1.3.6.1.4.1.42505.1.2.3.1.11.0:10000:MAP(SwitchState.map)] >[OFF:192.168.1.100:write:.1.3.6.1.4.1.42505.1.2.3.1.11.0:0] >[ON:192.168.1.100:write:.1.3.6.1.4.1.42505.1.2.3.1.11.0:1]" }
Switch DAE_B1_Switch1 "Switch1 [%s]" (DAEs) { snmp="<[192.168.1.100:read:.1.3.6.1.4.1.42505.1.2.3.1.11.1:10000:MAP(SwitchState.map)] >[OFF:192.168.1.100:write:.1.3.6.1.4.1.42505.1.2.3.1.11.1:0] >[ON:192.168.1.100:write:.1.3.6.1.4.1.42505.1.2.3.1.11.1:1]" }
Switch DAE_B1_Switch2 "Switch2 [%s]" (DAEs) { snmp="<[192.168.1.100:read:.1.3.6.1.4.1.42505.1.2.3.1.11.2:10000:MAP(SwitchState.map)] >[OFF:192.168.1.100:write:.1.3.6.1.4.1.42505.1.2.3.1.11.2:0] >[ON:192.168.1.100:write:.1.3.6.1.4.1.42505.1.2.3.1.11.2:1]" }
...and so on

Switch DAE_B1_DI0 "DAE_B1_DI0 [%s]"
Switch DAE_B1_DI1 "DAE_B1_DI1 [%s]"
Switch DAE_B1_DI2 "DAE_B1_DI2 [%s]"
...and so on
Number DAE_B1_AI0 "DAE_B1_AI0 [%s]" { snmp="<[192.168.1.100:read:.1.3.6.1.4.1.42505.1.2.2.1.6.0:10000]" }
Number DAE_B1_AI1 "DAE_B1_AI1 [%s]" { snmp="<[192.168.1.100:read:.1.3.6.1.4.1.42505.1.2.2.1.6.1:10000]" }
Number DAE_B1_AI2 "DAE_B1_AI2 [%s]" { snmp="<[192.168.1.100:read:.1.3.6.1.4.1.42505.1.2.2.1.6.2:10000]" }
...and so on




default.rules
______________________________________

rule "rule_DAE_B1_DI7"
    when
        Item DAE_B1_DI7 received command
    then
        if(DAE_B1_Switch0.state==OFF) {
            logInfo("************************", "****************** DAE_B1_DI7 Rules ON")
            sendCommand(DAE_B1_Switch0, ON)
        } else {
            logInfo("************************", "****************** DAE_B1_DI7 Rules OFF")
            sendCommand(DAE_B1_Switch0, OFF)
        }
end



Good luck, regards,
Gyula
Reply all
Reply to author
Forward
0 new messages