Setting msg array converts content/int to string

I'm trying to send an SNMP set command to a PDU (Power Distribution Unit), but the SNMP set node is rejecting because my varbind is not numbers.

The UI has a selection box where the user can pick the outlet they want to reboot.
The function takes that number and adds it to the first part of the OID to form the completed OID that the PDU will recognize.
The Value is also supposed to be an integer of 3 for the PDU reboot command.

In debug, the array is formed correctly, but the data types are string, which is where I'm thinking the SNMP node is rejecting.

How can I convert the OID to a number, and have the msg.varbind set keep it as a number and not convert it?

Regarding function structure;
The prior flow steps have the user select an outlet number in the UI, then an alert makes them manually re-enter the number to avoid typos or accidental reboots of the wrong equipment. The IF branch is just to verify that the same outlet selected is the outlet the user confirmed.
Once the user selects an outlet, a different function uses that selected number to form the OID and send it to the SNMP Get node, where it returns the OutletName, which is displayed on the popup for the user to confirm.
So the function to form the OID works for SNMP Get, but I'm thinking SNMP get accepts strings, while SNMP set does not.

var outlet = flow.get('SelectedOutlet');
var outletName = flow.get('OutletName');

var value = 3;
if (outlet == msg.payload){
    var oidfrag = "1.3.6.1.4.1.3808.1.1.3.3.3.1.1.4";
    var oid = oidfrag + "." + outlet;
    msg.host = flow.get('PDU1host');
    msg.community = flow.get('PDU1set');
    msg.varbinds = [{"oid":""+oid+"","type":"OctetString","value":""+value.toFixed(0)+""}]
    msg.payload = outletName;
    return [msg, null];
}

msg.host = " ";
msg.community = " ";
msg.varbinds = " ";
msg.payload = outletName;
msg.outlet = outlet;
return [null, msg];

Not sure you need all those extra "

can you try
msg.varbinds = [{"oid":oid,"type":"OctetString","value":value.toFixed(0)}]
Though the value may need to be a buffer, in which case try
msg.varbinds = [{"oid":oid,"type":"OctetString","value":Buffer.from(value.toFixed(0))}]

Won't this do?
msg.varbinds = [{oid: oid, type: "OctetString", value: value.toFixed(0)}]

Thanks for the help.

Both constructions worked.

Turns out the problem was the type; it needed to be Integer instead of OctetString.
The error returned so fast every time, that I thought it was coming from the SNMP node without it actually sending (the far end is extremely low bandwidth). It must have been sending the Set, and the PDU kicked it back, so the node was returning the error directly from the hardware.

However...now I know how to build a buffer, so that's pretty cool.

Also, it does indeed work like Colin's version without all the quotes as well.

1 Like

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