SNMP and msg.oid

We are using the SNMP node. It is working ok.
We are sending SNMP get to multiple ports on a device so need to send multiple oid's
We verified that we can provide a list of oid ( separated by commas) in the SNMP OID Properties .

However when we try to pass a msg.oid (created from a function), we are not able to get it to work.
The msg.oid format we are sending loolks like this:
Each oid is seperated with a comma. It must be some formatting issue. Any advise would be appreciated.

"1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.1,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.2,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.3,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.4,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.5,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.6,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.7,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.8,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.9,1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.10,"

Do you get an error? If not then what does happen?
Does a Catch node show an error?

Try taking the trailing comma off the end of the string.

Hi Colin
msg.oid we pass in includes the " ...." and the trailing , ( comma)
so we verified that that is the problem as we 'copy and pasted' without the " ...." and the trailing , ( comma) to the SNMP properties OID .

The question is then: how do we change the function msg.oid so when it passes in the msg.oid , that the " ...." and the trailing , ( comma) are removed

Since you have not posted the function it is impossible to say. Copy/paste the function text here. When pasting use the </> button at the top of the forum entry window.

[Edit] Also show us what you see in a debug node showing what it going into the function and another showing what is coming out.

Hi Colin
I narrowed it down . We need to be able to remove the " " and the ending , (comma)

Here is the function which we are using to pass the msg.oid to the SNMP node

let oid = '';

for(let i = 1; i<= 52; i++){
    
    oid = oid.concat(`1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.${i},`);
}

msg.oid = oid;

return msg;

The quotes are not actually present in the string. They are added when you display it in order to identify it as a string. To remove the trailing comma, switch it round so it appears at the start and miss it off the first time. Also it is often easier to use + rather than concat. So something like

let oid = ""
let terminator = ""
for(let i = 1; i<= 52; i++){
  oid += `${terminator}1.0.8802.1.1.2.1.5.32962.1.2.1.1.1.${i}`
  terminator = ","
}
msg.oid = oid
return msg

The reason it is easier to code a solution that misses it off the first time rather than the last time is that it easy to do something different the first time, it is much more difficult to do something different the last time.

Hi Colin,
Thank you for the explanation and suggestions. It makes sense and i learned something.
The SNMP node is nice. FYI, we had used the EXEC node to do the SNMP get ( not sure why we got on that crazy train)- the SNMP node is much easier to deal with.

Personally I don't use node red with snmp, I use Telegraf to pick it up and send it straight to influxdb.

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