Snmp data visualization

Can you try this please

node.warn(`payload: ${JSON.stringify(msg.payload)}`)
node.warn(`typeof data: ${typeof msg.payload[0].value.data}`)
if (typeof msg.payload[0].value.data === "object") {
    msg.payload[0].value = Buffer.from(msg.payload[0].value.data).toString()
}
return msg;

and if that doesn't do it

node.warn(`payload: ${JSON.stringify(msg.payload)}`)
node.warn(`typeof value: ${typeof msg.payload[0].value}`)
if (typeof msg.payload[0].value === "object") {
    msg.payload[0].value = Buffer.from(msg.payload[0].value.data).toString()
}
return msg;

Hi, i did the probe but the result is the same with the first function
WhatsApp Image 2023-11-29 at 14.44.47_832b9896
the same happens in the text file
and with second function there is an error

WhatsApp Image 2023-11-29 at 14.52.07_8b5f4d93

I want tell you that in one machine I could go to the old snmp node version 0.0.25 and inmediatly start work ok, really the problem is clear.
I appreciate your time and effort and I'm really grateful, is not nescessary that you lose your time in this problem. If you want to do some more probes I can put your functions in the flow an probe it, if not, is all right.
Unfortunately I can't do changes over your functions because I don't have the knowledge.
Thank you

Late to the thread - but if you want to change the value to a string then you can try

if (typeof msg.payload[0].type === 4) {
    msg.payload[0].value = msg.payload[0].value.data.toString()
}
return msg;

I would really like to get to the bottom of why my function doesn't work. It certainly can be made to word, it is just a matter of better understanding the data format, then you won't have to worry about being stuck with an old version which may fail to work at some point. Can you try this please.

node.warn(`payload in: ${JSON.stringify(msg.payload)}`)
node.warn(`typeof data: ${typeof msg.payload[0].value.data}`)
if (typeof msg.payload[0].value.data === "object") {
    node.warn("Modifying")
    msg.payload[0].value = Buffer.from(msg.payload[0].value.data).toString()
} 
node.warn(`payload out: ${JSON.stringify(msg.payload)}`)
return msg;

I would expect to see something like this

image

Thank you! Never is late, worst is neverā€¦

I have probed a lot of functions that simulated works ok, the problem is when I use SNMP NODE + FUNCTION (string conversion) + Write to file node

Iā€™m not a programmer, Iā€™m only an user, I understand somethings but I donā€™t have the knowledge for introduce changes like this. Really I donā€™t know what is happening.

But I found a solution using an old SNMP NODE version, from v2.0.0 to v0.0.25 and problem was solved.

Thank you for your response

You can see the code that was commented out when I "fixed" it for version 2

The reason for the change was that the underlying snmp returns a unique snmp object type - that other users were expecting - and by my changing just the octet string type it broke the object they were expecting, so it was decided to just return the native object as returned from the library so the user could process it later as required.

1 Like

HI, I understand the advantages of solve it using the newest version
this are the results and the flow, function1 have your code, like you can see, in text file value appear in raw mode

WhatsApp Image 2023-11-30 at 09.33.07_89e83db8

I don't know if yuo can understand excactly what is explainig dceejay, I don't know if he is eplaining the problem or the solution

Thank you, I understand that version 2.0.0 of snmp node contains changes that requires a modification in the way that value must be showed. But in the code that you have posted, you show a solution or the source of he problem?
I followed the link in giihub, I can download the code,, is this a version of snmp node? can I install it?
sorry by my ignorance.

@dceejay or anyone else, looking at my function and contents of the incoming payload can anyone understand how typeof msg.payload[0].value.data is undefined?

as I said the snmp lib returns a weird non-standard object so yeah I don't know as I haven't dug into it (not using snmp for anything right now) - but is probably related to that.

It makes it rather difficult to deal with the data if it cannot be accessed like a normal object.

@cef can you try this, which attempts to sanitise the data

msg.payload = JSON.parse(JSON.stringify(msg.payload))
node.warn(`payload in: ${JSON.stringify(msg.payload)}`)
node.warn(`typeof data: ${typeof msg.payload[0].value.data}`)
if (typeof msg.payload[0].value.data === "object") {
    node.warn("Modifying")
    msg.payload[0].value = Buffer.from(msg.payload[0].value.data).toString()
} 
node.warn(`payload out: ${JSON.stringify(msg.payload)}`)
return msg;

why turn it back into a Buffer ? It's a string at the end of the day.
And if it's the .value that is the issue then maybe set msg.payload[0].foo instead - ie a new different property

Is it? typeof says it is undefined.

snmp data type 4 is an OctetString (also shown as the tstr property). so just bytes as a string. So in theory it's safe to turn into a string... BUT when I did that it caused other (real power) snmp users to have problems and so I "fixed" it to send what they expect and let them handle it.

Hi Colin, tomorow I will probe it and Iā€™ll tell you

Hi Colin
congratulations...it is working!!!
I don't know really what you are changing, I know what you were looking for but is working

Thank you for your time!!!

Can I clarify something? On the system with the problem do all messages have this format, or do some have the old. The purpose of the if clause in the code is to determine which of those it is, so is not necessary if it does not need to handle both types of messages. Also now it is working you can remove the node.warn() lines which were for diagnostic output to help work out what is going on.

Also, in order to get to the simplest solution, could you try, as suggested by @dceejay just this in the function

msg.payload[0].value = msg.payload[0].value.toString()
return msg

and if that doesn't work

msg.payload[0].value = msg.payload[0].value.data.toString()
return msg

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.