--- a/example.coffee Wed Mar 27 15:56:00 2013 +0100
+++ b/example.coffee Wed Mar 27 16:00:05 2013 +0100
@@ -19,6 +19,9 @@
typeStr[snmpTypes.EndOfMibView] = 'EndOfMibView'
typeStr[snmpTypes.PDUBase] = 'PDUBase'
+###
+Converts TimeTicks value to easy-to-use structure.
+###
convertTimeTicks = (v) ->
intDiv = (a, b) -> Math.floor(a / b)
msec = v % 100
@@ -36,10 +39,12 @@
secs: secs
msecs: msec
-
+###
+Processes SNMP result value.
+###
processVarBind = (vb) ->
rv =
- oid: vb.oid.reduce (x,y) -> x+"."+y
+ oid: "." + vb.oid.reduce (x,y) -> x+"."+y
value: vb.value
type: vb.type
typeStr: typeStr[vb.type] ? 'Unknown'
@@ -47,6 +52,9 @@
rv.timeTicks = convertTimeTicks(vb.value)
rv
+###
+Creates SNMP session and retrieves values for the supplied OIDs.
+###
snmpget = (opts, cb) ->
sess = new snmp.Session(opts)
res = []
@@ -67,6 +75,7 @@
cb(res)
snmpgetOne 0
+# Example OIDs (some intentionally wrong).
oids = [
'.1.3.6.1.2.1.1.1',
'.1.3.6.1.2.1.1.1.0',
@@ -85,4 +94,7 @@
oids: oids
abortOnError: true
+###
+Do the work
+###
snmpget(opts, (res) -> console.log res)