[SOLVED] SNMP Binding and Problems with item names and SNMP Traps

Hello community,

after many days of trial and error I have to ask you for help about the snmp binding.
At first, here are my installed system:
Openhab 2.4.0.002 on a synology NAS Station with a lot of bindings (all works) and the snmp binding 1.13 (a higher version isn’t present on paper ui).
Binding configuration (snmp.cfg):

# Listening Port (optional, defaults to '162')
port=1620

# The SNMP community to listen to (optional, defaults to 'public')
community=public

# The SNMP retry timeout (in milliseconds). Defaults to 1500.
# Sets the number of milliseconds between retries.
timeout=1500

# The SNMP number of retries. Defaults to 0.
# Sets the number of retries before aborting the request.
retries=3

I control a denkovi daenetip2v2 module (16 digital in or outputs and 8 analog inputs) with get/set snmp. To control the digital outputs works great, also to get value back. See a example for Digital output port 3.1:

Switch   Pdig31   " Dout 3.1 [%s] "   { snmp="<[192.168.xxx.yyy:private:.1.3.6.1.4.1.42505.9.2.1.1.0:10000] >[ON:192.168.xxx.yyy:private:.1.3.6.1.4.1.42505.9.2.1.1.0:1] >[OFF:192.168.xxx.yyy:private:.1.3.6.1.4.1.42505.9.2.1.1.0:0]" }

now my first problem with item names: When I want to read out the analog ports I can’t use any Name for the item I want ( I now that I don’t have to use special characters…), see a example that works:

String   Pana68   " Ain 6.8 [%s] "    { snmp="<[192.168.xxx.yyy:private:.1.3.6.1.4.1.42505.9.2.3.8.0:10000]" }

“Pana68” will accepted and is refreshed every 10s. But when I use (for example) “Pana67” or “Pana66” the value will not present in Basic UI, only a “-” is shown. There are many more names, that doesn’t works (like “Alarm” oder “Window”, and so on). every Name I use is unique. Its hard to find a name, that works, because I want a simple Name which have a relationship to the thing, I want to control.
Is there anyone, that known this problem and can help me?

My second Problem is about SNMP Traps. In the denkovi module I switched the IP adresse, port and community to my NAS / openhab system (IP Adresse 192.168.xxx.zzz, Port 1620 and community is public). When the module is in alarm mode, it sends snmp traps. I sniff my network and can see, thats work great:

Configuration of the item that should receive the snmp traps in openhab is:

String          Ball   " [%s] "    { snmp="<[192.168.xxx.yyy:public:.1.3.6.1.4.1.42505.9.2.3.2.0:0]" }

But in Openhab the value 1022 (send via snmp trap from the denkovi modul) will not present, the item still shows a “-” in Basic UI. The item Name “Ball” is one of the names, that works for normal snmp-get.
In openhab.log is no error or warning and in event.log is also nothing to see.

I hope, there is somebody who can help me out.

Regards
Olaf

You need to set up logging for the binding and examine it to see what the problem is.
See the Taming OpenHAB 2 logging thread if you need to learn about logging.

If there is no known issue with your bindings in 2.5, I would suggest to upgrade to 2.5 and use the new SNMP binding.

so, I did a upgrade to openhab 2.5 and SNMP 2.5 but I still have (other) troubles.
The problems about the item names seems to be solved, all item name I have been tested, are ok and works.
But SNMP Traps still not works. And I also have problems to control the output ports of the daenetip Modul (with SNMP 2.5 binding).
I create a snmp thing:

Thing snmp:target:daenetip [ hostname="192.168.xxx.yyy", protocol="v1", community="private" ] {
    Channels:
        Type number : port31    [ oid=".1.3.6.1.4.1.42505.9.2.1.1.0", mode="READ" ]
        Type number : port62    [ oid=".1.3.6.1.4.1.42505.9.2.3.2.0", mode="TRAP" ]
        Type switch : port33    [ oid=".1.3.6.1.4.1.42505.9.2.1.3.0", mode="READ_WRITE", onvalue="1", offvalue="0" ]      
}

items:

Number      port31      " Pout 31 [%s] "            { channel="snmp:target:daenetip:port31" }
Number      port62      " Trap Pana 62 [%s] "       { channel="snmp:target:daenetip:port62" }
Switch      port33      " Pout 33 [%s] "            { channel="snmp:target:daenetip:port33" }

But only the Read Port 31 works. Why did I do wrong?

Can you provide a DEBUG log?

I changed the item name port33 to Pout33 (now it is no longer the same name as the channel type)

Switch      Pout33      " Pout 33 [%s] "            { channel="snmp:target:daenetip:port33" }

and see following in the events log:

2020-01-24 19:51:19.686 [ome.event.ItemCommandEvent] - Item 'Pout33' received command OFF
2020-01-24 19:51:19.688 [nt.ItemStatePredictedEvent] - Pout33 predicted to become NULL
2020-01-24 19:51:20.389 [ome.event.ItemCommandEvent] - Item 'Pout33' received command ON
2020-01-24 19:51:20.391 [nt.ItemStatePredictedEvent] - Pout33 predicted to become NULL

and in the openhab.log:

2020-01-24 19:51:18.561 [INFO ] [ding.snmp.internal.SnmpTargetHandler] - failed to renew target address, can't process 'ON' to 'snmp:target:daenetip:port33'.
2020-01-24 19:51:19.706 [INFO ] [ding.snmp.internal.SnmpTargetHandler] - failed to renew target address, can't process 'OFF' to 'snmp:target:daenetip:port33'.
2020-01-24 19:51:20.408 [INFO ] [ding.snmp.internal.SnmpTargetHandler] - failed to renew target address, can't process 'ON' to 'snmp:target:daenetip:port33'.
2020-01-24 19:51:40.052 [INFO ] [ding.snmp.internal.SnmpTargetHandler] - failed to renew target address, waiting for next refresh cycle
2020-01-24 19:52:40.071 [INFO ] [ding.snmp.internal.SnmpTargetHandler] - failed to renew target address, waiting for next refresh cycle
...

Is this helping too?
Currently I don’t know, how to start Debug Mode, I need to read documentation first.

Failed to renew target address usually means that the host name cannot be resolved. You use an IP address, I‘ll have to check the code how this can happen.

oups sorry, I just see, that this error is my mistake! I forgot to correct the IP Adress back to its correct value, because I did a test on it! sorry!
I’m still working on debug modus …

On the karaf console: log:set debug org.openhab.binding.snmp

yes thanks, but since my upgrade from OH 2.4 to OH 2.5 I got no access to console. the RSA fingerprint is incorrect. I delete it on my Mac and allow in org.apache.karaf.shell.cfg all network connections with ip 0.0.0.0 but I get no access …

argh, it seems to be a little problem with a lot of work to resolve it …

so, I got it and still have access to openhab and started the Debug Modus for snmp binding.
For testing I got these configuration (same like a few post before):

snmp.things:

Thing snmp:target:daenetip [ hostname="192.168.xxx.yyy", protocol="v1", community="private" ] {
    Channels:
        Type number : port31    [ oid=".1.3.6.1.4.1.42505.9.2.1.1.0", mode="READ" ]
        Type number : port62    [ oid=".1.3.6.1.4.1.42505.9.2.3.2.0", mode="TRAP" ]
        Type switch : port33    [ oid=".1.3.6.1.4.1.42505.9.2.1.3.0", mode="READ_WRITE", onvalue="1", offvalue="0" ]      
}

snmp.items:

Number      port31      " Pout 31 [%s] "            { channel="snmp:target:daenetip:port31" }
Number      port62      " Trap Pana 62 [%s] "       { channel="snmp:target:daenetip:port62"}
Switch      port33      " Pout 33 [%s] "            { channel="snmp:target:daenetip:port33" }

demo.sitemap:

sitemap demo label= "Demo" {
    Default item= port31
    Default item= port62
    Switch  item= port33
}

I tested and study the Debug log and meanwhile two things works: port31 is refreshed every 60s (default value) and for my SNMP Traps I saw, that my OID for receiving TRAPS is incorrect:

2020-01-25 14:03:41.987 [DEBUG] [ding.snmp.internal.SnmpTargetHandler] - received value 1022 for unknown OID 1.3.6.1.4.1.42505.9.2.3.2, skipping

I corrected this to:

Type number : port62    [ oid="1.3.6.1.4.1.42505.9.2.3.2", mode="TRAP" ]

and it works perfect! Thanks!

But now I have still the little problem with the switch:
When I change status of the Switch port33 on Basic UI, only the Status value change between ON and OFF, but nothings happens on the daenetip Module, the DEBUG log therefor is:

2020-01-25 14:00:50.165 [DEBUG] [ding.snmp.internal.SnmpTargetHandler] - channel snmp:target:daenetip:port33 received unmapped value 0 

I have no mappings to the switch, see the sitemap configuration! But where I got a value to the switch? Basic UI and the events.log says, the switch is ON or OFF?!

By the way, I have additional a question about mapping function:
How can I insert a mapping transformation in the channel configuration of the thing?
I found nothing in the Binding example and so I tried this (seen for the mqtt 2.x binding), but it doesn’t works and there is no debug information:

Type string : pana62    [ oid="1.3.6.1.4.1.42505.9.2.3.2", mode="TRAP", transformationPattern="MAP:snmp.map" ]

This only works for the MQTT binding.

OK, thanks and I think, there is no other way for a transformation!?

Do you have an idea for my switch Problem with ON and OFF (see post 11)?

If a 1.x version binding does not offer transformation, you cannot use it. It would be in the docs.

You can’t use profiles with 1.x bindings, which would otherwise be another way to add transformation.

If you want to actually change the state of an Item, you can of course transform using a second dummy Item and rules.

If you don’t really care what state is in the Item but just want to transform for display purposes, you can do that in the Item label [ ] format section.

Sorry Rossko, but your answer is a little bit “offtopic”.
For SNMP 1 is a possibility to use map transformation, but (when I#m right) not for SNMP 2 (maybe it is possibly, but not documented).

Since Post 4 I use SNMP 2, but I have to install SNMP 1 also, because I’m not able to control the Outputports with SNMP 2 (see Post 11), because there is a problem to send the values ON and OFF to the device.

SNMP 2 is currently for receiving SNMP TRAPS and
SNMP 1 is currently for switching outputports

This solution is not fine and I want to switch completely to SNMP 2 and when there is no mapping function on SNMP 2, I’ll find an other way for that (herefore you gave an example for this with dummy items and rules).

Okay, let’s complete the picture.

If a 2.x version binding does not offer transformation, you cannot use it. It would be in the docs.

You can add profiles to 2.x channels, where they link to Items. The profiles operate on channel state output before it arrives at the Item.
One available profile type is transform.
Sounds good! Only problem is that you can currently only transform to a String type Item, which may not suit you.

I thought for outgoing transformation is the onvalue=“1” and offvalue=“2” within the channel configuration responsible? So that the value “ON” from a switch item is transform to 1 and OFF to 0 in this example.

It’s in the docs. That, then, is the transformation offered by the 2.x SNMP binding.
transformationPattern="MAP:snmp.map"
still isn’t going to work in this binding.

Blockquote
transformationPattern="MAP:snmp.map"
still isn’t going to work in this binding.

I just know, Jan said it a few post before