Getting network use using SNMP - Error initializing binding

Hi,

I’m trying to get network IN/OUT bandwidth usage displayed on the OpenHAB installation (Rasperry Pi). I’ve figured out that these items should give me the information I need to be able to calculate a rough estimate (using this formula) and the OIDs associated with ifInOctets, ifOutOctets and ifSpeed on my Airport Express.

Number WiFiInOctets "Wifi IN Octets [%d]" <network> (Network) { snmp="<[10.0.1.1:public:.1.3.6.1.2.1.2.2.1.10.1:10000]" }
Number WiFiOutOctets "Wifi OUT Octets [%d]"  <network> (Network){ snmp="<[10.0.1.1:public:.1.3.6.1.2.1.2.2.1.16.1:10000]" }
Number WiFiIFSpeed "Wifi IF Speed [%d]" <network>  (Network) { snmp="<[10.0.1.1:public:.1.3.6.1.2.1.2.2.1.5.1:10000]" }

Number EthernetInOctets "Ethernet IN Octets [%d]"  <network> (Network) { snmp="<[10.0.1.1:public:.1.3.6.1.2.1.2.2.1.10.2:10000]" }
Number EthernetOutOctets "Ethernet OUT Octets [%d]" <network>  (Network){ snmp="<[10.0.1.1:public:.1.3.6.1.2.1.2.2.1.16.2:10000]" }
Number EthernetIFSpeed "Ethernet IF Speed [%d]"  <network> (Network) { snmp="<[10.0.1.1:public:.1.3.6.1.2.1.2.2.1.5.2:10000]" }

However, the log file is filling up with these messages:

2015-12-13 15:04:20.288 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request
2015-12-13 15:04:30.292 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request
2015-12-13 15:04:30.296 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request
2015-12-13 15:04:30.300 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request
2015-12-13 15:04:30.303 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request
2015-12-13 15:04:30.306 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request
2015-12-13 15:04:30.309 [ERROR] [.o.b.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request

and I get nothing displayed in the sitemap (no number that is, the icon and item names are displayed)

Any ideas? I appreciate all the help I can get on this.

Fredrik

How have you configured the binding? Does the permissions in the Pi allow you to use the port you’ve configured - this is often not the case as Linux locks down ports below 1024 (from memory).

Hi Chris,

Thank you for your response. The configuration looks like this:

################################ SNMP Binding #########################################
#
# Listening Port (optional, defaults to '162')
snmp:port=162

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

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

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

Please note that the SNMP is not on the local linux box, but on an Airport Express. Thats why I thought the non-privileged port discussion in the manual did not apply…?

No - this still applies. The remote is obviously a remove (??), but the SNMP binding opens the port that you specify in your configuration (ie 162) so that it can communicate with the remote(s). So, if your Pi doesn’t allow this port to be opened, then it won’t work.

Try changing the port to something higher than 1024 and see if hat helps.

The binding UDP / TCP port 162 is for inbound SNMP traps.

Would be a nice addition to the binding if the SNMP trap port could be disabled as not everyone will need it and are happy to work with gets and sets only.

The outgoing SNMP requests will be on UDP port 161, if running on a linux build the easiest way to check that the outgoing message is generated would be to run a tcpdump.

tcpdump udp port 161

I used the snmptrapd to try to capture something (at all) from the device, and added this forward to the snmptrapd configuration:

disableAuthorization yes
forward default udp:10.0.1.47:2048

but that did not work. Any way of just forwarding connections made on 10.0.1.47:2048
to 10.0.1.1:161?

(or should it be 10.0.1.1:162?)

I tried using
sudo iptables -t nat -A PREROUTING -p tcp --dport 2048 -j DNAT --to 10.0.1.1:161
sudo iptables -A FORWARD -d 10.0.1.1 -p tcp --dport 161 -j ACCEPT
sudo sysctl net.ipv4.ip_forward=1

but that did not do it (with snmp:port=2048).

Any ideas on how to get snmp requests sent by openhab on port 2048 redirected to 10.0.1.1 (which is my router)?

Fredrik

Hello @Fredrik_Karlsson

Sorry for the late reply I have not been on for a few days. You should be forwarding the inbound 162 trap traffic, 161 is for outbound SNMP requests which should work without any translation / forwarding.

In my openhab.cfg SNMP section there is no configuration option for outbound SNMP port, therefore this should always be port 161, otherwise you would have to either reconfigure all receiving systems default SNMP port or translate all your outbound traffic, both of which is messy and unnecessary.

As I mentioned earlier it would be a nice feature for this binding if inbound traps could be disabled.

once you get the octets how does one convert it to KBps/MBps for display on the sitemap?

can you give an example of what you are receiving as data? items/sitemap etc

Frame label="Internet Speed" icon="network" {
	Text item=EthernetInOctets label="Internet Download [%df]" icon="network"		
	Text item=EthernetOutOctets label="Internet Upload [%df]" icon="network"		
}	

Number EthernetInOctets “IN [%.1f]” { snmp="<[10.1.1.1:public:.1.3.6.1.2.1.2.2.1.10.1:10000]" }
Number EthernetOutOctets “OUT [%.1f]” { snmp=">[10.1.1.1:public:.1.3.6.1.2.1.2.2.1.16.1:10000]" }

which gives me 4259103375f in the widget instead of 45.5kbs or whatever that OID is… looking

Hi,

Ok, I never got this to work myself. Glad to see you succeeded getting
anything out of a router this way I will certainly look into this myself
too.
But what you get out of the OID is ontet NUMBER, not the number of ontets.
So, what you need to do is compare what you get with what you got the last
time you pulled the OID, then relate that to the time interval between the
two times and the interface speed (another OID).

Please have a look here:

Fredrik

Thread revival, I have been using the SNMP binding for some time, I have configured it to get the IN/OUT octets from a number of network devices which works but so far am not doing anything with the data apart from displaying on the screen.

What persistence would be best and how would I go about graphing the data?

Not sure about editing iptables, and the wiki wasn’t helpful.

I ended up getting SNMP working on a raspberry pi using authbind. The solution is based on this post (http://superuser.com/questions/710253/allow-non-root-process-to-bind-to-port-80-and-443)

Essentially:

  1. Install authbind
sudo apt-get install authbind
  1. Configure it to grant access to port 161.
sudo touch /etc/authbind/byport/161
sudo chmod 777 /etc/authbind/byport/161
  1. Start openhab via authbind specifying --deep argument:
authbind --deep /opt/openhab/start.sh

Hope that helps someone. or makes it to the wiki :sunglasses:

1 Like

SNMP Binging works on my openhab.b5 (binding-snmp1 - 1.9.0.b5) Windows 10
but does not work in openhab.last release (binding-snmp1 - 1.10.0.SNAPSHOT) CentOS

[ERROR] [ab.binding.snmp.internal.SnmpBinding] - SNMP: snmp not initialised - aborting request

have you fixed the permission issue mentioned above, for example like stated by @Steven_Conway ?

Yes, if I comment the string User=openhab, then SNMP binding works fine.
I’m doing something wrong… :slight_smile:

[Unit]
Description=Open Home Automation Bus
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
GuessMainPID=yes
ExecStart=/usr/bin/authbind --deep /opt/openhab/current/start.sh
ExecStop=/usr/bin/kill -SIGINT $MAINPID
ExecStopPost=
User=openhab
Restart=on-failure
WorkingDirectory=/opt/openhab/current

[Install]
WantedBy=multi-user.target

to me this looks like a permission issue. When you comment the User line, who is the owner of the openhab process ? Who is the owner when you uncomment it ?

root of course

what does

ls -l /etc/authbind/byport/

show ?

-rwxrwxrwx 1 openhab openhab 0 Feb 18 12:34 161