Transform map in SNMP String

Hi Guys

I want to monitor the fans in my router, SNMP is pulling the integer ‘1’ which signals Normal.

Cisco has this mapping:

Normal: 1
Warning: 2
Failed: 3-6

So I wrote a transform as below:


2=WARNING
1=OK
3=FAILED
4=FAILED
5=FAILED
6=FAILED
-=undefined

So that I can display if they are all OK in HabPanel, is my syntax correct in the items file? OH2 accepts it. But looking in the console the items dont return ‘OK’, just 1

Group gFANS
!
String C3945_FAN1 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.2:500000:MAP(C3945snmp.map)]" }
String C3945_FAN2 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.3:500000:MAP(C3945snmp.map)]" }
String C3945_FAN3 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.4:500000:MAP(C3945snmp.map)]" }
String C3945_FAN4 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.5:500000:MAP(C3945snmp.map)]" }
String C3945_FAN5 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.6:500000:MAP(C3945snmp.map)]" }


Further, I create a group, gFANS. How can I display OK, as long as all items are displaying OK, or 1. Anyhing else would be a warning or a failed?

In the binding examples, all the <oid> start with a .
Did you try:

String C3945_FAN1 (gFANS)  { snmp="<[192.168.0.254:LAN:.1.3.6.1.4.1.9.9.13.1.4.1.3.2:500000:MAP(C3945snmp.map)]" }

1 Like

Its definitely not the OID, as if you snmpwalk with the . infront it doesnt return a value. The OID is correct as I get the right response

Are you sure to have map transformation installed ?

Yes I do. Its working for other items

Group gFANS
!
String C3945_FAN1 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.2:500000:MAP(C3945snmp.map)]" }
String C3945_FAN2 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.3:500000:MAP(C3945snmp.map)]" }
String C3945_FAN3 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.4:500000:MAP(C3945snmp.map)]" }
String C3945_FAN4 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.5:500000:MAP(C3945snmp.map)]" }
String C3945_FAN5 (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.6:500000:MAP(C3945snmp.map)]" }

Is that exclamation mark intentional?

It was just a delimited I put in the code, its not in the items file :wink:

Does it work without the MAP transform?
Do you have any way to test the binding, ie:“fail” a fan to see if the value changes?

Yes, it works without the map file (how ive got it right now)

It turns ‘1’ for all strings, which is what I’d expect as the router shows all fans operational and OK ie: Value 1

I just want to translate the 1 to OK so I can report it in Hab Panel, something a bit more friendly. And then eventually, use a group to define that if any of them are 3,4,5 then report the group as ‘FAIL’

No ability to fail a fan I’m afraid.

kris@openhab2:/etc/openhab2/items$ snmpwalk -v 1 -c LAN 192.168.0.254 1.3.6.1.4.1.9.9.13.1.4.1.3.1

iso.3.6.1.4.1.9.9.13.1.4.1.3.1 = INTEGER: 1
kris@openhab2:/etc/openhab2/items$

OK, change the MAP to the label:

String C3945_FAN1 "[MAP(C3945snmp.map):%s]" (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.2:500000]" }

In HABPanel use the system provided format

Define you group as such:

Group:String:AND("1","2") gFANS "[MAP(C3945snmp.map):%s]"

If ALL fans are “1” then group value is “1” else group value is “2” and displayed using the MAP

1 Like

Thanks Vincent.

So I would have an items file like so:


/*SNNP Devices */
Group gSNMP
Group gFANS
Group:String:AND("1","2") gFANS "[MAP(C3945snmp.map):%s]"

String C3945_UpTime "C3945 UpTime  [%1$td.%1$tH:%1$tM:%1$tS]" (gSNMP)      { snmp="<[192.168.0.254:LAN:1.3.6.1.2.1.1.3.0:500000]" }
Number C3945_CPU5Min  (gSNMP)                              { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.2.1.58.0:10000]" }
Number C3945_CPUTemp  (gSNMP)                              { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.3.1.3.1:500000]" }
Number C3945_PSUTemp  (gSNMP)                              { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.3.1.3.6:500000]" }
String C3945_FAN1 "[MAP(C3945snmp.map):%s]" (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.2:500000]" }
String C3945_FAN2 "[MAP(C3945snmp.map):%s]" (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.3:500000]" }
String C3945_FAN3 "[MAP(C3945snmp.map):%s]" (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.4:500000]" }
String C3945_FAN4 "[MAP(C3945snmp.map):%s]" (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.5:500000]" }
String C3945_FAN5 "[MAP(C3945snmp.map):%s]" (gFANS)  { snmp="<[192.168.0.254:LAN:1.3.6.1.4.1.9.9.13.1.4.1.3.6:500000]" }








The resulting LOG file. HabPanel shows ‘1’ instead of the group in transformed state

18:49:25.467 [INFO ] [home.event.GroupItemStateChangedEvent] - gFANS changed from NULL to 1 through C3945_FAN1
18:49:25.470 [INFO ] [smarthome.event.ItemStateChangedEvent] - C3945_FAN1 changed from NULL to 1
18:49:25.472 [INFO ] [smarthome.event.ItemUpdatedEvent     ] - Item 'C3945_FAN1' has been updated.
18:49:25.474 [INFO ] [smarthome.event.ItemStateChangedEvent] - C3945_FAN2 changed from NULL to 1
18:49:25.476 [INFO ] [smarthome.event.ItemUpdatedEvent     ] - Item 'C3945_FAN2' has been updated.
18:49:25.478 [INFO ] [smarthome.event.ItemStateChangedEvent] - C3945_FAN3 changed from NULL to 1
18:49:25.479 [INFO ] [smarthome.event.ItemUpdatedEvent     ] - Item 'C3945_FAN3' has been updated.
18:49:25.481 [INFO ] [smarthome.event.ItemStateChangedEvent] - C3945_FAN4 changed from NULL to 1
18:49:25.483 [INFO ] [smarthome.event.ItemUpdatedEvent     ] - Item 'C3945_FAN4' has been updated.
18:49:25.484 [INFO ] [smarthome.event.ItemStateChangedEvent] - C3945_FAN5 changed from NULL to 1
18:49:25.487 [INFO ] [smarthome.event.ItemUpdatedEvent     ] - Item 'C3945_FAN5' has been updated.

And then I saw thisL:


18:50:02.144 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1' on item 'gFANS' with pattern 'MAP(C3945snmp.map):%s': An error occurred while opening file.
18:50:02.148 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1' on item 'C3945_FAN1' with pattern 'MAP(C3945snmp.map):%s': An error occurred while opening file.
18:50:02.152 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1' on item 'C3945_FAN2' with pattern 'MAP(C3945snmp.map):%s': An error occurred while opening file.
18:50:02.155 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1' on item 'C3945_FAN3' with pattern 'MAP(C3945snmp.map):%s': An error occurred while opening file.
18:50:02.158 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1' on item 'C3945_FAN4' with pattern 'MAP(C3945snmp.map):%s': An error occurred while opening file.
18:50:02.161 [WARN ] [.rest.core.item.EnrichedItemDTOMapper] - Failed transforming the state '1' on item 'C3945_FAN5' with pattern 'MAP(C3945snmp.map):%s': An error occurred while opening file.

Remove the:

1 Like

Done, thanks.

See previous logs about the Transform file


kris@openhab2:/etc/openhab2/transform$ ls
3945snmp.map  broadlink.map  de.map  door.map  en.map  readme.txt
kris@openhab2:/etc/openhab2/transform$ cat 3945snmp.map
2=WARNING
1=OK
3=FAILED
4=FAILED
5=FAILED
6=FAILED
-=undefined
kris@openhab2:/etc/openhab2/transform$

Your Item definitions say C3945snmp.map whereas the file is named just 3945snmp.map

1 Like

laughs

Thanks hmerk :smiley: devils in the detail, great spotting!

That fixed it guys! nice work, thank you so much!!!

@vzorglub

I assume now if I write a rule, I could use any of the Transformation map items to check for right?

E.g:



rule "Hardware Warning"
when
    Group gFANS received update
then

    if (gFANS == "Warning") {
         sendBroadcastNotification("Router Fan Warning!")
    }
end






I have noticed your UPTIME for the server
I use this transform that makes it really easy to read:

time.js in the transform folder
Make sure the javascript transform is installed

(function(i) {
    if (i == 'NULL') { return i; }
    if (i == '-') { return 'Undefined'; }
    var val = parseInt(i); // The value sent by OH is a string so we parse into an integer
    var days = 0; // Initialise variables
    var hours = 0;
    var minutes = 0;
    if (val >= 1440) { // 1440 minutes in a days
        days = Math.floor(val / 1440); // Number of days
        val = val - (days * 1440); // Remove days from val
    }
    if (val >= 60) { // 60 minutes in an hour
       hours = Math.floor(val /60); // Number of hours
        val = val - (hours * 60); // Remove hours from val
    }
    minutes = Math.floor(val); // Number of minutes

    var stringDays = ''; // Initialse string variables
    var stringHours = '';
    var stringMinutes = '';
    if (days === 1) {
        stringDays = '1 day '; // Only 1 day so no 's'
    } else if (days > 1) {
        stringDays = days + ' days '; // More than 1 day so 's'
    } // If days = 0 then stringDays remains ''

    if (hours === 1) {
        stringHours = '1 hour '; // Only 1 hour so no 's'
    } else if (hours > 1) {
        stringHours = hours + ' hours '; // More than 1 hour so 's'
    } // If hours = 0 then stringHours remains ''

    if (minutes === 1) {
        stringMinutes = '1 minute'; // Only 1 minute so no 's'
    } else if (minutes > 1) {
        stringMinutes = minutes + ' minutes'; // More than 1 minute so 's'
    } // If minutes = 0 then stringMinutes remains ''

    var returnString =  stringDays + stringHours + stringMinutes
    return returnString.trim(); // Removes the extraneous space at the end

})(input)

Your item:

String C3945_UpTime "C3945 UpTime  [JS(time.js):%s]" (gSNMP)      { snmp="<[192.168.0.254:LAN:1.3.6.1.2.1.1.3.0:500000]" }