-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (56 loc) · 1.85 KB
/
main.js
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
var snmp = require ("net-snmp");
// Default options
var varbinds = [
{
oid: "1.3.6.1.2.1.1.5.0",
type: snmp.ObjectType.OctetString,
value: new Buffer ("host1"),
}, {
oid: "1.3.6.1.2.1.1.6.0",
type: snmp.ObjectType.OctetString,
value: new Buffer ("host1"),
}
];
console.log('---- THE VARBINDS TO SET ---------');
console.log(varbinds);
console.log('----------------------------------');
var options = {
port: 5000,
retries: 1,
timeout: 5000,
transport: "udp4",
trapPort: 162,
version: snmp.Version1
};
var session = snmp.createSession ("localhost", "any", options);
session.set(varbinds, function (error, varbinds) {
//console.log(session)
if (error) {
console.error ("ERROR in SET OPR:>>>>" + error.toString ());
} else {
for (var i = 0; i < varbinds.length; i++) {
console.log('VAR=====' + varbinds[i].oid + "===" + varbinds[i].value );
// for version 1 we can assume all OIDs were successful
//console.log (varbinds[i].oid + "|" + varbinds[i].value);
// for version 2c we must check each OID for an error condition
if (snmp.isVarbindError (varbinds[i]))
console.error ("error>>" + snmp.varbindError (varbinds[i]));
else
console.log ("Info>>" + varbinds[i].oid + "|" + varbinds[i].value);
}
}
});
/*
var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
session.get (oids, function (error, varbinds) {
if (error) {
console.error (error);
} else {
for (var i = 0; i < varbinds.length; i++)
if (snmp.isVarbindError (varbinds[i]))
console.error (snmp.varbindError (varbinds[i]))
else
console.log (varbinds[i].oid + " = " + varbinds[i].value);
}
});
*/