SNMP binding confusion


(bob) #1

Platform information:

  • Hardware: CPUArchitecture/RAM/storage VM 4 core, 2gb ram 32gb HDD
  • OS: what OS is used and which version ubuntu 18.04
  • Java Runtime Environment: which java platform is used and what version 1.8.0_191
  • openHAB version: Openhab2 2.4.0-1

I’m trying to get the snmp binding working but getting a bit confused with what needs configured where.

My end goal is to know the state of a PDU socket in Basic UI (with a light or indicator) and to make an on/off button and reboot button for the socket.

so far i have established from the command line on the Ubuntu machine running my Openhab install I can achieve these goals using the following commands

snmpwalk -v1 -c public 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3

this returns

iso.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3 = INTEGER: 2

(interger 2 tells me the socket is off )

so i can run
snmpset -v1 -c private 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3$outlet integer 1

this switches the socket on.

if I run
snmpset -v1 -c private 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3$outlet integer 3

this would immediately power cycle the socket.

could someone give me a rough order of how best to approach this. so far i’m just reading stuff about snmp and going round in circles.

i have reads the snmp bindings page about 100 times so far, pls don’t refer me to that.

Thanks

Bob


(anonymous.one) #2

Take a look at something I wrote up, the good news is you are so close to having what you want: Leveraging SNMP to detect your mobile device

What I think you need is the Map add-on and setup a .map file with the following in it:

1=ON
2=OFF

Then just slap :MAP(filename.map) to your item and OH should then translate the integers into the ON/OFF you want in Basic UI.


(bob) #3

Thanks for your help, but I think I’m a lot further away than you realize :confused:

The 2 lines below which I currently run from the Ubuntu prompt, from my understanding i need to put these in the snmp.cfg file
1. snmpwalk -v1 -c public 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3

2. snmpset -v1 -c private 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3$outlet integer 2

do you know what syntax I would need to use for these in the snmp.cfg i have attempted below

1. snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3]"

I’m looking at the snmp binding guide but there is no example of snmpwalk so do I just format it the same as the GET example they use? Also what about the . before the OID? In my ubuntu command I don’t use that, is it specifically required for the openhab binding or is it just specific to the example OIDs they happen to be using?
in this status request there is no integer from the command line so can I omit the last :value in my snmp.cfg?

I’m slightly more confident with the 2 below than the one above?

2. snmp=">[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:$outlet integer 2]"
2. snmp=">[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:$outlet integer 1]"

my binding is installed but still doesn’t show in the paperui list so im guessing there is still something wrong.


(anonymous.one) #4

Ahhh you need to move your work out of snmp.cfg as that is for the system settings like SNMP timeout, SNMP community, etc.

Add your work into an items file, in my doc I’m just pulling information from the device so I use the ‘<’ and the end of that before you end the line do a ‘>’ to push commands to the device.


(bob) #5

yes initially i had them in the items file (although undoubtedly with the wrong syntax) , then last night i thought maybe they go directly in the cfg file

anyway… I have now moved them back out of the cfg file. it looks like this, is that all that is required in the snmp.cfg?

# Listening Port (optional, defaults to '162')
port=1600
# 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 

at what point should i see the snmp binding show up in the paperui ? it is definitely installed, but not displayed here.

image

are these the only files that i need to configure ?

/etc/openhab2/services/snmp.cfg
/etc/openhab2/items/snmp.items
/etc/openhab2/sitemaps/snmp.sitemap

or do i also need to configure

/etc/snmp/snmp.conf
/etc/snmp/snmpd.conf

Are there any other files I need to configure on the openhab box that I haven’t listed above?
At this stage i’m not talking about the binding port workaround.

thanks


(anonymous.one) #6

This is my SNMP.cfg

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

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

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

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

As for PaperUI, you have to always keep in mind that if it is a 1.x binding, chances are it isn’t going to show up in PaperUI; also confirmed on mine it doesn’t show up.

Just for grins post up the item so we can confirm things are correct in that. And you also need the following file created:
/etc/openhab2/transform/newfilename.map <-- This will require the transformation binding ‘map’ to be installed. And a small change to the item line will be needed to call the map file when it sends/receives the SNMP values.

Once installed and the map file is created you need to map the number to corresponding ON/OFF. Post the map file lines when you post your item line.


(bob) #7

Thanks for taking the time to reply,

i will spend some time trying to make it work with the information you have given and come back to post configs when i get completely lost again. I feel like i have enough info to digest and work on for a while.

Appreciate your help
Bob


(bob) #8

here is my items file that i have being working on today with no success.

I’ve been googling for background reading material but i struggle to find relevant info that i’m able to apply to this situation.

//  THE WORKING COMMANDS THAT TURN THE SWITCH on, off OR GIVE THE current status FROM THE UBUNTU CONSOLE ON THE MACHINE RUNNING OPENHAB. 
//  snmpset -v1 -c private 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3$outlet integer 1
//  snmpset -v1 -c private 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3$outlet integer 2
//  snmpwalk -v1 -c public 10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3


//MY FAILED ATTEMPTS to convert the commands above to something openhab can use
//Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:$outlet integer 2:MAP(snmp.map)] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:$outlet integer 1:MAP(snmp.map)]"}
//Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:MAP(snmp.map)] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:outlet integer 2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:$outlet integer 1] "}
//Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:MAP(snmp.map)] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1] "}
//Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1600:MAP(snmp.map)] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1] "}
//Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1600] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1] "}
//Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.10.72.23.51 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1600] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1:MAP(snmp.map)] "}

//MY CURRENT ATTEMPT
Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1:MAP(snmp.map)] "}


//OTHER PEOPLES EXAMPLES OF DIFFERENT SNMP LINES
//Switch Switch_PortEnable03 "Port 03 [%s]" <port> (ports)	{ snmp="<[192.168.0.140:private:.1.3.6.1.2.1.2.2.1.8.3:10000:MAP(SwitchState.map)] >[OFF:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.3:2] >[ON:192.168.0.140:private:.1.3.6.1.2.1.2.2.1.7.3:1]" }
//Switch Switch_POEEnable2 "PoE WiFi Enable [%s]"  { snmp="<[192.168.2.111:public:.1.3.6.1.4.1.4526.11.16.1.1.1.3.1.2:10000] >[OFF:192.168.2.111:private:.1.3.6.1.4.1.4526.11.16.1.1.1.3.1.2:2] >[ON:192.168.2.111:private:.1.3.6.1.4.1.4526.11.16.1.1.1.3.1.2:1]" }
//Switch phone1_ap1_24    "phone1 Association Ap1"    (phone1V, gPersist)    { snmp="<[192.168.1.2:public:.1.3.6.1.4.1.9.9.273.1.2.1.1.16.random.generated.values:10000:MAP(assoc.map)]"}
//Number AR_Printer_1 		"AR Black Toner [%d%%]"		<_4250>		(AR_Printer)	{ snmp="<[192.168.1.101:public:1.3.6.1.2.1.43.11.1.1.9.1.1:60000:JS(K_4250.js)]"}
//Switch Strip1_plug2 “Strip 1 Outlet 2 [%s] " { snmp=”<[10.10.121.6:public:.1.3.6.1.4.1.4779.1.3.5.6.1.4.2.1.2:1500] >[ON:10.10.121.6:private:.1.3.6.1.4.1.4779.1.3.5.6.1.4.2.1.2:1] >[OFF:10.10.121.6:private:.1.3.6.1.4.1.4779.1.3.5.6.1.4.2.1.2:0]"}



//THE SYNTAX INSTRUCTIONS THAT GET THROWN UP IN THE ERROR MSG IN THE LOG FILE
//  [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,57 lastmatch=]] 
//  [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,57 lastmatch=]]

I’m also not sure if the :1600 i have in some of my lines is supposed to signify the port number? there is no reference to this in the command i’m sending directly to the PDU.
in the other examples in my items file they have used 10000, 60000, 1500

does it matter if the :MAP(snmp.map) is at the end of my line or in the middle?

Below is my 2 tries at snmp.map I’m not sure which of the 2 is correct if the PDU needs “$outlet integer 1” from the command line I’m thinking it must need it from openhab as well?

$outlet integer 1=ON
$outlet integer 2=OFF
-=undefined


1=ON
2=OFF
-=undefined

thanks

bob


(anonymous.one) #9

Lets keep breaking out the problem, instead of also making the switch turn the outlet on and off; lets try to just pull the state of the outlet and get that up and working.

Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:10000:MAP(snmp.map)]"}

You should be able to watch your event log or the Basic UI and make manual changes that OH picks up and translates correctly from the map transformation.

Also something odd and not sure of (due to not having access to this hardware), looking into the OID you provided it doesn’t fully resolve to anything. But when I do find 1.3.6.1.4.1.318.1.1.12.3.3.1.1.4 as a valid OID for rPDUOutletControlOutletCommand. Site that I used to lookup the MIB tree - http://www.oidview.com/mibs/318/PowerNet-MIB.html


(bob) #10

thank you once again!! I now have this switch fully working. :smile:
1 thing i still don’t understand though, what is the significance of the 10000 what does it do?

ip : community string : 10000 : MAP command

my next project is to replicate this to many switches and also to sort them into groups and make a suitable gui.

thank you so much for your help.


(anonymous.one) #11

Excellent to hear, may I also suggest you post your solution for any future reader who needs a working example . :wink:

Reviewing the doco for the SNMP binding, the 10000 is the update interval for SNMP GET vs a SET/TRAP. It can probably change to other msec values, in my case it works.

It took me a while to get a grasp of Habpanel, but it’s a very flexible at making the GUI how you would like and have made group buttons to control many item state changes vs having to tap the dashboard multiple times.


(bob) #12

so to summarize from beginning to end I think this outlines everything I did to make my first SNMP switch.

-install OS
-install java
-install openhab
-create samba shares
-install snmp binding (it shows as installed in paperui but you don’t see any other indication that its installed or working like you do with 2.0 bindings.)
-created the following files in these folders. (you don’t need to name them all snmp.xxxx i just did this for easy identification.)

/etc/openhab2/services/snmp.cfg
/etc/openhab2/items/snmp.items
/etc/openhab2/sitemap/snmp.sitemap
/etc/openhab2/transform/snmp.map

the contents of my files are as follows.

snmp.cfg

port=1600
community= public
timeout= 1500
retries=3

snmp.items

Switch Lswitchenable "Lswitch [%s]" {snmp="<[10.72.23.51:public:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:10000:MAP(snmp.map)] >[OFF:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:2] >[ON:10.72.23.51:private:.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.3:1]"}

snmp.sitemap

sitemap snmp label="rebooting by SNMP" {

Frame label="snmp testing" icon="settings" {
        Switch item=Lswitchenable label="Lswitch[]" mappings=[ON="ON",OFF="OFF"]
}
}

snmp.map


1=ON
2=OFF
-=undefined

hope this helps someone.

thanks

Bob