[SOLVED] SNMPget does not work

Hello community

after hours of testing and no progress or clue how to proceed, I have to seek external help.
Simple Task: I want to request a few OID’s with the service snmp.

I activated snmp in the addons.cfg:

binding = snmp1,[...]

I created a new file items/snmp.items:

    //WAN
    Number fw_traffic_wan_in  "Traffic WAN IN  [%d]"  { snmp="<[10.0.3.1:privateSNMP:1.3.6.1.2.1.2.2.1.10.1:10000]" }
    Number fw_traffic_wan_out  "Traffic WAN OUT  [%d]"  { snmp="<[10.0.3.1:privateSNMP:1.3.6.1.2.1.2.2.1.16.1:10000]" }
    //DMZ
    Number fw_traffic_dmz_in  "Traffic DMZ IN  [%d]"  { snmp="<[10.0.3.1:privateSNMP:1.3.6.1.2.1.2.2.1.10.2:10000]" }
    Number fw_traffic_dmz_out  "Traffic DMZ OUT  [%d]"  { snmp="<[10.0.3.1:privateSNMP:1.3.6.1.2.1.2.2.1.16.2:10000]" }
    //LAN
    Number fw_traffic_lan_in  "Traffic LAN IN  [%d]"  { snmp="<[10.0.3.1:privateSNMP:1.3.6.1.2.1.2.2.1.10.3:10000]" }
    Number fw_traffic_lan_out  "Traffic LAN OUT  [%d]"  { snmp="<[10.0.3.1:privateSNMP:1.3.6.1.2.1.2.2.1.16.3:10000]" }

The Binding seems to work already:

    openhab> bundle:list
    230 │ Active   │  80 │ 1.12.0                 │ openHAB SNMP Binding
    openhab> logout

But I neither get any snmp related output in the openhab.log or the events.log
only the confirmation for the installation:

2018-11-20 17:51:21.858 [thome.event.ExtensionEvent] - Extension 'binding-snmp1' has been installed.

SNMP on the destination-device is activated and is working for v1 and v2c:

    >: snmpwalk -v1 -c privateSNMP 10.0.3.1 1.3.6.1.2.1.2.2.1.10.1
    iso.3.6.1.2.1.2.2.1.10.1 = Counter32: 4267948229
    >: snmpwalk -v2c -c privateSNMP 10.0.3.1 1.3.6.1.2.1.2.2.1.10.1
    iso.3.6.1.2.1.2.2.1.10.1 = Counter32: 4268019919

Does anyone have a suggestion what could be wrong or where to look, to start polling?!

Many thanks in advance.

your configs look good. By the way: Which OH2 release are you running?

can you try to enable TRACE on org.openhab.binding.snmp using the OH2 console to see if something useful comes up?

log:set TRACE org.openhab.binding.snmp

Sorry I forgot the version: I’m running the latest

: dpkg --list | grep openhab
ii openhab2 2.3.0-1 all openhab2
ii openhab2-addons 2.3.0-1 all openhab2-addons

And I’m running it on a Debian 9.6.

And while I activated the Tracing the output remains empty ( I changed the intervall in the snmp.items)

openhab> log:set TRACE org.openhab.binding.snmp
openhab> log:list
Logger                                             │ Level
───────────────────────────────────────────────────┼──────
org.openhab.binding.snmp                           │ TRACE
openhab>

And still no additional snmp-related output in events.log and openhab.log.

I may have been wrong about the correct name of the bundle

can you check from console?

bundle:list -s |grep snmp

edit: no, it’s correct. i installed in a test system and it’s org.openhab.binding.snmp

very strange… does the bundle have an Active state?

I did a reboot, just in case… But yes it’s still active.

openhab> bundle:list -s |grep snmp
231 │ Active   │  80 │ 1.12.0                 │ org.openhab.binding.snmp

edit: Does it start polling instantly on your testsystem after adding items?

check please in your console the following:

bundle:list -s |grep action

do you get any results? (you shouldn’t, unless you have installed any of them)

I do have installed two and i get them as response:

openhab> bundle:list -s |grep action
220 │ Active   │  80 │ 1.12.0                 │ org.openhab.action.telegram
229 │ Active   │  80 │ 1.12.0                 │ org.openhab.action.mail
1 Like

I have no idea what could be wrong
your configs look (very) good to me and they should have worked…

I checked on github and there is no open issue with the snmp binding…

It’s very strange that it doesn’t produce any log output also…

Maybe someone else has some more ideas… I am out of them for now :frowning:

1 Like

No problem. The confirmation that the config is fine and it should work was good for the start.
Thanks for your answers, maybe someone else finds the missing “whatever” :confused:

run the following test:

*.items

String snmplabs_ip "snmplabs.com Public IP [%s]" { snmp="<[demo.snmplabs.com:public:.1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0:10000]" }

check the state in console:

openhab> items list |grep snmplabs_ip
snmplabs_ip (Type=StringItem, State=195.218.254.0, Label=snmplabs.com Public IP, Category=null)

TRACE log output:

21:08:00.690 [INFO ] [smarthome.event.ExtensionEvent       ] - Extension 'binding-snmp1' has been installed.
21:08:00.720 [INFO ] [ab.core.service.AbstractActiveService] - SNMP Refresh Service has been started
21:18:05.550 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'snmp.items'
21:20:22.395 [INFO ] [del.core.internal.ModelRepositoryImpl] - Refreshing model 'snmp.items'
21:20:23.350 [INFO ] [smarthome.event.ItemStateChangedEvent] - snmplabs_ip changed from NULL to 195.218.254.0
21:21:03.133 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Item 'snmplabs_ip' is about to be refreshed
21:21:03.135 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - SNMP: Send PDU 104.236.166.95/161 GET[requestID=0, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = Null]]
21:21:03.339 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Received PDU from '104.236.166.95/161' 'RESPONSE[requestID=1478765319, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = 195.218.254.0]]'
21:21:13.141 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Item 'snmplabs_ip' is about to be refreshed
21:21:13.142 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - SNMP: Send PDU 104.236.166.95/161 GET[requestID=0, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = Null]]
21:21:13.345 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Received PDU from '104.236.166.95/161' 'RESPONSE[requestID=1478765321, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = 195.218.254.0]]'
21:21:23.149 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Item 'snmplabs_ip' is about to be refreshed
21:21:23.153 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - SNMP: Send PDU 104.236.166.95/161 GET[requestID=0, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = Null]]
21:21:23.359 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Received PDU from '104.236.166.95/161' 'RESPONSE[requestID=1478765323, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = 195.218.254.0]]'
21:21:33.163 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Item 'snmplabs_ip' is about to be refreshed
21:21:33.169 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - SNMP: Send PDU 104.236.166.95/161 GET[requestID=0, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = Null]]
21:21:33.373 [DEBUG] [hab.binding.snmp.internal.SnmpBinding] - Received PDU from '104.236.166.95/161' 'RESPONSE[requestID=1478765325, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.4.24.4.1.1.195.218.254.0.0.255.255.255.0.0.0.0.0 = 195.218.254.0]]'

The ONLY difference that I see is that your OID doesn’t start with a dot (.) … but this shouldn’t be the problem

I dropped my previous file and I only used your proposed string.
And it seems to work:

openhab> items list |grep snmplabs_ip
snmplabs_ip (Type=StringItem, State=195.218.254.0, Label=snmplabs.com Public IP, Category=null)

But I only get this line as output in events.log (no DEBUG)

2018-11-20 20:53:34.404 [vent.ItemStateChangedEvent] - snmplabs_ip changed from NULL to 195.218.254.0

I added two of my previous items again (added the dots, just in case):

Number fw_traffic_wan_in  "Traffic WAN IN  [%d]"  { snmp="<[10.0.3.1:privateSNMP:.1.3.6.1.2.1.2.2.1.10.1:10000]" }
Number fw_traffic_wan_out  "Traffic WAN OUT  [%d]"  { snmp="<[10.0.3.1:privateSNMP:.1.3.6.1.2.1.2.2.1.16.1:10000]" }

results in this:

openhab> items list |grep traffic
fw_traffic_wan_in (Type=NumberItem, State=NULL, Label=Traffic WAN IN, Category=null)
fw_traffic_wan_out (Type=NumberItem, State=NULL, Label=Traffic WAN OUT, Category=null)

monitor his “brother”, the openhab.log :slight_smile:

Nothing in there too. Last entry is two weeks old.

then there is something else wrong with your system… it’s not normal to have a 2 week old openhab.log…

have you modified/customized your logging configuration in any way? (to send logs to separate files etc)

stop OH2 service, check free disk space, clean old log files, check permissions in directory, start OH2

Yep openhab.log was owned by root, so openhab couldn’t write into that file. Now one step further:

2018-11-20 21:33:15.461 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'snmp' of item 'fw_traffic_wan_in' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: snmp binding configuration must consist of four/five/six [config=java.util.regex.Matcher[pattern=<\[([0-9.a-zA-Z/]+):(v1|v2c|v3):([0-9.a-zA-Z]+):([0-9.a-zA-Z]+):([0-9]+):(.*)?\] region=0,60 lastmatch=]] or five/six parts [config=java.util.regex.Matcher[pattern=>\[([0-9.a-zA-Z]+):([0-9.a-zA-Z/]+):(v1|v2c|v3):([0-9.a-zA-Z]+):([0-9.a-zA-Z]+):([0-9]+)\] region=0,60 lastmatch=]]
        at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:52) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:400) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:369) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:229) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:435) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:301) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:139) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:227) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:291) ~[?:?]
        at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
2018-11-20 21:33:15.466 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'snmp' of item 'fw_traffic_wan_out' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: snmp binding configuration must consist of four/five/six [config=java.util.regex.Matcher[pattern=<\[([0-9.a-zA-Z/]+):(v1|v2c|v3):([0-9.a-zA-Z]+):([0-9.a-zA-Z]+):([0-9]+):(.*)?\] region=0,60 lastmatch=]] or five/six parts [config=java.util.regex.Matcher[pattern=>\[([0-9.a-zA-Z]+):([0-9.a-zA-Z/]+):(v1|v2c|v3):([0-9.a-zA-Z]+):([0-9.a-zA-Z]+):([0-9]+)\] region=0,60 lastmatch=]]
        at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:52) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:400) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:369) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:229) ~[?:?]
        at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:435) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:301) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:139) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:227) ~[?:?]
        at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:291) ~[?:?]
        at org.eclipse.smarthome.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]

And with this hint I found that the snmp item can be given the snmp version

pattern=<\[([0-9.a-zA-Z/]+):(v1|v2c|v3):([0-9.a-zA-Z]+):([0-9.a-zA-Z]+):([0-9]+):(.*)?\

But that also didn’t help. But this:

([0-9.a-zA-Z]+)

For my original community (privateSNMP_address) that regex can’t match.I shortend it in my post, because of privacy and no expectation that would matter.

//WAN
Number fw_traffic_wan_in  "Traffic WAN IN  [%d]"  { snmp="<[10.0.3.1:v2c:private:.1.3.6.1.2.1.2.2.1.10.1:10000]" }
Number fw_traffic_wan_out  "Traffic WAN OUT  [%d]"  { snmp="<[10.0.3.1:v2c:private:.1.3.6.1.2.1.2.2.1.16.1:10000]" }

Now I created a community without “_” and I get at least something more:


2018-11-20 21:55:05.998 [DEBUG] [ab.binding.snmp.internal.SnmpBinding] - Item 'fw_traffic_wan_out' is about to be refreshed
2018-11-20 21:55:05.998 [DEBUG] [ab.binding.snmp.internal.SnmpBinding] - SNMP: Send PDU 10.0.3.1/161 GET[requestID=0, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.2.2.1.16.1 = Null]]
2018-11-20 21:55:05.998 [DEBUG] [ab.binding.snmp.internal.SnmpBinding] - Item 'fw_traffic_wan_in' is about to be refreshed
2018-11-20 21:55:05.999 [DEBUG] [ab.binding.snmp.internal.SnmpBinding] - SNMP: Send PDU 10.0.3.1/161 GET[requestID=0, errorStatus=Success(0), errorIndex=0, VBS[1.3.6.1.2.1.2.2.1.10.1 = Null]]

Nice! we have progress…
but… we have no responses from your firewall… hmm

is he listening to the default snmp port? (can you test the snmpwalk the OID again to test?)

Finally. I / we got it:

openhab> items list | grep traffic
fw_traffic_wan_in (Type=NumberItem, State=40090010, Label=Traffic WAN IN, Category=null)
fw_traffic_wan_out (Type=NumberItem, State=2296833091, Label=Traffic WAN OUT, Category=null)
fw_traffic_dmz_in (Type=NumberItem, State=1714339479, Label=Traffic DMZ IN, Category=null)
fw_traffic_dmz_out (Type=NumberItem, State=2740568648, Label=Traffic DMZ OUT, Category=null)
fw_traffic_lan_in (Type=NumberItem, State=3170220, Label=Traffic LAN IN, Category=null)
fw_traffic_lan_out (Type=NumberItem, State=2366700, Label=Traffic LAN OUT, Category=null)

Conclusion: Don’t use special characters in the community string :face_with_raised_eyebrow:

Many thanks for your help and patience.

1 Like

Hi @tmcgee,

I’m interested in what you’ve achieved with this, could you share your further details. Either PM me or post here. Rules, Items and Things. At present I’m using Cacti to graph my devices, but using OH and storing data in InfluxDB with Grafana publishing the graphs would be a better solution. So any pointers would be very helpful to me at least.

Thanks

Garry

Hej @Maximo

sure I post you my final working settings:

services/addons.cfg
[...]
binding = snmp1,[...]
[...]
items/snmp.items
//WAN1
Number fw_traffic_wan1_in  "Traffic WAN1 IN  [%d]"  { snmp="<[10.0.3.1:v2c:private:.1.3.6.1.2.1.31.1.1.1.6.2:60000]" }
Number fw_traffic_wan1_in_diff "wan1indiff" (system)
Number fw_traffic_wan1_out  "Traffic WAN1 OUT  [%d]"  { snmp="<[10.0.3.1:v2c:private:.1.3.6.1.2.1.31.1.1.1.10.2:60000]" }
Number fw_traffic_wan1_out_diff "wan1outdiff" (system)

Remember no special characters in the community :sweat_smile: only one of these characters ([0-9.a-zA-Z]+)

For my current (Fortigate) firewall I currently just found an increasing counter for the traffic per interface in the MIB. But I wanted to display the current throughput, Therefore I had to create a rule to calculate the difference.

rules/calc_traffic.rules
rule "fw traffic dmz in updated, calculate difference"
when
    Item fw_traffic_dmz_in received update
then
    var float currentStateValue = (fw_traffic_dmz_in.state as DecimalType).floatValue
    var float previousStateValue = (fw_traffic_dmz_in.previousState.state as DecimalType).floatValue
    var float diff = (currentStateValue - previousStateValue)/8
//    logInfo("test", "dmz_in_diff: {} ({} : {})", diff, currentStateValue, previousStateValue)
    fw_traffic_dmz_in_diff.postUpdate(diff)
end

rule "fw traffic dmz out updated, calculate difference"
when
    Item fw_traffic_dmz_out received update
then
    var float currentStateValue = (fw_traffic_dmz_out.state as DecimalType).floatValue
    var float previousStateValue = (fw_traffic_dmz_out.previousState.state as DecimalType).floatValue
    var float diff = (currentStateValue - previousStateValue)/8

I also use Grafana and influxDB and that’s my current state:

I hope that helps you.

2 Likes

was it worth it @tmcgee ? are you satisfied with the performance?

Very nice work by the way! I love the grafana dashboard that you created!

my first reaction would be also to go to a tool like cacti instead of going through the trouble of integrating all these items in OH2, process them with rules, persist their state and then graph them.

This is just another example that there are no limitations to what one can achieve with openHAB!