-
Notifications
You must be signed in to change notification settings - Fork 5
/
README
75 lines (57 loc) · 2.28 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
snmp for node.js
i hate writing doco. the code below shows how it works though. it
queries all the devices on 192.168.1.0/24 for their interface info. in
my environment it was about to find 26 devices which had 3500 interfaces
in just under 15 seconds.
var snmp = require('snmp');
var mgr = snmp.createManager( { community: 'public', version: 2, retries: 10 } );
var agents = { };
process.on('exit', function() {
console.log(agents);
console.log(Object.keys(agents).length);
});
var oid2mib = {
'1.3.6.1.2.1.2.2.1.2': 'ifDescr',
'1.3.6.1.2.1.2.2.1.7': 'ifAdminStatus',
'1.3.6.1.2.1.2.2.1.8': 'ifOperStatus',
'1.3.6.1.2.1.31.1.1.1.1': 'ifName',
'1.3.6.1.2.1.31.1.1.1.15': 'ifHighSpeed',
'1.3.6.1.2.1.31.1.1.1.18': 'ifAlias',
'1.3.6.1.2.1.31.1.1.1.6': 'ifHCInOctets',
'1.3.6.1.2.1.31.1.1.1.10': 'ifHCOutOctets',
'1.3.6.1.2.1.31.1.1.1.7': 'ifHCInUcastPkts',
'1.3.6.1.2.1.31.1.1.1.11': 'ifHCOutUcastPkts',
'1.3.6.1.2.1.31.1.1.1.8': 'ifHCInMulticastPkts',
'1.3.6.1.2.1.31.1.1.1.12': 'ifHCOutMulticastPkts',
'1.3.6.1.2.1.31.1.1.1.9': 'ifHCInBroadcastPkts',
'1.3.6.1.2.1.31.1.1.1.13': 'ifHCOutBroadcastPkts',
'1.3.6.1.2.1.2.2.1.13': 'ifInDiscards',
'1.3.6.1.2.1.2.2.1.19': 'ifOutDiscards',
'1.3.6.1.2.1.2.2.1.14': 'ifInErrors',
'1.3.6.1.2.1.2.2.1.20': 'ifOutErrors'
};
function ml(err, res, agent) {
if (err)
return;
if (typeof(agents[agent]) === 'undefined')
agents[agent] = { };
for (var i = 0; i < res.length; i++) {
var o = res[i].oid.split('.');
var idx = o.pop();
var oid = o.join('.');
if (typeof(agents[agent][idx]) === 'undefined')
agents[agent][idx] = { };
agents[agent][idx][oid2mib[oid]] = res[i].value.toString();
}
}
function m(agent) {
mgr.get(agent, '1.3.6.1.2.1.1.3.0', function(e, r) {
if (e)
return;
for (var k in oid2mib) {
mgr.bulkGet(agent, k, function (e, r) { ml(e,r,agent); });
}
}, { retries: 3 });
}
for (i = 1; i < 255; i++)
m('192.168.1.' + i);