Snmp data visualization

Hello, I'm new here and I'm not a profesional using Node Red, but I is very useful for my project.
I have installed in several computers but it is not working well in all of them.
I can't see the same result using the same flow chart in different machines.
Is working properly with Node.JS V14.18.0 and V13.10.1 but it is not working in same way in V18.17.1 and in other machine with same version that is working good, V14.18.0
I don't know if could be a windows configuration problem

I send a read command to an OID using snmp protocol and the equipment respond, I can see the message and save it simultaneously in a text file

This is the main function

'''
[
var msgList =;
var letterList = [
"1.3.6.1.3.2016.5.1.1",
"1.3.6.1.3.2016.5.1.84"];
for (var i = 0; i < 2; i++){msgList.push({oid:letterList[i]});
}
return [msgList]; ]

'''''
Correct message show right value:

[{"oid":"1.3.6.1.3.2016.5.1.1","type":4,
"value": "235.4 ",
"tstr":"OctetString"}]

wrong message shows a text result in Value:

[{"oid":"1.3.6.1.3.2016.5.1.1","type":4,
"value": {"type":"Buffer","data":[48,46,48]},
tstr":"OctetString"}]

If somebody can help me I will be grateful.

Thank you

Welcome to the forum @cef

How exactly are you doing that? Have you installed a contrib node to do it?

Hi Colin

I have installed snmp

Flow chart is following

They work very good in some machines an In others don’t work

This is the message that is ok and is saved in PMx.txt

[{"oid":"1.3.6.1.3.2016.5.1.1","type":4,"value":"235.4","tstr":"OctetString"}]

And this the message that is wrong, saved in the txt file too.

I don’t know if it is clear.

Thank you!

Claudio

[{"oid":"1.3.6.1.3.2016.5.1.1","type":4,"value":{"type":"Buffer","data":[48,46,48]},"tstr":"OctetString"}]

In [48,46,48] 48 is the character "0" and 46 is "." so that is "0.0". Why you get the two different formats I don't know. You can extract the value in either case using a function containing

if (typeof msg.payload[0].value.data == "object") {
    msg.payload = Buffer.from(msg.payload[0].value.data).toString()
} else {
    msg.payload = msg.payload[0].value
}
return msg;

Test flow:

[{"id":"87cd3c2546c2cc60","type":"inject","z":"bdd7be38.d3b55","name":"Buffer","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"oid\":\"1.3.6.1.3.2016.5.1.1\",\"type\":4,\"value\":{\"type\":\"Buffer\",\"data\":[48,46,48]},\"tstr\":\"OctetString\"}]","payloadType":"json","x":270,"y":2320,"wires":[["3f190d0a5fac66ff"]]},{"id":"d33e1bd6c42680d3","type":"debug","z":"bdd7be38.d3b55","name":"debug 107","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":2340,"wires":[]},{"id":"3f190d0a5fac66ff","type":"function","z":"bdd7be38.d3b55","name":"Convert to string","func":"if (typeof msg.payload[0].value.data == \"object\") {\n    msg.payload = Buffer.from(msg.payload[0].value.data).toString()\n} else {\n    msg.payload = msg.payload[0].value\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":2340,"wires":[["d33e1bd6c42680d3"]]},{"id":"65e66957b8d01da8","type":"inject","z":"bdd7be38.d3b55","name":"String","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"oid\":\"1.3.6.1.3.2016.5.1.1\",\"type\":4,\"value\":\"235.4\",\"tstr\":\"OctetString\"}]","payloadType":"json","x":270,"y":2380,"wires":[["3f190d0a5fac66ff"]]}]

SNMP is a tricky old thing and many of the outputs can be values much larger than JavaScript can easily handle natively. Without knowing the actual schema in use, not really possible to say if that is the case here but it wouldn't surprise me and in which case, a buffer might be the safest output.

But I'm no real expert on SNMP so I could be wrong.

Hi Julian

Flow chart is the following

They work very good in some machines an In others don’t work

This is the message that is ok and is saved in PMx.txt

[{"oid":"1.3.6.1.3.2016.5.1.1","type":4,"value":"235.4","tstr":"OctetString"}]

And this the message that is wrong, saved in the txt file too.

[{"oid":"1.3.6.1.3.2016.5.1.1","type":4,"value":{"type":"Buffer","data":[48,46,48]},"tstr":"OctetString"}]

I don’t know if it is clear.

For me it must to be something in windows configuration because all parameters are same in all machines.

Thank you!

You can create a UInt8Array from the buffer and then decode that to text.

if (msg.payload[0].value.type === 'Buffer') {
  let utf8decoder = new TextDecoder()
  let x = new Uint8Array(msg.payload[0].value.data)
  node.warn( utf8decoder.decode(x) ) 
}

The above is just an estimate, untested. But running manually against the same array as your buffer, it seems to give the right answer.

Thank you Colin

I Will use it and I will tell you results.

Thank you again!

Best Regards

Claudio

Hello, unfortunately it is not working, I used your function in the middle fo my flow chart before node "message payload" but I dont see changes, Value is showed in a wrong way.
If you have other idea I will probe it. thank you

Hi, I tried to use your function but something looks like wrong, The error is

Really I can't fix it, if you have an idea I will probe it

thank you

Add debug nodes showing what is going into and out of the new function node and post the results here.

TextDecoder should be available (will need to look into that!)

But you could try:

if (msg.payload[0]?.value?.type === 'Buffer') {
  msg.payload[0].value.type = 'String'
  msg.payload[0].value.data = Buffer.from(msg.payload[0].value.data || []).toString('utf8')
}
return msg
1 Like

What version of Node.js are you running? Though as far as I can tell, it has been part of Node.js since v11.

It certainly worked in my testing but I only tested in the browser. Perhaps it isn't permitted in the Node.js VM that Node-RED wraps around function code. If so, a work-around would be to define a function in the globals section of your settings.js file that did the conversion. Then you could global.get the function in your function node.

There is something odd about this data. Can anyone explain why, if I feed this:

[
    {
        "oid": "1.3.6.1.3.2016.5.1.1",
        "type": 4,
        "value": {
            "type": "Buffer",
            "data": [
                48,
                46,
                48
            ]
        },
        "tstr": "OctetString"
    }
]

into a debug node I get:

image

and if I feed it into a function node containing

msg.payload = msg.payload[0].value
return msg

I get

image

Test flow:

[{"id":"6633146530757655","type":"inject","z":"bdd7be38.d3b55","name":"Data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"oid\":\"1.3.6.1.3.2016.5.1.1\",\"type\":4,\"value\":{\"type\":\"Buffer\",\"data\":[48,46,48]},\"tstr\":\"OctetString\"}]","payloadType":"json","x":250,"y":2580,"wires":[["3ae58fc1eeb26868","1e14d5d37987454e"]]},{"id":"3ae58fc1eeb26868","type":"debug","z":"bdd7be38.d3b55","name":"debug 109","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":410,"y":2520,"wires":[]},{"id":"1e14d5d37987454e","type":"function","z":"bdd7be38.d3b55","name":"function 4","func":"msg.payload = msg.payload[0].value\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":2580,"wires":[["9cb491b557e59cbb"]]},{"id":"9cb491b557e59cbb","type":"debug","z":"bdd7be38.d3b55","name":"debug 113","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":2580,"wires":[]}]

I think there is some logic in the debug code that serialises data for transmission over ws to the debug view in that exact format. It sees the data with an object with props type: "Buffer" and value: [..] that it then knows to visualises it as a buffer. I think it is an unfortunate side effect of how that node presents it's values.

Hi everybody
First of all, thank you for their help, really I don't have enought knowledge for probe every thing that you have proposed me, I have probe somethings and did not work.
I could see though debug node that value is in raw data format, If I choose string data is showed in right way.

Then, problem exist when I save data in a txt file.
I think that could be the way that snmp node is delivering data to the other nodes.
Actually I have 7 differents machines with node-red and same flows running, 3 are ok and the rest work bad, using same version in one machine works ok and in other not.
But I have seen one difference, this is the version of snmp node

One mochine with Version 2.0.0 don't work, and other wit Version 0.0.20 work.

I need to know, in order to probe is this can be the problem, how I can change this version 2.0.0 by 0.0.20,

Thank you

2.00 is the latest version of the node, and has a warning v2 Breaking Change

v2 has a breaking change in that the single snmp node no longer tries to stringify an octet string type (04). This makes it consistent with the other nodes in this bundle. this means the user now has to convert to a string if required but has better control of how they wish to do that.

I assume then that you have older versions on your other machines. The best bet might be to upgrade them all to the same version and then fix your flows, to accommodate this change.

HI, thank you
Yes I have checked and I have old version in the machines that are working ok, I'm only need snmp V1, then if changes have new solutions for V2 it is not useful in this moment.
Really I can't change, in spite of all suggestion, the way to save a txt file like string, only I see raw data.
If I can go to latest versions of snmp node I will get the solution.
If can help me to do that I will very gratefull
Thank you
If you can help me to do this change I will be gratefull

You really ought to work out why the proposed solutions do not work, by adding debug nodes showing what is going into the function and what is coming out (you were asked to do that earlier but have not). Try this, and if it does not work then show us what the debug nodes show.

if (typeof msg.payload[0].value == "object") {
    msg.payload[0].value = Buffer.from(msg.payload[0].value.data).toString()
}
return msg;

It works for me on the data that you posted.

Excuseme Colin

this is the new flow

Here is the result using new function proposed

image
In debug 1 I can chosse see value in a string format, this is at the output of SNMP node

image