net-snmp 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1296 -1296
- package/example/cisco-device-inventory.js +140 -140
- package/example/snmp-get-bulk.js +53 -53
- package/example/snmp-get-next.js +30 -30
- package/example/snmp-get.js +30 -30
- package/example/snmp-inform.js +32 -32
- package/example/snmp-set.js +31 -31
- package/example/snmp-subtree.js +37 -37
- package/example/snmp-table-columns.js +61 -61
- package/example/snmp-table.js +56 -56
- package/example/snmp-tail.js +34 -34
- package/example/snmp-trap.js +32 -32
- package/example/snmp-walk.js +37 -37
- package/example/specify-source-address-and-port.js +41 -41
- package/example/specify-sysuptime-to-inform.js +34 -34
- package/example/specify-sysuptime-to-trap.js +35 -35
- package/index.js +1464 -1464
- package/package.json +43 -39
- package/ref/rfc/v1/rfc1065.txt +1178 -1178
- package/ref/rfc/v1/rfc1066.txt +5042 -5042
- package/ref/rfc/v1/rfc1067.txt +1850 -1850
- package/ref/rfc/v1/rfc1098.txt +1906 -1906
- package/ref/rfc/v1/rfc1155.txt +1234 -1234
- package/ref/rfc/v2c/rfc1908.txt +563 -563
- package/ref/rfc/v2c/rfc2578.txt +2541 -2541
- package/ref/rfc/v2c/rfc3416.txt +1739 -1739
- package/test/varbinds.js +42 -42
@@ -1,140 +1,140 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
3
|
-
|
4
|
-
var snmp = require ("../");
|
5
|
-
var util = require ("util");
|
6
|
-
|
7
|
-
if (process.argv.length < 5) {
|
8
|
-
console.log ("usage: cisco-device-inventory <target> <community> <version>");
|
9
|
-
process.exit (1);
|
10
|
-
}
|
11
|
-
|
12
|
-
var target = process.argv[2];
|
13
|
-
var community = process.argv[3];
|
14
|
-
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
15
|
-
|
16
|
-
function pollDeviceDetails (session, device, pollCb) {
|
17
|
-
console.log ("getting system properties...");
|
18
|
-
|
19
|
-
var oids = ["1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
|
20
|
-
session.get (oids, function (error, varbinds) {
|
21
|
-
if (error) {
|
22
|
-
pollCb (error, null);
|
23
|
-
} else {
|
24
|
-
for (var i = 0; i < varbinds.length; i++) {
|
25
|
-
if (snmp.isVarbindError (varbinds[i])) {
|
26
|
-
console.error (snmp.varbindError (varbinds[i]));
|
27
|
-
return;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
device.name = varbinds[0].value.toString ();
|
32
|
-
device.description = varbinds[1].value.toString ();
|
33
|
-
device.location = varbinds[2].value.toString ();
|
34
|
-
|
35
|
-
pollDeviceInterfaces (session, device, pollCb);
|
36
|
-
}
|
37
|
-
});
|
38
|
-
}
|
39
|
-
|
40
|
-
function pollDeviceDevices (session, device, pollCb) {
|
41
|
-
function pollVlans () {
|
42
|
-
if (device.vlandIds.length > 0) {
|
43
|
-
var vlanId = device.vlandIds.pop ();
|
44
|
-
var session = snmp.createSession (target,
|
45
|
-
community + "@" + vlanId, {version: version});
|
46
|
-
|
47
|
-
console.log ("getting macs for vlan " + vlanId + "...");
|
48
|
-
|
49
|
-
// dot1dTpFdbTable: dot1dTpFdbPort
|
50
|
-
var oid = "1.3.6.1.2.1.17.4.3";
|
51
|
-
session.tableColumns (oid, [2], function (error, table) {
|
52
|
-
if (error) {
|
53
|
-
pollCb (error, null);
|
54
|
-
} else {
|
55
|
-
for (index in table) {
|
56
|
-
var mac = new Buffer (index.split (".")).toString ("hex");
|
57
|
-
var row = table[index];
|
58
|
-
delete table[index];
|
59
|
-
table[mac] = row;
|
60
|
-
}
|
61
|
-
|
62
|
-
device.devices[vlanId] = table;
|
63
|
-
if (device.vlandIds.length > 0) {
|
64
|
-
pollVlans ();
|
65
|
-
} else {
|
66
|
-
delete device.vlandIds;
|
67
|
-
pollCb (null, device);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
});
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
console.log ("getting macs...");
|
75
|
-
|
76
|
-
if (device.vlandIds.length > 0) {
|
77
|
-
pollVlans ();
|
78
|
-
} else {
|
79
|
-
delete device.vlandIds;
|
80
|
-
pollCb (null, device);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
function pollDeviceInterfaces (session, device, pollCb) {
|
85
|
-
console.log ("getting interfaces...");
|
86
|
-
|
87
|
-
// ifTable: ifDescr, ifType, ifPhysAddress
|
88
|
-
session.tableColumns ("1.3.6.1.2.1.2.2", [2, 3, 6], function (error, table) {
|
89
|
-
if (error) {
|
90
|
-
pollCb (error, null);
|
91
|
-
} else {
|
92
|
-
device.intefaces = table;
|
93
|
-
|
94
|
-
pollDeviceVlans (session, device, pollCb);
|
95
|
-
}
|
96
|
-
});
|
97
|
-
}
|
98
|
-
|
99
|
-
function pollDeviceVlans (session, device, pollCb) {
|
100
|
-
console.log ("getting vlans...");
|
101
|
-
|
102
|
-
// vtpVlanTable: vtpVlanType
|
103
|
-
session.tableColumns ("1.3.6.1.4.1.9.9.46.1.3.1", [3], function (error, table) {
|
104
|
-
if (error) {
|
105
|
-
pollCb (error, null);
|
106
|
-
} else {
|
107
|
-
device.vlans = table;
|
108
|
-
device.vlandIds = [];
|
109
|
-
device.devices = {};
|
110
|
-
|
111
|
-
for (index in table) {
|
112
|
-
var match = index.match (/(\d+)$/);
|
113
|
-
if (match) {
|
114
|
-
var vlanId = match[1];
|
115
|
-
var row = table[index];
|
116
|
-
delete table[index];
|
117
|
-
table[vlanId] = row;
|
118
|
-
if (table[vlanId][3] == 1)
|
119
|
-
device.vlandIds.push (vlanId);
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
pollDeviceDevices (session, device, pollCb);
|
124
|
-
}
|
125
|
-
});
|
126
|
-
}
|
127
|
-
|
128
|
-
function pollDevice (session, device, pollCb) {
|
129
|
-
pollDeviceDetails (session, device, pollCb);
|
130
|
-
}
|
131
|
-
|
132
|
-
var session = snmp.createSession (target, community, {version: version});
|
133
|
-
|
134
|
-
pollDevice (session, {}, function (error, device) {
|
135
|
-
if (error) {
|
136
|
-
console.error (error.toString ());
|
137
|
-
} else {
|
138
|
-
console.warn (util.inspect (device, {depth: 3}));
|
139
|
-
}
|
140
|
-
});
|
1
|
+
|
2
|
+
// Copyright 2013 Stephen Vickers
|
3
|
+
|
4
|
+
var snmp = require ("../");
|
5
|
+
var util = require ("util");
|
6
|
+
|
7
|
+
if (process.argv.length < 5) {
|
8
|
+
console.log ("usage: cisco-device-inventory <target> <community> <version>");
|
9
|
+
process.exit (1);
|
10
|
+
}
|
11
|
+
|
12
|
+
var target = process.argv[2];
|
13
|
+
var community = process.argv[3];
|
14
|
+
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
15
|
+
|
16
|
+
function pollDeviceDetails (session, device, pollCb) {
|
17
|
+
console.log ("getting system properties...");
|
18
|
+
|
19
|
+
var oids = ["1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
|
20
|
+
session.get (oids, function (error, varbinds) {
|
21
|
+
if (error) {
|
22
|
+
pollCb (error, null);
|
23
|
+
} else {
|
24
|
+
for (var i = 0; i < varbinds.length; i++) {
|
25
|
+
if (snmp.isVarbindError (varbinds[i])) {
|
26
|
+
console.error (snmp.varbindError (varbinds[i]));
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
device.name = varbinds[0].value.toString ();
|
32
|
+
device.description = varbinds[1].value.toString ();
|
33
|
+
device.location = varbinds[2].value.toString ();
|
34
|
+
|
35
|
+
pollDeviceInterfaces (session, device, pollCb);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
function pollDeviceDevices (session, device, pollCb) {
|
41
|
+
function pollVlans () {
|
42
|
+
if (device.vlandIds.length > 0) {
|
43
|
+
var vlanId = device.vlandIds.pop ();
|
44
|
+
var session = snmp.createSession (target,
|
45
|
+
community + "@" + vlanId, {version: version});
|
46
|
+
|
47
|
+
console.log ("getting macs for vlan " + vlanId + "...");
|
48
|
+
|
49
|
+
// dot1dTpFdbTable: dot1dTpFdbPort
|
50
|
+
var oid = "1.3.6.1.2.1.17.4.3";
|
51
|
+
session.tableColumns (oid, [2], function (error, table) {
|
52
|
+
if (error) {
|
53
|
+
pollCb (error, null);
|
54
|
+
} else {
|
55
|
+
for (index in table) {
|
56
|
+
var mac = new Buffer (index.split (".")).toString ("hex");
|
57
|
+
var row = table[index];
|
58
|
+
delete table[index];
|
59
|
+
table[mac] = row;
|
60
|
+
}
|
61
|
+
|
62
|
+
device.devices[vlanId] = table;
|
63
|
+
if (device.vlandIds.length > 0) {
|
64
|
+
pollVlans ();
|
65
|
+
} else {
|
66
|
+
delete device.vlandIds;
|
67
|
+
pollCb (null, device);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
console.log ("getting macs...");
|
75
|
+
|
76
|
+
if (device.vlandIds.length > 0) {
|
77
|
+
pollVlans ();
|
78
|
+
} else {
|
79
|
+
delete device.vlandIds;
|
80
|
+
pollCb (null, device);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
function pollDeviceInterfaces (session, device, pollCb) {
|
85
|
+
console.log ("getting interfaces...");
|
86
|
+
|
87
|
+
// ifTable: ifDescr, ifType, ifPhysAddress
|
88
|
+
session.tableColumns ("1.3.6.1.2.1.2.2", [2, 3, 6], function (error, table) {
|
89
|
+
if (error) {
|
90
|
+
pollCb (error, null);
|
91
|
+
} else {
|
92
|
+
device.intefaces = table;
|
93
|
+
|
94
|
+
pollDeviceVlans (session, device, pollCb);
|
95
|
+
}
|
96
|
+
});
|
97
|
+
}
|
98
|
+
|
99
|
+
function pollDeviceVlans (session, device, pollCb) {
|
100
|
+
console.log ("getting vlans...");
|
101
|
+
|
102
|
+
// vtpVlanTable: vtpVlanType
|
103
|
+
session.tableColumns ("1.3.6.1.4.1.9.9.46.1.3.1", [3], function (error, table) {
|
104
|
+
if (error) {
|
105
|
+
pollCb (error, null);
|
106
|
+
} else {
|
107
|
+
device.vlans = table;
|
108
|
+
device.vlandIds = [];
|
109
|
+
device.devices = {};
|
110
|
+
|
111
|
+
for (index in table) {
|
112
|
+
var match = index.match (/(\d+)$/);
|
113
|
+
if (match) {
|
114
|
+
var vlanId = match[1];
|
115
|
+
var row = table[index];
|
116
|
+
delete table[index];
|
117
|
+
table[vlanId] = row;
|
118
|
+
if (table[vlanId][3] == 1)
|
119
|
+
device.vlandIds.push (vlanId);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
pollDeviceDevices (session, device, pollCb);
|
124
|
+
}
|
125
|
+
});
|
126
|
+
}
|
127
|
+
|
128
|
+
function pollDevice (session, device, pollCb) {
|
129
|
+
pollDeviceDetails (session, device, pollCb);
|
130
|
+
}
|
131
|
+
|
132
|
+
var session = snmp.createSession (target, community, {version: version});
|
133
|
+
|
134
|
+
pollDevice (session, {}, function (error, device) {
|
135
|
+
if (error) {
|
136
|
+
console.error (error.toString ());
|
137
|
+
} else {
|
138
|
+
console.warn (util.inspect (device, {depth: 3}));
|
139
|
+
}
|
140
|
+
});
|
package/example/snmp-get-bulk.js
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
3
|
-
|
4
|
-
var snmp = require ("../");
|
5
|
-
|
6
|
-
if (process.argv.length < 7) {
|
7
|
-
console.log ("usage: snmp-get-bulk <target> <community> <non-rpts> "
|
8
|
-
+ "<max-reps> <oid> [<oid>...]");
|
9
|
-
process.exit (1);
|
10
|
-
}
|
11
|
-
|
12
|
-
var target = process.argv[2];
|
13
|
-
var community = process.argv[3];
|
14
|
-
|
15
|
-
var nonRepeaters = parseInt (process.argv[4])
|
16
|
-
var maxRepetitions = parseInt (process.argv[5]);
|
17
|
-
|
18
|
-
var oids = [];
|
19
|
-
|
20
|
-
for (var i = 6; i < process.argv.length; i++)
|
21
|
-
oids.push (process.argv[i]);
|
22
|
-
|
23
|
-
var options = {version: snmp.Version2c};
|
24
|
-
|
25
|
-
var session = snmp.createSession (target, community, options);
|
26
|
-
|
27
|
-
session.getBulk (oids, nonRepeaters, maxRepetitions, function (error,
|
28
|
-
varbinds) {
|
29
|
-
if (error) {
|
30
|
-
console.error (error.toString ());
|
31
|
-
} else {
|
32
|
-
// step through the non-repeaters which are single varbinds
|
33
|
-
for (var i = 0; i < nonRepeaters; i++) {
|
34
|
-
if (i >= varbinds.length)
|
35
|
-
break;
|
36
|
-
|
37
|
-
if (snmp.isVarbindError (varbinds[i]))
|
38
|
-
console.error (snmp.varbindError (varbinds[i]));
|
39
|
-
else
|
40
|
-
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
41
|
-
}
|
42
|
-
|
43
|
-
// then step through the repeaters which are varbind arrays
|
44
|
-
for (var i = nonRepeaters; i < varbinds.length; i++) {
|
45
|
-
for (var j = 0; j < varbinds[i].length; j++) {
|
46
|
-
if (snmp.isVarbindError (varbinds[i][j]))
|
47
|
-
console.error (snmp.varbindError (varbinds[i][j]));
|
48
|
-
else
|
49
|
-
console.log (varbinds[i][j].oid + "|" + varbinds[i][j].value);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
});
|
1
|
+
|
2
|
+
// Copyright 2013 Stephen Vickers
|
3
|
+
|
4
|
+
var snmp = require ("../");
|
5
|
+
|
6
|
+
if (process.argv.length < 7) {
|
7
|
+
console.log ("usage: snmp-get-bulk <target> <community> <non-rpts> "
|
8
|
+
+ "<max-reps> <oid> [<oid>...]");
|
9
|
+
process.exit (1);
|
10
|
+
}
|
11
|
+
|
12
|
+
var target = process.argv[2];
|
13
|
+
var community = process.argv[3];
|
14
|
+
|
15
|
+
var nonRepeaters = parseInt (process.argv[4])
|
16
|
+
var maxRepetitions = parseInt (process.argv[5]);
|
17
|
+
|
18
|
+
var oids = [];
|
19
|
+
|
20
|
+
for (var i = 6; i < process.argv.length; i++)
|
21
|
+
oids.push (process.argv[i]);
|
22
|
+
|
23
|
+
var options = {version: snmp.Version2c};
|
24
|
+
|
25
|
+
var session = snmp.createSession (target, community, options);
|
26
|
+
|
27
|
+
session.getBulk (oids, nonRepeaters, maxRepetitions, function (error,
|
28
|
+
varbinds) {
|
29
|
+
if (error) {
|
30
|
+
console.error (error.toString ());
|
31
|
+
} else {
|
32
|
+
// step through the non-repeaters which are single varbinds
|
33
|
+
for (var i = 0; i < nonRepeaters; i++) {
|
34
|
+
if (i >= varbinds.length)
|
35
|
+
break;
|
36
|
+
|
37
|
+
if (snmp.isVarbindError (varbinds[i]))
|
38
|
+
console.error (snmp.varbindError (varbinds[i]));
|
39
|
+
else
|
40
|
+
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
41
|
+
}
|
42
|
+
|
43
|
+
// then step through the repeaters which are varbind arrays
|
44
|
+
for (var i = nonRepeaters; i < varbinds.length; i++) {
|
45
|
+
for (var j = 0; j < varbinds[i].length; j++) {
|
46
|
+
if (snmp.isVarbindError (varbinds[i][j]))
|
47
|
+
console.error (snmp.varbindError (varbinds[i][j]));
|
48
|
+
else
|
49
|
+
console.log (varbinds[i][j].oid + "|" + varbinds[i][j].value);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
});
|
package/example/snmp-get-next.js
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
3
|
-
|
4
|
-
var snmp = require ("../");
|
5
|
-
|
6
|
-
if (process.argv.length < 5) {
|
7
|
-
console.log ("usage: snmp-get-next <target> <community> <version> <oid>");
|
8
|
-
process.exit (1);
|
9
|
-
}
|
10
|
-
|
11
|
-
var target = process.argv[2];
|
12
|
-
var community = process.argv[3];
|
13
|
-
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
14
|
-
|
15
|
-
var oids = [process.argv[5]];
|
16
|
-
|
17
|
-
var session = snmp.createSession (target, community, {version: version});
|
18
|
-
|
19
|
-
session.getNext (oids, function (error, varbinds) {
|
20
|
-
if (error) {
|
21
|
-
console.error (error.toString ());
|
22
|
-
} else {
|
23
|
-
for (var i = 0; i < varbinds.length; i++) {
|
24
|
-
if (snmp.isVarbindError (varbinds[i]))
|
25
|
-
console.error (snmp.varbindError (varbinds[i]));
|
26
|
-
else
|
27
|
-
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
});
|
1
|
+
|
2
|
+
// Copyright 2013 Stephen Vickers
|
3
|
+
|
4
|
+
var snmp = require ("../");
|
5
|
+
|
6
|
+
if (process.argv.length < 5) {
|
7
|
+
console.log ("usage: snmp-get-next <target> <community> <version> <oid>");
|
8
|
+
process.exit (1);
|
9
|
+
}
|
10
|
+
|
11
|
+
var target = process.argv[2];
|
12
|
+
var community = process.argv[3];
|
13
|
+
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
14
|
+
|
15
|
+
var oids = [process.argv[5]];
|
16
|
+
|
17
|
+
var session = snmp.createSession (target, community, {version: version});
|
18
|
+
|
19
|
+
session.getNext (oids, function (error, varbinds) {
|
20
|
+
if (error) {
|
21
|
+
console.error (error.toString ());
|
22
|
+
} else {
|
23
|
+
for (var i = 0; i < varbinds.length; i++) {
|
24
|
+
if (snmp.isVarbindError (varbinds[i]))
|
25
|
+
console.error (snmp.varbindError (varbinds[i]));
|
26
|
+
else
|
27
|
+
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
});
|
package/example/snmp-get.js
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
3
|
-
|
4
|
-
var snmp = require ("../");
|
5
|
-
|
6
|
-
if (process.argv.length < 6) {
|
7
|
-
console.log ("usage: snmp-get <target> <community> <version> <oid>");
|
8
|
-
process.exit (1);
|
9
|
-
}
|
10
|
-
|
11
|
-
var target = process.argv[2];
|
12
|
-
var community = process.argv[3];
|
13
|
-
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
14
|
-
|
15
|
-
var oids = [process.argv[5]];
|
16
|
-
|
17
|
-
var session = snmp.createSession (target, community, {version: version});
|
18
|
-
|
19
|
-
session.get (oids, function (error, varbinds) {
|
20
|
-
if (error) {
|
21
|
-
console.error (error.toString ());
|
22
|
-
} else {
|
23
|
-
for (var i = 0; i < varbinds.length; i++) {
|
24
|
-
if (snmp.isVarbindError (varbinds[i]))
|
25
|
-
console.error (snmp.varbindError (varbinds[i]));
|
26
|
-
else
|
27
|
-
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
});
|
1
|
+
|
2
|
+
// Copyright 2013 Stephen Vickers
|
3
|
+
|
4
|
+
var snmp = require ("../");
|
5
|
+
|
6
|
+
if (process.argv.length < 6) {
|
7
|
+
console.log ("usage: snmp-get <target> <community> <version> <oid>");
|
8
|
+
process.exit (1);
|
9
|
+
}
|
10
|
+
|
11
|
+
var target = process.argv[2];
|
12
|
+
var community = process.argv[3];
|
13
|
+
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
14
|
+
|
15
|
+
var oids = [process.argv[5]];
|
16
|
+
|
17
|
+
var session = snmp.createSession (target, community, {version: version});
|
18
|
+
|
19
|
+
session.get (oids, function (error, varbinds) {
|
20
|
+
if (error) {
|
21
|
+
console.error (error.toString ());
|
22
|
+
} else {
|
23
|
+
for (var i = 0; i < varbinds.length; i++) {
|
24
|
+
if (snmp.isVarbindError (varbinds[i]))
|
25
|
+
console.error (snmp.varbindError (varbinds[i]));
|
26
|
+
else
|
27
|
+
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
});
|
package/example/snmp-inform.js
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
3
|
-
|
4
|
-
var snmp = require ("../");
|
5
|
-
|
6
|
-
if (process.argv.length < 5) {
|
7
|
-
console.log ("usage: snmp-inform <target> <community> <oid>");
|
8
|
-
process.exit (1);
|
9
|
-
}
|
10
|
-
|
11
|
-
var target = process.argv[2];
|
12
|
-
var community = process.argv[3];
|
13
|
-
|
14
|
-
var typeOrOid = process.argv[4];
|
15
|
-
|
16
|
-
var options = {version: snmp.Version2c};
|
17
|
-
|
18
|
-
var session = snmp.createSession (target, community, options);
|
19
|
-
|
20
|
-
session.inform (snmp.TrapType[typeOrOid] || typeOrOid, function (error,
|
21
|
-
varbinds) {
|
22
|
-
if (error) {
|
23
|
-
console.error (error.toString ());
|
24
|
-
} else {
|
25
|
-
for (var i = 0; i < varbinds.length; i++) {
|
26
|
-
if (snmp.isVarbindError (varbinds[i]))
|
27
|
-
console.error (snmp.varbindError (varbinds[i]));
|
28
|
-
else
|
29
|
-
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
});
|
1
|
+
|
2
|
+
// Copyright 2013 Stephen Vickers
|
3
|
+
|
4
|
+
var snmp = require ("../");
|
5
|
+
|
6
|
+
if (process.argv.length < 5) {
|
7
|
+
console.log ("usage: snmp-inform <target> <community> <oid>");
|
8
|
+
process.exit (1);
|
9
|
+
}
|
10
|
+
|
11
|
+
var target = process.argv[2];
|
12
|
+
var community = process.argv[3];
|
13
|
+
|
14
|
+
var typeOrOid = process.argv[4];
|
15
|
+
|
16
|
+
var options = {version: snmp.Version2c};
|
17
|
+
|
18
|
+
var session = snmp.createSession (target, community, options);
|
19
|
+
|
20
|
+
session.inform (snmp.TrapType[typeOrOid] || typeOrOid, function (error,
|
21
|
+
varbinds) {
|
22
|
+
if (error) {
|
23
|
+
console.error (error.toString ());
|
24
|
+
} else {
|
25
|
+
for (var i = 0; i < varbinds.length; i++) {
|
26
|
+
if (snmp.isVarbindError (varbinds[i]))
|
27
|
+
console.error (snmp.varbindError (varbinds[i]));
|
28
|
+
else
|
29
|
+
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
});
|
package/example/snmp-set.js
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
3
|
-
|
4
|
-
var snmp = require ("../");
|
5
|
-
|
6
|
-
if (process.argv.length < 8) {
|
7
|
-
console.log ("usage: snmp-set <target> <community> <version> <oid> <type> "
|
8
|
-
+ "<value>");
|
9
|
-
process.exit (1);
|
10
|
-
}
|
11
|
-
|
12
|
-
var target = process.argv[2];
|
13
|
-
var community = process.argv[3];
|
14
|
-
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
15
|
-
|
16
|
-
var varbinds = [{
|
17
|
-
oid: process.argv[5],
|
18
|
-
type: snmp.ObjectType[process.argv[6]],
|
19
|
-
value: process.argv[7]
|
20
|
-
}];
|
21
|
-
|
22
|
-
var session = snmp.createSession (target, community, {version: version});
|
23
|
-
|
24
|
-
session.set (varbinds, function (error, varbinds) {
|
25
|
-
if (error) {
|
26
|
-
console.error (error.toString ());
|
27
|
-
} else {
|
28
|
-
for (var i = 0; i < varbinds.length; i++)
|
29
|
-
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
30
|
-
}
|
31
|
-
});
|
1
|
+
|
2
|
+
// Copyright 2013 Stephen Vickers
|
3
|
+
|
4
|
+
var snmp = require ("../");
|
5
|
+
|
6
|
+
if (process.argv.length < 8) {
|
7
|
+
console.log ("usage: snmp-set <target> <community> <version> <oid> <type> "
|
8
|
+
+ "<value>");
|
9
|
+
process.exit (1);
|
10
|
+
}
|
11
|
+
|
12
|
+
var target = process.argv[2];
|
13
|
+
var community = process.argv[3];
|
14
|
+
var version = (process.argv[4] == "2c") ? snmp.Version2c : snmp.Version1;
|
15
|
+
|
16
|
+
var varbinds = [{
|
17
|
+
oid: process.argv[5],
|
18
|
+
type: snmp.ObjectType[process.argv[6]],
|
19
|
+
value: process.argv[7]
|
20
|
+
}];
|
21
|
+
|
22
|
+
var session = snmp.createSession (target, community, {version: version});
|
23
|
+
|
24
|
+
session.set (varbinds, function (error, varbinds) {
|
25
|
+
if (error) {
|
26
|
+
console.error (error.toString ());
|
27
|
+
} else {
|
28
|
+
for (var i = 0; i < varbinds.length; i++)
|
29
|
+
console.log (varbinds[i].oid + "|" + varbinds[i].value);
|
30
|
+
}
|
31
|
+
});
|