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]" }
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”
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)
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
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]]
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.
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 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:
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!