# SNMP and msg.oid

**URL:** <https://discourse.nodered.org/t/snmp-and-msg-oid/59311>\
**Category:** General\
**Created:** [3 March 2022 13:57 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311 "2022-03-03T13:57:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [3 March 2022 13:57 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/1 "2022-03-03T13:57:52Z")

</div>

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,"

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2022 14:44 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/2 "2022-03-03T14:44:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [3 March 2022 15:09 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/3 "2022-03-03T15:09:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2022 15:15 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/4 "2022-03-03T15:15:12Z")

</div>

> [@sweetwater](#):
>
> how do we change the function

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.

---

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [3 March 2022 19:00 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/5 "2022-03-03T19:00:40Z")

</div>

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

```auto
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;

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 March 2022 20:36 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/6 "2022-03-03T20:36:44Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [4 March 2022 13:17 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/7 "2022-03-04T13:17:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 March 2022 13:50 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/8 "2022-03-04T13:50:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 May 2022 13:50 UTC](https://discourse.nodered.org/t/snmp-and-msg-oid/59311/9 "2022-05-03T13:50:36Z")

</div>

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