Cloud9 and snmpjs

I am currently trying to get the basic example code working for the node.js library node-snmpjs in the c9.io development environment.

The example code is here:

https://github.com/wesolows/node-snmpjs or

https://npmjs.org/package/snmpjs

var os = require('os');
var snmp = require('snmpjs');
var logger = require('bunyan');

var log = new logger({
    name: 'snmpd',
    level: 'info'
});

var agent = snmp.createAgent({
    log: log
});

agent.request({ oid: '.1.3.6.1.2.1.1.5', handler: function (prq) {
    console.log("Request received");
    var nodename = os.hostname();
    var val = snmp.data.createData({ type: 'OctetString',
        value: nodename });

    snmp.provider.readOnlyScalar(prq, val);
} });

agent.bind({ family: 'udp4', port: 161 });

I've tried changing the bind port to: parseInt(process.env.PORT)

When I try to execute an snmpget against the address and port that c9 spits out on run, it fails. I've also tried :8080. 8080 is what c9's console output always says is is mapped to process.env.PORT. I've also tried port 80 in the snmpget.

As a fallback, I've also tried making a basic telnet, socket connection using c9 and can't get it to work... It seems like the root problem may be that I don't know what IP and port is being used.

------------------------- EDIT ------------------------

I've tried the following variations on the agent.bind line:

agent.bind({ family: 'udp4', port: parseInt(process.env.PORT), addr: process.env.IP});

and

agent.bind({ family: 'udp4', port: 17000, addr: process.env.IP});

Output:

Your code is running at 'http://node-dev1.thaspius.c9.io'.
Important: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts!
"127.12.254.129:17000"
ex-c9-node47.prod.rhcloud.com
{"name":"snmpd","hostname":"ex-c9-node47.prod.rhcloud.com","pid":32758,"component":"snmp-agent","level":30,"msg":"Bound to 127.12.254.129:17000","time":"2013-07-31T17:59:56.376Z","v":0}

snmpget result:

snmpget -v 2c -c any 127.12.254.129:17000 .1.3.6.1.2.1.1.5
Timeout: No Response from 127.12.254.129:17000.

snmpget -v 2c -c any ex-c9-node47.prod.rhcloud.com:17000 .1.3.6.1.2.1.1.5
Timeout: No Response from ex-c9-node47.prod.rhcloud.com:17000.

snmpget -v 2c -c any node-dev1.thaspius.c9.io:17000 .1.3.6.1.2.1.1.5
Timeout: No Response from node-dev1.thaspius.c9.io:17000.

You likely need to bind your application to a specific IP as well: process.env.IP. According to the snmpjs docs, you can do that using the addr option (i.e.., agent.bind({ family: 'udp4', port: process.env.PORT, addr: process.env.IP })). Also have a look at https://c9.io/site/blog/2013/05/can-i-use-cloud9-to-do-x/ for more info.

As you used "snmp.provider.readOnlyScalar(prq, val);" this function will automatic add instant id ".0" after the OID you set;

So you must run use ".1.3.6.1.2.1.1.5.0": snmpget -v 2c -c any node-dev1.thaspius.c9.io:17000 .1.3.6.1.2.1.1.5.0