wrapAsync confusion

We are trying to make use of the net-snmp node package in Meteor for talking to some physical devices and getting back information. We have tried following a number of examples but seem to have problems getting a return value from the call.

A simple portion of our code looks like the following inside Meteor.methods:

import snmp from 'net-snmp';

Meteor.methods({
  snmpGet: function snmpGet(ip, oids, inCommunity) {
    check(ip, String);
    check(oids, [String]);
    check(inCommunity, Match.Maybe(String));

    const community = (typeof inCommunity === 'undefined') ?
      Meteor.settings.private.snmp.public : inCommunity;
    const session = snmp.createSession(ip, community);
    const getResult = {};
    const sessionGetSync = Meteor.wrapAsync(session.get);

    try {
      const result = sessionGetSync(oids);
      getResult.success = true;
      getResult.varbinds = result;
    } catch (error) {
      getResult.success = false;
      getResult.error = error;
    }
    session.close();
    return getResult;
  },
});

Every time we call this it returns an error of “TypeError: this.simpleGet is not a function” and I am guessing it is because we use the snmp import to create the session, which in turn is what we are passing to the wrapAsync function. I have tried a number of variations to get this working, hoping somebody can provide me with the answer.

Thanks!

Your import statement looks okay. Can you try binding to the session context:

const sessionGetSync = Meteor.wrapAsync(session.get, session);

First, thanks for the quick response! I have tried that already and it yields the error: “Error: argument is not a valid OID string”.

Well, that sounds like it’s working and isn’t being passed what you think is being passed. Have you tried hard coding the oids or console.loging what’s coming in via the call?

1 Like

I did check this and was passing in the oids array with [ ‘.1.3.6.1.4.1.41112.1.4.7.1.2’ ]. However, going on your feel that it was wrong simply removed the starting ‘.’ and it passed through fine and is working! Thank you very much!

1 Like