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 CHANGED
@@ -1,1296 +1,1296 @@
1
-
2
- # net-snmp
3
-
4
- This module implements version 1 and 2c of the [Simple Network Management
5
- Protocol (SNMP)][SNMP].
6
-
7
- This module is installed using [node package manager (npm)][npm]:
8
-
9
- npm install net-snmp
10
-
11
- It is loaded using the `require()` function:
12
-
13
- var snmp = require ("net-snmp");
14
-
15
- Sessions to remote hosts can then be created and used to perform SNMP requests
16
- and send SNMP traps or informs:
17
-
18
- var session = snmp.createSession ("127.0.0.1", "public");
19
-
20
- var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
21
-
22
- session.get (oids, function (error, varbinds) {
23
- if (error) {
24
- console.error (error);
25
- } else {
26
- for (var i = 0; i < varbinds.length; i++)
27
- if (snmp.isVarbindError (varbinds[i]))
28
- console.error (snmp.varbindError (varbinds[i]))
29
- else
30
- console.log (varbinds[i].oid + " = " + varbinds[i].value);
31
- }
32
-
33
- // If done, close the session
34
- session.close ();
35
- });
36
-
37
- session.trap (snmp.TrapType.LinkDown, function (error) {
38
- if (error)
39
- console.error (error);
40
- });
41
-
42
- [SNMP]: http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol "SNMP"
43
- [npm]: https://npmjs.org/ "npm"
44
-
45
- # Standards Compliance
46
-
47
- This module aims to be fully compliant with the following RFCs:
48
-
49
- * [1155][1155] - Structure and Identification of Management Information
50
- * [1098][1098] - A Simple Network Management Protocol (version 1)
51
- * [2578][2578] - Structure of Management Information Version 2 (SMIv2)
52
- * [3416][3416] - Simple Network Management Protocol (SNMP) (version 2c)
53
-
54
- However, this module does not implement, or export any method that might help
55
- to implement, the SNMP version 2c report request type.
56
-
57
- [1155]: https://tools.ietf.org/rfc/rfc1155.txt "RFC 1155"
58
- [1098]: https://tools.ietf.org/rfc/rfc1098.txt "RFC 1098"
59
- [2578]: https://tools.ietf.org/rfc/rfc2578.txt "RFC 2578"
60
- [3416]: https://tools.ietf.org/rfc/rfc3416.txt "RFC 3416"
61
-
62
- # Constants
63
-
64
- The following sections describe constants exported and used by this module.
65
-
66
- ## snmp.Version1 & snmp.Version2c
67
-
68
- These constants are used to specify which of the two versions supported by
69
- this module should be used.
70
-
71
- ## snmp.ErrorStatus
72
-
73
- This object contains constants for all valid values the error-status field in
74
- response PDUs can hold. If when parsing a PDU the error-index field contains
75
- a value not defined in this object the constant `snmp.ErrorStatus.GeneralError`
76
- will be used instead of the value in the error-status field. The following
77
- constants are defined in this object:
78
-
79
- * `NoError`
80
- * `TooBig`
81
- * `NoSuchName`
82
- * `BadValue`
83
- * `ReadOnly`
84
- * `GeneralError`
85
- * `NoAccess`
86
- * `WrongType`
87
- * `WrongLength`
88
- * `WrongEncoding`
89
- * `WrongValue`
90
- * `NoCreation`
91
- * `InconsistentValue`
92
- * `ResourceUnavailable`
93
- * `CommitFailed`
94
- * `UndoFailed`
95
- * `AuthorizationError`
96
- * `NotWritable`
97
- * `InconsistentName`
98
-
99
- ## snmp.ObjectType
100
-
101
- This object contains constants used to specify syntax for varbind objects,
102
- e.g.:
103
-
104
- var varbind = {
105
- oid: "1.3.6.1.2.1.1.4.0",
106
- type: snmp.ObjectType.OctetString,
107
- value: "user.name@domain.name"
108
- };
109
-
110
- The following constants are defined in this object:
111
-
112
- * `Boolean`
113
- * `Integer`
114
- * `OctetString`
115
- * `Null`
116
- * `OID`
117
- * `IpAddress`
118
- * `Counter`
119
- * `Gauge`
120
- * `TimeTicks`
121
- * `Opaque`
122
- * `Integer32`
123
- * `Counter32`
124
- * `Gauge32`
125
- * `Unsigned32`
126
- * `Counter64`
127
- * `NoSuchObject`
128
- * `NoSuchInstance`
129
- * `EndOfMibView`
130
-
131
- ## snmp.TrapType
132
-
133
- This object contains constants used to specify a type of SNMP trap. These
134
- constants are passed to the `trap()` and `inform()` methods exposed by the
135
- `Session` class. The following constants are defined in this object:
136
-
137
- * `ColdStart`
138
- * `WarmStart`
139
- * `LinkDown`
140
- * `LinkUp`
141
- * `AuthenticationFailure`
142
- * `EgpNeighborLoss`
143
- * `EnterpriseSpecific`
144
-
145
- # OID Strings & Varbinds
146
-
147
- Some parts of this module accept simple OID strings, e.g.:
148
-
149
- var oid = "1.3.6.1.2.1.1.5.0";
150
-
151
- Other parts take an OID string, it's type and value. This is collectively
152
- referred to as a varbind, and is specified as an object, e.g.:
153
-
154
- var varbind = {
155
- oid: "1.3.6.1.2.1.1.5.0",
156
- type: snmp.ObjectType.OctetString,
157
- value: new Buffer ("host1")
158
- };
159
-
160
- The `type` parameter is one of the constants defined in the `snmp.ObjectType`
161
- object.
162
-
163
- The JavaScript `true` and `false` keywords are used for the values of varbinds
164
- with type `Boolean`.
165
-
166
- All integer based types are specified as expected (this includes `Integer`,
167
- `Counter`, `Gauge`, `TimeTicks`, `Integer32`, `Counter32`, `Gauge32`, and
168
- `Unsigned32`), e.g. `-128` or `100`.
169
-
170
- Since JavaScript does not offer full 64 bit integer support objects with type
171
- `Counter64` cannot be supported in the same way as other integer types,
172
- instead [Node.js][nodejs] `Buffer` objects are used. Users are responsible for
173
- producing (i.e. for `set()` requests) and consuming (i.e. the varbinds passed
174
- to callback functions) `Buffer` objects. That is, this module does not work
175
- with 64 bit integers, it simply treats them as opaque `Buffer` objects.
176
-
177
- Dotted decimal strings are used for the values of varbinds with type `OID`,
178
- e.g. `1.3.6.1.2.1.1.5.0`.
179
-
180
- Dotted quad formatted strings are used for the values of varbinds with type
181
- `IpAddress`, e.g. `192.168.1.1`.
182
-
183
- [Node.js][nodejs] `Buffer` objects are used for the values of varbinds with
184
- type `Opaque` and `OctetString`. For varbinds with type `OctetString` this
185
- module will accept JavaScript strings, but will always give back `Buffer`
186
- objects.
187
-
188
- The `NoSuchObject`, `NoSuchInstance` and `EndOfMibView` types are used to
189
- indicate an error condition. Currently there is no reason for users of this
190
- module to to build varbinds using these types.
191
-
192
- [nodejs]: http://nodejs.org "Node.js"
193
-
194
- # Callback Functions & Error Handling
195
-
196
- Most of the request methods exposed by this module require a mandatory
197
- callback function. This function is called once a request has been processed.
198
- This could be because an error occurred when processing the request, a trap
199
- has been dispatched or a successful response was received.
200
-
201
- The first parameter to every callback is an error object. In the case no
202
- error occurred this parameter will be "null" indicating no error, e.g.:
203
-
204
- function responseCb (error, varbinds) {
205
- if (error) {
206
- console.error (error);
207
- } else {
208
- // no error, do something with varbinds
209
- }
210
- }
211
-
212
- When defined, the error parameter is always an instance of the `Error` class,
213
- or a sub-class described in one of the sub-sections contained in this section.
214
-
215
- The semantics of error handling is slightly different between SNMP version
216
- 1 and 2c. In SNMP version 1 if an error occurs when calculating the value for
217
- one OID the request as a whole will fail, i.e. no OIDs will have a value.
218
-
219
- This failure manifests itself within the error-status and error-index fields
220
- of the response. When the error-status field in the response is non-zero,
221
- i.e. not `snmp.ErrorStatus.NoError` the `callback` will be called with `error`
222
- defined detailing the error.
223
-
224
- Requests made with SNMP version 1 can simply assume all OIDs have a value when
225
- no error object is passed to the `callback`, i.e.:
226
-
227
- var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
228
-
229
- session.get (oids, function (error, varbinds) {
230
- if (error) {
231
- console.error (error.toString ());
232
- } else {
233
- var sysName = varbinds[0].value; // this WILL have a value
234
- }
235
- });
236
-
237
- In SNMP version 2c instead of using the error-status and error-index fields of
238
- the response to signal an error, the value for the varbind placed in the
239
- response for an OID will have an object syntax describing an error. The
240
- error-status and error-index fields of the response will indicate the request
241
- was successul, i.e. `snmp.ErrorStatus.NoError`.
242
-
243
- This changes the way in which error checking is performed in the `callback`.
244
- When using SNMP version 2c each varbind must be checked to see if its value
245
- was computed and returned successfully:
246
-
247
- var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
248
-
249
- session.get (oids, function (error, varbinds) {
250
- if (error) {
251
- console.error (error.toString ());
252
- } else {
253
- if (varbinds[0].type != snmp.ErrorStatus.NoSuchObject
254
- && varbinds[0].type != snmp.ErrorStatus.NoSuchInstance
255
- && varbinds[0].type != snmp.ErrorStatus.EndOfMibView) {
256
- var sysName = varbinds[0].value;
257
- } else {
258
- console.error (snmp.ObjectType[varbinds[0].type] + ": "
259
- + varbinds[0].oid);
260
- }
261
- }
262
- });
263
-
264
- This module exports two functions and promotes a specifc pattern to make error
265
- checking a little simpler. Firstly, regardless of version in use varbinds can
266
- always be checked. This results in a generic `callback` that can be used for
267
- both versions.
268
-
269
- The `isVarbindError()` function can be used to determine if a varbind has an
270
- error condition. This function takes a single `varbind` parameter and returns
271
- `true` if the varbind has an error condition, otherwise `false`. The exported
272
- `varbindError()` function can then be used to obtain the error string
273
- describing the error, which will include the OID for the varbind:
274
-
275
- session.get (oids, function (error, varbinds) {
276
- if (error) {
277
- console.error (error.toString ());
278
- } else {
279
- if (snmp.isVarbindError (varbinds[0])) {
280
- console.error (snmp.varbindError (varbinds[0]));
281
- } else {
282
- var sysName = varbinds[0].value;
283
- }
284
- }
285
- });
286
-
287
- If the `varbindError` function is called with a varbind for which
288
- `isVarbindError` would return false, the string `NotAnError` will be returned
289
- appended with the related OID.
290
-
291
- The sections following defines the error classes used by this module.
292
-
293
- ## snmp.RequestFailedError
294
-
295
- This error indicates a remote host failed to process a request. The exposed
296
- `message` attribute will contain a detailed error message. This error also
297
- exposes a `status` attribute which contains the error-index value from a
298
- response. This will be one of the constants defined in the
299
- `snmp.ErrorStatus` object.
300
-
301
- ## snmp.RequestInvalidError
302
-
303
- This error indicates a failure to render a request message before it could be
304
- sent. The error can also indicate that a parameter provided was invalid.
305
- The exposed `message` attribute will contain a detailed error message.
306
-
307
- ## snmp.RequestTimedOutError
308
-
309
- This error states that no response was received for a particular request. The
310
- exposed `message` attribute will contain the value `Request timed out`.
311
-
312
- ## snmp.ResponseInvalidError
313
-
314
- This error indicates a failure to parse a response message. The exposed
315
- `message` attribute will contain a detailed error message.
316
-
317
- # Using This Module
318
-
319
- All SNMP requests are made using an instance of the `Session` class. This
320
- module exports the `createSession()` function which is used to create
321
- instances of the `Session` class.
322
-
323
- ## snmp.createSession ([target], [community], [options])
324
-
325
- The `createSession()` function instantiates and returns an instance of the
326
- `Session` class:
327
-
328
- // Default options
329
- var options = {
330
- port: 161,
331
- retries: 1,
332
- timeout: 5000,
333
- transport: "udp4",
334
- trapPort: 162,
335
- version: snmp.Version1,
336
- idBitsSize: 16
337
- };
338
-
339
- var session = snmp.createSession ("127.0.0.1", "public", options);
340
-
341
- The optional `target` parameter defaults to `127.0.0.1`. The optional
342
- `community` parameter defaults to `public`. The optional `options` parameter
343
- is an object, and can contain the following items:
344
-
345
- * `port` - UDP port to send requests too, defaults to `161`
346
- * `retries` - Number of times to re-send a request, defaults to `1`
347
- * `sourceAddress` - IP address from which SNMP requests should originate,
348
- there is no default for this option, the operating system will select an
349
- appropriate source address when the SNMP request is sent
350
- * `sourcePort` - UDP port from which SNMP requests should originate, defaults
351
- to an ephemeral port selected by the operation system
352
- * `timeout` - Number of milliseconds to wait for a response before re-trying
353
- or failing, defaults to `5000`
354
- * `transport` - Specify the transport to use, can be either `udp4` or `udp6`,
355
- defaults to `udp4`
356
- * `trapPort` - UDP port to send traps and informs too, defaults to `162`
357
- * `version` - Either `snmp.Version1` or `snmp.Version2c`, defaults to
358
- `snmp.Version1`
359
- * `idBitsSize` - Either `16` or `32`, defaults to `32`. Used to reduce the size
360
- of the generated id for compatibility with some older devices.
361
-
362
- When a session has been finished with it should be closed:
363
-
364
- session.close ();
365
-
366
- ## session.on ("close", callback)
367
-
368
- The `close` event is emitted by the session when the sessions underlying UDP
369
- socket is closed.
370
-
371
- No arguments are passed to the callback.
372
-
373
- Before this event is emitted all outstanding requests are cancelled, resulting
374
- in the failure of each outstanding request. The error passed back through to
375
- each request will be an instance of the `Error` class with the errors
376
- `message` attribute set to `Socket forcibly closed`.
377
-
378
- The following example prints a message to the console when a sessions
379
- underlying UDP socket is closed:
380
-
381
- session.on ("close", function () {
382
- console.log ("socket closed");
383
- });
384
-
385
- ## session.on ("error", callback)
386
-
387
- The `error` event is emitted by the session when the sessions underlying UDP
388
- socket emits an error.
389
-
390
- The following arguments will be passed to the `callback` function:
391
-
392
- * `error` - An instance of the `Error` class, the exposed `message` attribute
393
- will contain a detailed error message.
394
-
395
- The following example prints a message to the console when an error occurs
396
- with a sessions underlying UDP socket, the session is then closed:
397
-
398
- session.on ("error", function (error) {
399
- console.log (error.toString ());
400
- session.close ();
401
- });
402
-
403
- ## session.close ()
404
-
405
- The `close()` method closes the sessions underlying UDP socket. This will
406
- result in the `close` event being emitted by the sessions underlying UDP
407
- socket which is passed through to the session, resulting in the session also
408
- emitting a `close` event.
409
-
410
- The following example closes a sessions underlying UDP socket:
411
-
412
- session.close ();
413
-
414
- ## session.get (oids, callback)
415
-
416
- The `get()` method fetches the value for one or more OIDs.
417
-
418
- The `oids` parameter is an array of OID strings. The `callback` function is
419
- called once the request is complete. The following arguments will be passed
420
- to the `callback` function:
421
-
422
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
423
- error occurred
424
- * `varbinds` - Array of varbinds, will not be provided if an error occurred
425
-
426
- The varbind in position N in the `varbinds` array will correspond to the OID
427
- in position N in the `oids` array in the request.
428
-
429
- Each varbind must be checked for an error condition using the
430
- `snmp.isVarbindError()` function when using SNMP version 2c.
431
-
432
- The following example fetches values for the sysName (`1.3.6.1.2.1.1.5.0`) and
433
- sysLocation (`1.3.6.1.2.1.1.6.0`) OIDs:
434
-
435
- var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
436
-
437
- session.get (oids, function (error, varbinds) {
438
- if (error) {
439
- console.error (error.toString ());
440
- } else {
441
- for (var i = 0; i < varbinds.length; i++) {
442
- // for version 1 we can assume all OIDs were successful
443
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
444
-
445
- // for version 2c we must check each OID for an error condition
446
- if (snmp.isVarbindError (varbinds[i]))
447
- console.error (snmp.varbindError (varbinds[i]));
448
- else
449
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
450
- }
451
- }
452
- });
453
-
454
- ## session.getBulk (oids, [nonRepeaters], [maxRepetitions], callback)
455
-
456
- The `getBulk()` method fetches the value for the OIDs lexicographically
457
- following one or more OIDs in the MIB tree.
458
-
459
- The `oids` parameter is an array of OID strings. The optional `nonRepeaters`
460
- parameter specifies the number of OIDs in the `oids` parameter for which only
461
- 1 varbind should be returned, and defaults to `0`. For each remaining OID
462
- in the `oids` parameter the optional `maxRepetitions` parameter specifies how
463
- many OIDs lexicographically following an OID for which varbinds should be
464
- fetched, and defaults to `20`.
465
-
466
- The `callback` function is called once the request is complete. The following
467
- arguments will be passed to the `callback` function:
468
-
469
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
470
- error occurred
471
- * `varbinds` - Array of varbinds, will not be provided if an error occurred
472
-
473
- The varbind in position N in the `varbinds` array will correspond to the OID
474
- in position N in the `oids` array in the request.
475
-
476
- For for the first `nonRepeaters` items in `varbinds` each item will be a
477
- single varbind. For all remaining items in `varbinds` each item will be an
478
- array of varbinds - this makes it easy to tie response varbinds with requested
479
- OIDs since response varbinds are grouped and placed in the same position in
480
- `varbinds`.
481
-
482
- Each varbind must be checked for an error condition using the
483
- `snmp.isVarbindError()` function when using SNMP version 2c.
484
-
485
- The following example fetches values for the OIDs following the sysContact
486
- (`1.3.6.1.2.1.1.4.0`) and sysName (`1.3.6.1.2.1.1.5.0`) OIDs, and up to the
487
- first 20 OIDs in the ifDescr (`1.3.6.1.2.1.2.2.1.2`) and ifType
488
- (`1.3.6.1.2.1.2.2.1.3`) columns from the ifTable (`1.3.6.1.2.1.2.2`) table:
489
-
490
- var oids = [
491
- "1.3.6.1.2.1.1.4.0",
492
- "1.3.6.1.2.1.1.5.0",
493
- "1.3.6.1.2.1.2.2.1.2",
494
- "1.3.6.1.2.1.2.2.1.3"
495
- ];
496
-
497
- var nonRepeaters = 2;
498
-
499
- session.getNext (oids, nonRepeaters, function (error, varbinds) {
500
- if (error) {
501
- console.error (error.toString ());
502
- } else {
503
- // step through the non-repeaters which are single varbinds
504
- for (var i = 0; i < nonRepeaters; i++) {
505
- if (i >= varbinds.length)
506
- break;
507
-
508
- if (snmp.isVarbindError (varbinds[i]))
509
- console.error (snmp.varbindError (varbinds[i]));
510
- else
511
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
512
- }
513
-
514
- // then step through the repeaters which are varbind arrays
515
- for (var i = nonRepeaters; i < varbinds.length; i++) {
516
- for (var j = 0; j < varbinds[i].length; j++) {
517
- if (snmp.isVarbindError (varbinds[i][j]))
518
- console.error (snmp.varbindError (varbinds[i][j]));
519
- else
520
- console.log (varbinds[i][j].oid + "|"
521
- + varbinds[i][j].value);
522
- }
523
- }
524
- });
525
-
526
- ## session.getNext (oids, callback)
527
-
528
- The `getNext()` method fetches the value for the OIDs lexicographically
529
- following one or more OIDs in the MIB tree.
530
-
531
- The `oids` parameter is an array of OID strings. The `callback` function is
532
- called once the request is complete. The following arguments will be passed
533
- to the `callback` function:
534
-
535
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
536
- error occurred
537
- * `varbinds` - Array of varbinds, will not be provided if an error occurred
538
-
539
- The varbind in position N in the `varbinds` array will correspond to the OID
540
- in position N in the `oids` array in the request.
541
-
542
- Each varbind must be checked for an error condition using the
543
- `snmp.isVarbindError()` function when using SNMP version 2c.
544
-
545
- The following example fetches values for the next OIDs following the
546
- sysObjectID (`1.3.6.1.2.1.1.1.0`) and sysName (`1.3.6.1.2.1.1.4.0`) OIDs:
547
-
548
- var oids = [
549
- "1.3.6.1.2.1.1.1.0",
550
- "1.3.6.1.2.1.1.4.0"
551
- ];
552
-
553
- session.getNext (oids, function (error, varbinds) {
554
- if (error) {
555
- console.error (error.toString ());
556
- } else {
557
- for (var i = 0; i < varbinds.length; i++) {
558
- // for version 1 we can assume all OIDs were successful
559
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
560
-
561
- // for version 2c we must check each OID for an error condition
562
- if (snmp.isVarbindError (varbinds[i]))
563
- console.error (snmp.varbindError (varbinds[i]));
564
- else
565
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
566
- }
567
- }
568
- });
569
-
570
- ## session.inform (typeOrOid, [varbinds], [options], callback)
571
-
572
- The `inform()` method sends a SNMP inform.
573
-
574
- The `typeOrOid` parameter can be one of two types; one of the constants
575
- defined in the `snmp.TrapType` object (excluding the
576
- `snmp.TrapType.EnterpriseSpecific` constant), or an OID string.
577
-
578
- The first varbind to be placed in the request message will be for the
579
- `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`). The value for this varbind will
580
- be the value returned by the `process.uptime ()` function multiplied by 100
581
- (this can be overridden by providing `upTime` in the optional `options`
582
- parameter, as documented below).
583
-
584
- This will be followed by a second varbind for the `snmpTrapOID.0` OID
585
- (`1.3.6.1.6.3.1.1.4.1.0`). The value for this will depend on the `typeOrOid`
586
- parameter. If a constant is specified the trap OID for the constant will be
587
- used as supplied for the varbinds value, otherwise the OID string specified
588
- will be used as is for the value of the varbind.
589
-
590
- The optional `varbinds` parameter is an array of varbinds to include in the
591
- inform request, and defaults to the empty array `[]`.
592
-
593
- The optional `options` parameter is an object, and can contain the following
594
- items:
595
-
596
- * `upTime` - Value of the `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`) in the
597
- inform, defaults to the value returned by the `process.uptime ()` function
598
- multiplied by 100
599
-
600
- The `callback` function is called once a response to the inform request has
601
- been received, or an error occurred. The following arguments will be passed
602
- to the `callback` function:
603
-
604
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
605
- error occurred
606
- * `varbinds` - Array of varbinds, will not be provided if an error occurred
607
-
608
- The varbind in position N in the `varbinds` array will correspond to the
609
- varbind in position N in the `varbinds` array in the request. The remote host
610
- should echo back varbinds and their values as specified in the request, and
611
- the `varbinds` array will contain each varbind as sent back by the remote host.
612
-
613
- Normally there is no reason to use the contents of the `varbinds` parameter
614
- since the varbinds are as they were sent in the request.
615
-
616
- The following example sends a generic cold-start inform to a remote host,
617
- it does not include any varbinds:
618
-
619
- session.inform (snmp.TrapType.ColdStart, function (error) {
620
- if (error)
621
- console.error (error);
622
- });
623
-
624
- The following example sends an enterprise specific inform to a remote host,
625
- and includes two enterprise specific varbinds:
626
-
627
- var informOid = "1.3.6.1.4.1.2000.1";
628
-
629
- var varbinds = [
630
- {
631
- oid: "1.3.6.1.4.1.2000.2",
632
- type: snmp.ObjectType.OctetString,
633
- value: "Periodic hardware self-check"
634
- },
635
- {
636
- oid: "1.3.6.1.4.1.2000.3",
637
- type: snmp.ObjectType.OctetString,
638
- value: "hardware-ok"
639
- }
640
- ];
641
-
642
- // Override sysUpTime, specfiying it as 10 seconds...
643
- var options = {upTime: 1000};
644
- session.inform (informOid, varbinds, options, function (error) {
645
- if (error)
646
- console.error (error);
647
- });
648
-
649
- ## session.set (varbinds, callback)
650
-
651
- The `set()` method sets the value of one or more OIDs.
652
-
653
- The `varbinds` parameter is an array of varbind objects. The `callback`
654
- function is called once the request is complete. The following arguments will
655
- be passed to the `callback` function:
656
-
657
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
658
- error occurred
659
- * `varbinds` - Array of varbinds, will not be provided if an error occurred
660
-
661
- The varbind in position N in the `varbinds` array will correspond to the
662
- varbind in position N in the `varbinds` array in the request. The remote host
663
- should echo back varbinds and their values as specified in the request unless
664
- an error occurred. The `varbinds` array will contain each varbind as sent
665
- back by the remote host.
666
-
667
- Each varbind must be checked for an error condition using the
668
- `snmp.isVarbindError()` function when using SNMP version 2c.
669
-
670
- The following example sets the value of the sysName (`1.3.6.1.2.1.1.4.0`) and
671
- sysLocation (`1.3.6.1.2.1.1.6.0`) OIDs:
672
-
673
- var varbinds = [
674
- {
675
- oid: "1.3.6.1.2.1.1.5.0",
676
- type: snmp.ObjectType.OctetString,
677
- value: "host1"
678
- }, {
679
- oid: "1.3.6.1.2.1.1.6.0",
680
- type: snmp.ObjectType.OctetString,
681
- value: "somewhere"
682
- }
683
- ];
684
-
685
- session.set (varbinds, function (error, varbinds) {
686
- if (error) {
687
- console.error (error.toString ());
688
- } else {
689
- for (var i = 0; i < varbinds.length; i++) {
690
- // for version 1 we can assume all OIDs were successful
691
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
692
-
693
- // for version 2c we must check each OID for an error condition
694
- if (snmp.isVarbindError (varbinds[i]))
695
- console.error (snmp.varbindError (varbinds[i]));
696
- else
697
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
698
- }
699
- }
700
- });
701
-
702
- ## session.subtree (oid, [maxRepetitions], feedCallback, doneCallback)
703
-
704
- The `subtree()` method fetches the value for all OIDs lexicographically
705
- following a specified OID in the MIB tree which have the specified OID as
706
- there base. For example, the OIDs sysName (`1.3.6.1.2.1.1.5.0`) and
707
- sysLocation (`1.3.6.1.2.1.1.6.0`) both have the same base system
708
- (`1.3.6.1.2.1.1`) OID.
709
-
710
- For SNMP version 1 repeated `get()` calls are made until the one of the
711
- returned OIDs does not use the specified OID as its base. For SNMP version
712
- 2c repeated `getBulk()` calls are made until the one of the returned OIDs
713
- does no used the specified OID as its base.
714
-
715
- The `oid` parameter is an OID string. The optional `maxRepetitions` parameter
716
- is passed to `getBulk()` requests when SNMP version 2c is being used.
717
-
718
- This method will not call a single callback once all OID values are fetched.
719
- Instead the `feedCallback` function will be called each time a response is
720
- received from the remote host. The following arguments will be passed to the
721
- `feedCallback` function:
722
-
723
- * `varbinds` - Array of varbinds, and will contain at least one varbind
724
-
725
- Each varbind must be checked for an error condition using the
726
- `snmp.isVarbindError()` function when using SNMP version 2c.
727
-
728
- Once at least one of the returned OIDs does not use the specified OID as its
729
- base, or an error has occurred, the `doneCallback` function will be called.
730
- The following arguments will be passed to the `doneCallback` function:
731
-
732
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
733
- error occurred
734
-
735
- Once the `doneCallback` function has been called the request is complete and
736
- the `feedCallback` function will no longer be called.
737
-
738
- If the `feedCallback` function returns a `true` value when called no more
739
- `get()` or `getBulk()` method calls will be made and the `doneCallback` will
740
- be called.
741
-
742
- The following example fetches all OIDS under the system (`1.3.6.1.2.1.1`) OID:
743
-
744
- var oid = "1.3.6.1.2.1.1";
745
-
746
- function doneCb (error) {
747
- if (error)
748
- console.error (error.toString ());
749
- }
750
-
751
- function feedCb (varbinds) {
752
- for (var i = 0; i < varbinds.length; i++) {
753
- if (snmp.isVarbindError (varbinds[i]))
754
- console.error (snmp.varbindError (varbinds[i]));
755
- else
756
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
757
- }
758
- }
759
-
760
- var maxRepetitions = 20;
761
-
762
- // The maxRepetitions argument is optional, and will be ignored unless using
763
- // SNMP verison 2c
764
- session.subtree (oid, maxRepetitions, feedCb, doneCb);
765
-
766
- ## session.table (oid, [maxRepetitions], callback)
767
-
768
- The `table()` method fetches the value for all OIDs lexicographically
769
- following a specified OID in the MIB tree which have the specified OID as
770
- there base, much like the `subtree()` method.
771
-
772
- This method is designed to fetch conceptial tables, for example the ifTable
773
- (`1.3.6.1.2.1.2.2`) table. The values for returned varbinds will be structured
774
- into objects to represent conceptual rows. Each row is then placed into an
775
- object with the rows index being the key, e.g.:
776
-
777
- var table = {
778
- // Rows keyed by ifIndex (1 and 2 are shown)
779
- 1: {
780
- // ifDescr (column 2) and ifType (columnd 3) are shown
781
- 2: "interface-1",
782
- 3: 6,
783
- ...
784
- },
785
- 2: {
786
- 2: "interface-2",
787
- 3: 6,
788
- ...
789
- },
790
- ...
791
- }
792
-
793
- Internally this method calls the `subtree()` method to obtain the subtree of
794
- the specified table.
795
-
796
- The `oid` parameter is an OID string. If an OID string is passed which does
797
- not represent a table the resulting object produced to hold table data will be
798
- empty, i.e. it will contain no indexes and rows. The optional
799
- `maxRepetitions` parameter is passed to the `subtree()` request.
800
-
801
- The `callback` function will be called once the entire table has been fetched.
802
- The following arguments will be passed to the `callback` function:
803
-
804
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
805
- error occurred
806
- * `table` - Object containing object references representing conceptual
807
- rows keyed by index (e.g. for the ifTable table rows are keyed by ifIndex),
808
- each row object will contain values keyed by column number, will not be
809
- provided if an error occurred
810
-
811
- If an error occurs with any varbind returned by `subtree()` no table will be
812
- passed to the `callback` function. The reason for failure, and the related
813
- OID string (as returned from a call to the `snmp.varbindError()` function),
814
- will be passed to the `callback` function in the `error` argument as an
815
- instance of the `RequestFailedError` class.
816
-
817
- The following example fetches the ifTable (`1.3.6.1.2.1.2.2`) table:
818
-
819
- var oid = "1.3.6.1.2.1.2.2";
820
-
821
- function sortInt (a, b) {
822
- if (a > b)
823
- return 1;
824
- else if (b > a)
825
- return -1;
826
- else
827
- return 0;
828
- }
829
-
830
- function responseCb (error, table) {
831
- if (error) {
832
- console.error (error.toString ());
833
- } else {
834
- // This code is purely used to print rows out in index order,
835
- // ifIndex's are integers so we'll sort them numerically using
836
- // the sortInt() function above
837
- var indexes = [];
838
- for (index in table)
839
- indexes.push (parseInt (index));
840
- indexes.sort (sortInt);
841
-
842
- // Use the sorted indexes we've calculated to walk through each
843
- // row in order
844
- for (var i = 0; i < indexes.length; i++) {
845
- // Like indexes we sort by column, so use the same trick here,
846
- // some rows may not have the same columns as other rows, so
847
- // we calculate this per row
848
- var columns = [];
849
- for (column in table[indexes[i]])
850
- columns.push (parseInt (column));
851
- columns.sort (sortInt);
852
-
853
- // Print index, then each column indented under the index
854
- console.log ("row for index = " + indexes[i]);
855
- for (var j = 0; j < columns.length; j++) {
856
- console.log (" column " + columns[j] + " = "
857
- + table[indexes[i]][columns[j]]);
858
- }
859
- }
860
- }
861
- }
862
-
863
- var maxRepetitions = 20;
864
-
865
- // The maxRepetitions argument is optional, and will be ignored unless using
866
- // SNMP verison 2c
867
- session.table (oid, maxRepetitions, responseCb);
868
-
869
- ## session.tableColumns (oid, columns, [maxRepetitions], callback)
870
-
871
- The `tableColumns()` method implements the same interface as the `table()`
872
- method. However, only the columns specified in the `columns` parameter will
873
- be in the resulting table.
874
-
875
- This method should be used when only selected columns are required, and
876
- will be many times faster than the `table()` method since a much smaller
877
- amount of data will be fected.
878
-
879
- The following example fetches the ifTable (`1.3.6.1.2.1.2.2`) table, and
880
- specifies that only the ifDescr (`1.3.6.1.2.1.2.2.1.2`) and ifPhysAddress
881
- (`1.3.6.1.2.1.2.2.1.6`) columns should actually be fetched:
882
-
883
- var oid = "1.3.6.1.2.1.2.2";
884
- var columns = [2, 6];
885
-
886
- function sortInt (a, b) {
887
- if (a > b)
888
- return 1;
889
- else if (b > a)
890
- return -1;
891
- else
892
- return 0;
893
- }
894
-
895
- function responseCb (error, table) {
896
- if (error) {
897
- console.error (error.toString ());
898
- } else {
899
- // This code is purely used to print rows out in index order,
900
- // ifIndex's are integers so we'll sort them numerically using
901
- // the sortInt() function above
902
- var indexes = [];
903
- for (index in table)
904
- indexes.push (parseInt (index));
905
- indexes.sort (sortInt);
906
-
907
- // Use the sorted indexes we've calculated to walk through each
908
- // row in order
909
- for (var i = 0; i < indexes.length; i++) {
910
- // Like indexes we sort by column, so use the same trick here,
911
- // some rows may not have the same columns as other rows, so
912
- // we calculate this per row
913
- var columns = [];
914
- for (column in table[indexes[i]])
915
- columns.push (parseInt (column));
916
- columns.sort (sortInt);
917
-
918
- // Print index, then each column indented under the index
919
- console.log ("row for index = " + indexes[i]);
920
- for (var j = 0; j < columns.length; j++) {
921
- console.log (" column " + columns[j] + " = "
922
- + table[indexes[i]][columns[j]]);
923
- }
924
- }
925
- }
926
- }
927
-
928
- var maxRepetitions = 20;
929
-
930
- // The maxRepetitions argument is optional, and will be ignored unless using
931
- // SNMP verison 2c
932
- session.tableColumns (oid, columns, maxRepetitions, responseCb);
933
-
934
- ## session.trap (typeOrOid, [varbinds], [agentAddrOrOptions], callback)
935
-
936
- The `trap()` method sends a SNMP trap.
937
-
938
- The `typeOrOid` parameter can be one of two types; one of the constants
939
- defined in the `snmp.TrapType` object (excluding the
940
- `snmp.TrapType.EnterpriseSpecific` constant), or an OID string.
941
-
942
- For SNMP version 1 when a constant is specified the following fields are set in
943
- the trap:
944
-
945
- * The enterprise field is set to the OID `1.3.6.1.4.1`
946
- * The generic-trap field is set to the constant specified
947
- * The specific-trap field is set to 0
948
-
949
- When an OID string is specified the following fields are set in the trap:
950
-
951
- * The final decimal is stripped from the OID string and set in the
952
- specific-trap field
953
- * The remaining OID string is set in the enterprise field
954
- * The generic-trap field is set to the constant
955
- `snmp.TrapType.EnterpriseSpecific`
956
-
957
- In both cases the time-stamp field in the trap PDU is set to the value
958
- returned by the `process.uptime ()` function multiplied by `100`.
959
-
960
- SNMP version 2c messages are quite different in comparison with version 1.
961
- The version 2c trap has a much simpler format, simply a sequence of varbinds.
962
- The first varbind to be placed in the trap message will be for the
963
- `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`). The value for this varbind will
964
- be the value returned by the `process.uptime ()` function multiplied by 100
965
- (this can be overridden by providing `upTime` in the optional `options`
966
- parameter, as documented below).
967
-
968
- This will be followed by a second varbind for the `snmpTrapOID.0` OID
969
- (`1.3.6.1.6.3.1.1.4.1.0`). The value for this will depend on the `typeOrOid`
970
- parameter. If a constant is specified the trap OID for the constant
971
- will be used as supplied for the varbinds value, otherwise the OID string
972
- specified will be used as is for the value of the varbind.
973
-
974
- The optional `varbinds` parameter is an array of varbinds to include in the
975
- trap, and defaults to the empty array `[]`.
976
-
977
- The optional `agentAddrOrOptions` parameter can be one of two types; one is
978
- the IP address used to populate the agent-addr field for SNMP version 1 type
979
- traps, and defaults to `127.0.0.1`, or an object, and can contain the
980
- following items:
981
-
982
- * `agentAddr` - IP address used to populate the agent-addr field for SNMP
983
- version 1 type traps, and defaults to `127.0.0.1`
984
- * `upTime` - Value of the `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`) in the
985
- trap, defaults to the value returned by the `process.uptime ()` function
986
- multiplied by 100
987
-
988
- **NOTE** When using SNMP version 2c the `agentAddr` parameter is ignored if
989
- specified since version 2c trap messages do not have an agent-addr field.
990
-
991
- The `callback` function is called once the trap has been sent, or an error
992
- occurred. The following arguments will be passed to the `callback` function:
993
-
994
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
995
- error occurred
996
-
997
- The following example sends an enterprise specific trap to a remote host using
998
- a SNMP version 1 trap, and includes the sysName (`1.3.6.1.2.1.1.5.0`) varbind
999
- in the trap. Before the trap is sent the `agentAddr` field is calculated using
1000
- DNS to resolve the hostname of the local host:
1001
-
1002
- var enterpriseOid = "1.3.6.1.4.1.2000.1"; // made up, but it may be valid
1003
-
1004
- var varbinds = [
1005
- {
1006
- oid: "1.3.6.1.2.1.1.5.0",
1007
- type: snmp.ObjectType.OctetString,
1008
- value: "host1"
1009
- }
1010
- ];
1011
-
1012
- dns.lookup (os.hostname (), function (error, agentAddress) {
1013
- if (error) {
1014
- console.error (error);
1015
- } else {
1016
- // Override sysUpTime, specfiying it as 10 seconds...
1017
- var options = {agentAddr: agentAddress, upTime: 1000};
1018
- session.trap (enterpriseOid, varbinds, agentAddress,
1019
- function (error) {
1020
- if (error)
1021
- console.error (error);
1022
- });
1023
- }
1024
- });
1025
-
1026
- The following example sends a generic link-down trap to a remote host using a
1027
- SNMP version 1 trap, it does not include any varbinds or specify the
1028
- `agentAddr` parameter:
1029
-
1030
- session.trap (snmp.TrapType.LinkDown, function (error) {
1031
- if (error)
1032
- console.error (error);
1033
- });
1034
-
1035
- The following example sends an enterprise specific trap to a remote host using
1036
- a SNMP version 2c trap, and includes two enterprise specific varbinds:
1037
-
1038
- var trapOid = "1.3.6.1.4.1.2000.1";
1039
-
1040
- var varbinds = [
1041
- {
1042
- oid: "1.3.6.1.4.1.2000.2",
1043
- type: snmp.ObjectType.OctetString,
1044
- value: "Hardware health status changed"
1045
- },
1046
- {
1047
- oid: "1.3.6.1.4.1.2000.3",
1048
- type: snmp.ObjectType.OctetString,
1049
- value: "status-error"
1050
- }
1051
- ];
1052
-
1053
- // version 2c should have been specified when creating the session
1054
- session.trap (trapOid, varbinds, function (error) {
1055
- if (error)
1056
- console.error (error);
1057
- });
1058
-
1059
- ## session.walk (oid, [maxRepetitions], feedCallback, doneCallback)
1060
-
1061
- The `walk()` method fetches the value for all OIDs lexicographically following
1062
- a specified OID in the MIB tree.
1063
-
1064
- For SNMP version 1 repeated `get()` calls are made until the end of the MIB
1065
- tree is reached. For SNMP version 2c repeated `getBulk()` calls are made
1066
- until the end of the MIB tree is reached.
1067
-
1068
- The `oid` parameter is an OID string. The optional `maxRepetitions` parameter
1069
- is passed to `getBulk()` requests when SNMP version 2c is being used.
1070
-
1071
- This method will not call a single callback once all OID values are fetched.
1072
- Instead the `feedCallback` function will be called each time a response is
1073
- received from the remote host. The following arguments will be passed to the
1074
- `feedCallback` function:
1075
-
1076
- * `varbinds` - Array of varbinds, and will contain at least one varbind
1077
-
1078
- Each varbind must be checked for an error condition using the
1079
- `snmp.isVarbindError()` function when using SNMP version 2c.
1080
-
1081
- Once the end of the MIB tree has been reached, or an error has occurred, the
1082
- `doneCallback` function will be called. The following arguments will be
1083
- passed to the `doneCallback` function:
1084
-
1085
- * `error` - Instance of the `Error` class or a sub-class, or `null` if no
1086
- error occurred
1087
-
1088
- Once the `doneCallback` function has been called the request is complete and
1089
- the `feedCallback` function will no longer be called.
1090
-
1091
- If the `feedCallback` function returns a `true` value when called no more
1092
- `get()` or `getBulk()` method calls will be made and the `doneCallback` will
1093
- be called.
1094
-
1095
- The following example walks to the end of the MIB tree starting from the
1096
- ifTable (`1.3.6.1.2.1.2.2`) OID:
1097
-
1098
- var oid = "1.3.6.1.2.1.2.2";
1099
-
1100
- function doneCb (error) {
1101
- if (error)
1102
- console.error (error.toString ());
1103
- }
1104
-
1105
- function feedCb (varbinds) {
1106
- for (var i = 0; i < varbinds.length; i++) {
1107
- if (snmp.isVarbindError (varbinds[i]))
1108
- console.error (snmp.varbindError (varbinds[i]));
1109
- else
1110
- console.log (varbinds[i].oid + "|" + varbinds[i].value);
1111
- }
1112
- }
1113
-
1114
- var maxRepetitions = 20;
1115
-
1116
- // The maxRepetitions argument is optional, and will be ignored unless using
1117
- // SNMP verison 2c
1118
- session.walk (oid, maxRepetitions, feedCb, doneCb);
1119
-
1120
- # Example Programs
1121
-
1122
- Example programs are included under the modules `example` directory.
1123
-
1124
- # Changes
1125
-
1126
- ## Version 1.0.0 - 14/01/2013
1127
-
1128
- * Initial release including only SNMP version 1 support
1129
-
1130
- ## Version 1.1.0 - 20/01/2013
1131
-
1132
- * Implement SNMP version 2c support
1133
-
1134
- ## Version 1.1.1 - 21/01/2013
1135
-
1136
- * Correct name used in example `require()` call to include this module
1137
-
1138
- ## Version 1.1.2 - 22/01/2013
1139
-
1140
- * Implement `subtree()`, `table()` and `walk()` methods
1141
- * Support IPv6 (added `transport` option to the `createSession()` function)
1142
- * Re-order some methods in README.md
1143
-
1144
- ## Version 1.1.3 - 27/01/2013
1145
-
1146
- * Fix some typos and grammar errors in README.md
1147
- * Example `snmp-table` program had `snmp-subtree` in its usage message
1148
- * Implement example `snmp-tail` program to constantly poll for an OIDs value
1149
- * Add note to README.md about the ability to stop the `walk()` and `subtree()`
1150
- methods by returning `true`
1151
-
1152
- ## Version 1.1.4 - 29/01/2013
1153
-
1154
- * Fix incorrect usage of the term "NPM" in README.md, should be "npm"
1155
-
1156
- ## Version 1.1.5 - 05/02/2013
1157
-
1158
- * The `transport` option to `createSession()` was not used
1159
-
1160
- ## Version 1.1.6 - 12/04/2013
1161
-
1162
- * Implement `tableColumns()` method
1163
- * Added example program `snmp-table-columns.js`
1164
- * Correct name of the `table` parameter to the `table()` callback
1165
- * Slight OID comparison performance enhancement
1166
-
1167
- ## Version 1.1.7 - 11/05/2013
1168
-
1169
- * Use MIT license instead of GPL
1170
-
1171
- ## Version 1.1.8 - 22/06/2013
1172
-
1173
- * Added the example program `cisco-device-inventory.js`
1174
- * Receive `Trap failed: TypeError: value is out of bounds` when sending
1175
- traps using SNMP version 2c
1176
-
1177
- ## Version 1.1.9 - 03/11/2013
1178
-
1179
- * Corrected a few instances of the parameter named `requestCallback` to some
1180
- methods in the README.md file which should have been `feedCallback`
1181
- * Null type is used for varbinds with a 0 value
1182
- * Correct instances of snmp.Type to snmp.ObjectType in the README.md file
1183
-
1184
- ## Version 1.1.10 - 01/12/2013
1185
-
1186
- * Error handler in the `dgram.send()` callback in the `send()` method was
1187
- creating a new instance of the `Error` class from the `error` parameter, but
1188
- it was already an instance of the `Error` class (thanks Ray Solomon)
1189
- * Add stack traces to Error classes exported by this module (thanks Ray
1190
- Solomon)
1191
- * Allow users to specify `0` retries when creating a session (thanks Ray
1192
- Solomon)
1193
- * Update the list of SNMP version 1 related RFCs we adhere to in the
1194
- `Standards Compliance` section of the README.md file
1195
-
1196
- ## Version 1.1.11 - 27/12/2013
1197
-
1198
- * Add `sourceAddress` and `sourcePort` optional options to the
1199
- `Session` classes `createSession()` method, which can be used to control
1200
- from which IP address and port messages should be sent
1201
- * Allow users to specify sysUpTime for SNMP traps and informs
1202
-
1203
- ## Version 1.1.12 - 02/04/2014
1204
-
1205
- * The `agentAddr` attribute is not used when passed in the `options` object
1206
- to the `trap()` method
1207
-
1208
- ## Version 1.1.13 - 12/08/2014
1209
-
1210
- * Not catching error events for the UDP socket returned from the
1211
- `dgram.createSocket()` function
1212
- * Some request methods do not copy arguments which results in sometimes
1213
- unexpected behaviour
1214
- * Use a single UDP socket for all requests in a single SNMP session
1215
- * Use a try/catch block in the timer callback in the `Session.send()` method
1216
- * The `Session` can now emit an `error` event to catch errors in a sessions
1217
- underlying UDP socket
1218
- * The `Session` can now emit a `close` event to catch close events from a
1219
- sessions underlying UDP socket, which results in the cancellation of
1220
- all outstanding requests
1221
- * Added a `close()` method to `Session` to close a sessions underlying UDP
1222
- socket, which results a `close` event
1223
- * Signed integers are treated as unsigned integers when parsing response
1224
- messages
1225
-
1226
- ## Version 1.1.14 - 22/09/2015
1227
-
1228
- * Host repository on GitHub
1229
-
1230
- ## Version 1.1.15 - 08/02/2016
1231
-
1232
- * When parsing an invalid response an exception in message parsing does not
1233
- interupt response processing
1234
- * Incorrectly passing `req` object in call to `req.responseCb` when handling
1235
- errors during response processing
1236
-
1237
- ## Version 1.1.16 - 29/02/2016
1238
-
1239
- * Address a number of issues detected with the Mocha test suite by a user
1240
-
1241
- ## Version 1.1.17 - 21/03/2016
1242
-
1243
- * Correct reference to non-existant `req` variable in the `Session` objects
1244
- constructor (should be `this`)
1245
-
1246
- ## Version 1.1.18 - 15/05/2015
1247
-
1248
- * Correct argument number and names to the `snmp.createSession()` function
1249
- * Add missing braces to an example in the README.md file
1250
-
1251
- ## Version 1.1.19 - 26/08/2016
1252
-
1253
- * Remove 64bit integer check to ensure a maximum of 8 bytes are given in send
1254
- and received messages
1255
-
1256
- ## Version 1.2.0 - 22/07/2017
1257
-
1258
- * Replace asn1 dependancy with asn1-ber
1259
-
1260
- ## Version 1.2.1 - 11/02/2018
1261
-
1262
- * Add support of 16bit ids to help interoperate with older devices (added the
1263
- `idBitsSize` option to the `createSession()` function
1264
- * Add note to README.md that sessions should be closed when done with
1265
-
1266
- ## Version 1.2.3 - 06/06/2018
1267
-
1268
- * Set NoSpaceships Ltd to be the owner and maintainer
1269
-
1270
- ## Version 1.2.4 - 07/06/2018
1271
-
1272
- * Remove redundant sections from README.md
1273
-
1274
- # License
1275
-
1276
- Copyright (c) 2018 NoSpaceships Ltd <hello@nospaceships.com>
1277
-
1278
- Copyright (c) 2013 Stephen Vickers <stephen.vickers.sv@gmail.com>
1279
-
1280
- Permission is hereby granted, free of charge, to any person obtaining a copy
1281
- of this software and associated documentation files (the "Software"), to deal
1282
- in the Software without restriction, including without limitation the rights
1283
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1284
- copies of the Software, and to permit persons to whom the Software is
1285
- furnished to do so, subject to the following conditions:
1286
-
1287
- The above copyright notice and this permission notice shall be included in
1288
- all copies or substantial portions of the Software.
1289
-
1290
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1291
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1292
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1293
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1294
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1295
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1296
- THE SOFTWARE.
1
+
2
+ # net-snmp
3
+
4
+ This module implements version 1 and 2c of the [Simple Network Management
5
+ Protocol (SNMP)][SNMP].
6
+
7
+ This module is installed using [node package manager (npm)][npm]:
8
+
9
+ npm install net-snmp
10
+
11
+ It is loaded using the `require()` function:
12
+
13
+ var snmp = require ("net-snmp");
14
+
15
+ Sessions to remote hosts can then be created and used to perform SNMP requests
16
+ and send SNMP traps or informs:
17
+
18
+ var session = snmp.createSession ("127.0.0.1", "public");
19
+
20
+ var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
21
+
22
+ session.get (oids, function (error, varbinds) {
23
+ if (error) {
24
+ console.error (error);
25
+ } else {
26
+ for (var i = 0; i < varbinds.length; i++)
27
+ if (snmp.isVarbindError (varbinds[i]))
28
+ console.error (snmp.varbindError (varbinds[i]))
29
+ else
30
+ console.log (varbinds[i].oid + " = " + varbinds[i].value);
31
+ }
32
+
33
+ // If done, close the session
34
+ session.close ();
35
+ });
36
+
37
+ session.trap (snmp.TrapType.LinkDown, function (error) {
38
+ if (error)
39
+ console.error (error);
40
+ });
41
+
42
+ [SNMP]: http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol "SNMP"
43
+ [npm]: https://npmjs.org/ "npm"
44
+
45
+ # Standards Compliance
46
+
47
+ This module aims to be fully compliant with the following RFCs:
48
+
49
+ * [1155][1155] - Structure and Identification of Management Information
50
+ * [1098][1098] - A Simple Network Management Protocol (version 1)
51
+ * [2578][2578] - Structure of Management Information Version 2 (SMIv2)
52
+ * [3416][3416] - Simple Network Management Protocol (SNMP) (version 2c)
53
+
54
+ However, this module does not implement, or export any method that might help
55
+ to implement, the SNMP version 2c report request type.
56
+
57
+ [1155]: https://tools.ietf.org/rfc/rfc1155.txt "RFC 1155"
58
+ [1098]: https://tools.ietf.org/rfc/rfc1098.txt "RFC 1098"
59
+ [2578]: https://tools.ietf.org/rfc/rfc2578.txt "RFC 2578"
60
+ [3416]: https://tools.ietf.org/rfc/rfc3416.txt "RFC 3416"
61
+
62
+ # Constants
63
+
64
+ The following sections describe constants exported and used by this module.
65
+
66
+ ## snmp.Version1 & snmp.Version2c
67
+
68
+ These constants are used to specify which of the two versions supported by
69
+ this module should be used.
70
+
71
+ ## snmp.ErrorStatus
72
+
73
+ This object contains constants for all valid values the error-status field in
74
+ response PDUs can hold. If when parsing a PDU the error-index field contains
75
+ a value not defined in this object the constant `snmp.ErrorStatus.GeneralError`
76
+ will be used instead of the value in the error-status field. The following
77
+ constants are defined in this object:
78
+
79
+ * `NoError`
80
+ * `TooBig`
81
+ * `NoSuchName`
82
+ * `BadValue`
83
+ * `ReadOnly`
84
+ * `GeneralError`
85
+ * `NoAccess`
86
+ * `WrongType`
87
+ * `WrongLength`
88
+ * `WrongEncoding`
89
+ * `WrongValue`
90
+ * `NoCreation`
91
+ * `InconsistentValue`
92
+ * `ResourceUnavailable`
93
+ * `CommitFailed`
94
+ * `UndoFailed`
95
+ * `AuthorizationError`
96
+ * `NotWritable`
97
+ * `InconsistentName`
98
+
99
+ ## snmp.ObjectType
100
+
101
+ This object contains constants used to specify syntax for varbind objects,
102
+ e.g.:
103
+
104
+ var varbind = {
105
+ oid: "1.3.6.1.2.1.1.4.0",
106
+ type: snmp.ObjectType.OctetString,
107
+ value: "user.name@domain.name"
108
+ };
109
+
110
+ The following constants are defined in this object:
111
+
112
+ * `Boolean`
113
+ * `Integer`
114
+ * `OctetString`
115
+ * `Null`
116
+ * `OID`
117
+ * `IpAddress`
118
+ * `Counter`
119
+ * `Gauge`
120
+ * `TimeTicks`
121
+ * `Opaque`
122
+ * `Integer32`
123
+ * `Counter32`
124
+ * `Gauge32`
125
+ * `Unsigned32`
126
+ * `Counter64`
127
+ * `NoSuchObject`
128
+ * `NoSuchInstance`
129
+ * `EndOfMibView`
130
+
131
+ ## snmp.TrapType
132
+
133
+ This object contains constants used to specify a type of SNMP trap. These
134
+ constants are passed to the `trap()` and `inform()` methods exposed by the
135
+ `Session` class. The following constants are defined in this object:
136
+
137
+ * `ColdStart`
138
+ * `WarmStart`
139
+ * `LinkDown`
140
+ * `LinkUp`
141
+ * `AuthenticationFailure`
142
+ * `EgpNeighborLoss`
143
+ * `EnterpriseSpecific`
144
+
145
+ # OID Strings & Varbinds
146
+
147
+ Some parts of this module accept simple OID strings, e.g.:
148
+
149
+ var oid = "1.3.6.1.2.1.1.5.0";
150
+
151
+ Other parts take an OID string, it's type and value. This is collectively
152
+ referred to as a varbind, and is specified as an object, e.g.:
153
+
154
+ var varbind = {
155
+ oid: "1.3.6.1.2.1.1.5.0",
156
+ type: snmp.ObjectType.OctetString,
157
+ value: new Buffer ("host1")
158
+ };
159
+
160
+ The `type` parameter is one of the constants defined in the `snmp.ObjectType`
161
+ object.
162
+
163
+ The JavaScript `true` and `false` keywords are used for the values of varbinds
164
+ with type `Boolean`.
165
+
166
+ All integer based types are specified as expected (this includes `Integer`,
167
+ `Counter`, `Gauge`, `TimeTicks`, `Integer32`, `Counter32`, `Gauge32`, and
168
+ `Unsigned32`), e.g. `-128` or `100`.
169
+
170
+ Since JavaScript does not offer full 64 bit integer support objects with type
171
+ `Counter64` cannot be supported in the same way as other integer types,
172
+ instead [Node.js][nodejs] `Buffer` objects are used. Users are responsible for
173
+ producing (i.e. for `set()` requests) and consuming (i.e. the varbinds passed
174
+ to callback functions) `Buffer` objects. That is, this module does not work
175
+ with 64 bit integers, it simply treats them as opaque `Buffer` objects.
176
+
177
+ Dotted decimal strings are used for the values of varbinds with type `OID`,
178
+ e.g. `1.3.6.1.2.1.1.5.0`.
179
+
180
+ Dotted quad formatted strings are used for the values of varbinds with type
181
+ `IpAddress`, e.g. `192.168.1.1`.
182
+
183
+ [Node.js][nodejs] `Buffer` objects are used for the values of varbinds with
184
+ type `Opaque` and `OctetString`. For varbinds with type `OctetString` this
185
+ module will accept JavaScript strings, but will always give back `Buffer`
186
+ objects.
187
+
188
+ The `NoSuchObject`, `NoSuchInstance` and `EndOfMibView` types are used to
189
+ indicate an error condition. Currently there is no reason for users of this
190
+ module to to build varbinds using these types.
191
+
192
+ [nodejs]: http://nodejs.org "Node.js"
193
+
194
+ # Callback Functions & Error Handling
195
+
196
+ Most of the request methods exposed by this module require a mandatory
197
+ callback function. This function is called once a request has been processed.
198
+ This could be because an error occurred when processing the request, a trap
199
+ has been dispatched or a successful response was received.
200
+
201
+ The first parameter to every callback is an error object. In the case no
202
+ error occurred this parameter will be "null" indicating no error, e.g.:
203
+
204
+ function responseCb (error, varbinds) {
205
+ if (error) {
206
+ console.error (error);
207
+ } else {
208
+ // no error, do something with varbinds
209
+ }
210
+ }
211
+
212
+ When defined, the error parameter is always an instance of the `Error` class,
213
+ or a sub-class described in one of the sub-sections contained in this section.
214
+
215
+ The semantics of error handling is slightly different between SNMP version
216
+ 1 and 2c. In SNMP version 1 if an error occurs when calculating the value for
217
+ one OID the request as a whole will fail, i.e. no OIDs will have a value.
218
+
219
+ This failure manifests itself within the error-status and error-index fields
220
+ of the response. When the error-status field in the response is non-zero,
221
+ i.e. not `snmp.ErrorStatus.NoError` the `callback` will be called with `error`
222
+ defined detailing the error.
223
+
224
+ Requests made with SNMP version 1 can simply assume all OIDs have a value when
225
+ no error object is passed to the `callback`, i.e.:
226
+
227
+ var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
228
+
229
+ session.get (oids, function (error, varbinds) {
230
+ if (error) {
231
+ console.error (error.toString ());
232
+ } else {
233
+ var sysName = varbinds[0].value; // this WILL have a value
234
+ }
235
+ });
236
+
237
+ In SNMP version 2c instead of using the error-status and error-index fields of
238
+ the response to signal an error, the value for the varbind placed in the
239
+ response for an OID will have an object syntax describing an error. The
240
+ error-status and error-index fields of the response will indicate the request
241
+ was successul, i.e. `snmp.ErrorStatus.NoError`.
242
+
243
+ This changes the way in which error checking is performed in the `callback`.
244
+ When using SNMP version 2c each varbind must be checked to see if its value
245
+ was computed and returned successfully:
246
+
247
+ var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
248
+
249
+ session.get (oids, function (error, varbinds) {
250
+ if (error) {
251
+ console.error (error.toString ());
252
+ } else {
253
+ if (varbinds[0].type != snmp.ErrorStatus.NoSuchObject
254
+ && varbinds[0].type != snmp.ErrorStatus.NoSuchInstance
255
+ && varbinds[0].type != snmp.ErrorStatus.EndOfMibView) {
256
+ var sysName = varbinds[0].value;
257
+ } else {
258
+ console.error (snmp.ObjectType[varbinds[0].type] + ": "
259
+ + varbinds[0].oid);
260
+ }
261
+ }
262
+ });
263
+
264
+ This module exports two functions and promotes a specifc pattern to make error
265
+ checking a little simpler. Firstly, regardless of version in use varbinds can
266
+ always be checked. This results in a generic `callback` that can be used for
267
+ both versions.
268
+
269
+ The `isVarbindError()` function can be used to determine if a varbind has an
270
+ error condition. This function takes a single `varbind` parameter and returns
271
+ `true` if the varbind has an error condition, otherwise `false`. The exported
272
+ `varbindError()` function can then be used to obtain the error string
273
+ describing the error, which will include the OID for the varbind:
274
+
275
+ session.get (oids, function (error, varbinds) {
276
+ if (error) {
277
+ console.error (error.toString ());
278
+ } else {
279
+ if (snmp.isVarbindError (varbinds[0])) {
280
+ console.error (snmp.varbindError (varbinds[0]));
281
+ } else {
282
+ var sysName = varbinds[0].value;
283
+ }
284
+ }
285
+ });
286
+
287
+ If the `varbindError` function is called with a varbind for which
288
+ `isVarbindError` would return false, the string `NotAnError` will be returned
289
+ appended with the related OID.
290
+
291
+ The sections following defines the error classes used by this module.
292
+
293
+ ## snmp.RequestFailedError
294
+
295
+ This error indicates a remote host failed to process a request. The exposed
296
+ `message` attribute will contain a detailed error message. This error also
297
+ exposes a `status` attribute which contains the error-index value from a
298
+ response. This will be one of the constants defined in the
299
+ `snmp.ErrorStatus` object.
300
+
301
+ ## snmp.RequestInvalidError
302
+
303
+ This error indicates a failure to render a request message before it could be
304
+ sent. The error can also indicate that a parameter provided was invalid.
305
+ The exposed `message` attribute will contain a detailed error message.
306
+
307
+ ## snmp.RequestTimedOutError
308
+
309
+ This error states that no response was received for a particular request. The
310
+ exposed `message` attribute will contain the value `Request timed out`.
311
+
312
+ ## snmp.ResponseInvalidError
313
+
314
+ This error indicates a failure to parse a response message. The exposed
315
+ `message` attribute will contain a detailed error message.
316
+
317
+ # Using This Module
318
+
319
+ All SNMP requests are made using an instance of the `Session` class. This
320
+ module exports the `createSession()` function which is used to create
321
+ instances of the `Session` class.
322
+
323
+ ## snmp.createSession ([target], [community], [options])
324
+
325
+ The `createSession()` function instantiates and returns an instance of the
326
+ `Session` class:
327
+
328
+ // Default options
329
+ var options = {
330
+ port: 161,
331
+ retries: 1,
332
+ timeout: 5000,
333
+ transport: "udp4",
334
+ trapPort: 162,
335
+ version: snmp.Version1,
336
+ idBitsSize: 16
337
+ };
338
+
339
+ var session = snmp.createSession ("127.0.0.1", "public", options);
340
+
341
+ The optional `target` parameter defaults to `127.0.0.1`. The optional
342
+ `community` parameter defaults to `public`. The optional `options` parameter
343
+ is an object, and can contain the following items:
344
+
345
+ * `port` - UDP port to send requests too, defaults to `161`
346
+ * `retries` - Number of times to re-send a request, defaults to `1`
347
+ * `sourceAddress` - IP address from which SNMP requests should originate,
348
+ there is no default for this option, the operating system will select an
349
+ appropriate source address when the SNMP request is sent
350
+ * `sourcePort` - UDP port from which SNMP requests should originate, defaults
351
+ to an ephemeral port selected by the operation system
352
+ * `timeout` - Number of milliseconds to wait for a response before re-trying
353
+ or failing, defaults to `5000`
354
+ * `transport` - Specify the transport to use, can be either `udp4` or `udp6`,
355
+ defaults to `udp4`
356
+ * `trapPort` - UDP port to send traps and informs too, defaults to `162`
357
+ * `version` - Either `snmp.Version1` or `snmp.Version2c`, defaults to
358
+ `snmp.Version1`
359
+ * `idBitsSize` - Either `16` or `32`, defaults to `32`. Used to reduce the size
360
+ of the generated id for compatibility with some older devices.
361
+
362
+ When a session has been finished with it should be closed:
363
+
364
+ session.close ();
365
+
366
+ ## session.on ("close", callback)
367
+
368
+ The `close` event is emitted by the session when the sessions underlying UDP
369
+ socket is closed.
370
+
371
+ No arguments are passed to the callback.
372
+
373
+ Before this event is emitted all outstanding requests are cancelled, resulting
374
+ in the failure of each outstanding request. The error passed back through to
375
+ each request will be an instance of the `Error` class with the errors
376
+ `message` attribute set to `Socket forcibly closed`.
377
+
378
+ The following example prints a message to the console when a sessions
379
+ underlying UDP socket is closed:
380
+
381
+ session.on ("close", function () {
382
+ console.log ("socket closed");
383
+ });
384
+
385
+ ## session.on ("error", callback)
386
+
387
+ The `error` event is emitted by the session when the sessions underlying UDP
388
+ socket emits an error.
389
+
390
+ The following arguments will be passed to the `callback` function:
391
+
392
+ * `error` - An instance of the `Error` class, the exposed `message` attribute
393
+ will contain a detailed error message.
394
+
395
+ The following example prints a message to the console when an error occurs
396
+ with a sessions underlying UDP socket, the session is then closed:
397
+
398
+ session.on ("error", function (error) {
399
+ console.log (error.toString ());
400
+ session.close ();
401
+ });
402
+
403
+ ## session.close ()
404
+
405
+ The `close()` method closes the sessions underlying UDP socket. This will
406
+ result in the `close` event being emitted by the sessions underlying UDP
407
+ socket which is passed through to the session, resulting in the session also
408
+ emitting a `close` event.
409
+
410
+ The following example closes a sessions underlying UDP socket:
411
+
412
+ session.close ();
413
+
414
+ ## session.get (oids, callback)
415
+
416
+ The `get()` method fetches the value for one or more OIDs.
417
+
418
+ The `oids` parameter is an array of OID strings. The `callback` function is
419
+ called once the request is complete. The following arguments will be passed
420
+ to the `callback` function:
421
+
422
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
423
+ error occurred
424
+ * `varbinds` - Array of varbinds, will not be provided if an error occurred
425
+
426
+ The varbind in position N in the `varbinds` array will correspond to the OID
427
+ in position N in the `oids` array in the request.
428
+
429
+ Each varbind must be checked for an error condition using the
430
+ `snmp.isVarbindError()` function when using SNMP version 2c.
431
+
432
+ The following example fetches values for the sysName (`1.3.6.1.2.1.1.5.0`) and
433
+ sysLocation (`1.3.6.1.2.1.1.6.0`) OIDs:
434
+
435
+ var oids = ["1.3.6.1.2.1.1.5.0", "1.3.6.1.2.1.1.6.0"];
436
+
437
+ session.get (oids, function (error, varbinds) {
438
+ if (error) {
439
+ console.error (error.toString ());
440
+ } else {
441
+ for (var i = 0; i < varbinds.length; i++) {
442
+ // for version 1 we can assume all OIDs were successful
443
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
444
+
445
+ // for version 2c we must check each OID for an error condition
446
+ if (snmp.isVarbindError (varbinds[i]))
447
+ console.error (snmp.varbindError (varbinds[i]));
448
+ else
449
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
450
+ }
451
+ }
452
+ });
453
+
454
+ ## session.getBulk (oids, [nonRepeaters], [maxRepetitions], callback)
455
+
456
+ The `getBulk()` method fetches the value for the OIDs lexicographically
457
+ following one or more OIDs in the MIB tree.
458
+
459
+ The `oids` parameter is an array of OID strings. The optional `nonRepeaters`
460
+ parameter specifies the number of OIDs in the `oids` parameter for which only
461
+ 1 varbind should be returned, and defaults to `0`. For each remaining OID
462
+ in the `oids` parameter the optional `maxRepetitions` parameter specifies how
463
+ many OIDs lexicographically following an OID for which varbinds should be
464
+ fetched, and defaults to `20`.
465
+
466
+ The `callback` function is called once the request is complete. The following
467
+ arguments will be passed to the `callback` function:
468
+
469
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
470
+ error occurred
471
+ * `varbinds` - Array of varbinds, will not be provided if an error occurred
472
+
473
+ The varbind in position N in the `varbinds` array will correspond to the OID
474
+ in position N in the `oids` array in the request.
475
+
476
+ For for the first `nonRepeaters` items in `varbinds` each item will be a
477
+ single varbind. For all remaining items in `varbinds` each item will be an
478
+ array of varbinds - this makes it easy to tie response varbinds with requested
479
+ OIDs since response varbinds are grouped and placed in the same position in
480
+ `varbinds`.
481
+
482
+ Each varbind must be checked for an error condition using the
483
+ `snmp.isVarbindError()` function when using SNMP version 2c.
484
+
485
+ The following example fetches values for the OIDs following the sysContact
486
+ (`1.3.6.1.2.1.1.4.0`) and sysName (`1.3.6.1.2.1.1.5.0`) OIDs, and up to the
487
+ first 20 OIDs in the ifDescr (`1.3.6.1.2.1.2.2.1.2`) and ifType
488
+ (`1.3.6.1.2.1.2.2.1.3`) columns from the ifTable (`1.3.6.1.2.1.2.2`) table:
489
+
490
+ var oids = [
491
+ "1.3.6.1.2.1.1.4.0",
492
+ "1.3.6.1.2.1.1.5.0",
493
+ "1.3.6.1.2.1.2.2.1.2",
494
+ "1.3.6.1.2.1.2.2.1.3"
495
+ ];
496
+
497
+ var nonRepeaters = 2;
498
+
499
+ session.getNext (oids, nonRepeaters, function (error, varbinds) {
500
+ if (error) {
501
+ console.error (error.toString ());
502
+ } else {
503
+ // step through the non-repeaters which are single varbinds
504
+ for (var i = 0; i < nonRepeaters; i++) {
505
+ if (i >= varbinds.length)
506
+ break;
507
+
508
+ if (snmp.isVarbindError (varbinds[i]))
509
+ console.error (snmp.varbindError (varbinds[i]));
510
+ else
511
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
512
+ }
513
+
514
+ // then step through the repeaters which are varbind arrays
515
+ for (var i = nonRepeaters; i < varbinds.length; i++) {
516
+ for (var j = 0; j < varbinds[i].length; j++) {
517
+ if (snmp.isVarbindError (varbinds[i][j]))
518
+ console.error (snmp.varbindError (varbinds[i][j]));
519
+ else
520
+ console.log (varbinds[i][j].oid + "|"
521
+ + varbinds[i][j].value);
522
+ }
523
+ }
524
+ });
525
+
526
+ ## session.getNext (oids, callback)
527
+
528
+ The `getNext()` method fetches the value for the OIDs lexicographically
529
+ following one or more OIDs in the MIB tree.
530
+
531
+ The `oids` parameter is an array of OID strings. The `callback` function is
532
+ called once the request is complete. The following arguments will be passed
533
+ to the `callback` function:
534
+
535
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
536
+ error occurred
537
+ * `varbinds` - Array of varbinds, will not be provided if an error occurred
538
+
539
+ The varbind in position N in the `varbinds` array will correspond to the OID
540
+ in position N in the `oids` array in the request.
541
+
542
+ Each varbind must be checked for an error condition using the
543
+ `snmp.isVarbindError()` function when using SNMP version 2c.
544
+
545
+ The following example fetches values for the next OIDs following the
546
+ sysObjectID (`1.3.6.1.2.1.1.1.0`) and sysName (`1.3.6.1.2.1.1.4.0`) OIDs:
547
+
548
+ var oids = [
549
+ "1.3.6.1.2.1.1.1.0",
550
+ "1.3.6.1.2.1.1.4.0"
551
+ ];
552
+
553
+ session.getNext (oids, function (error, varbinds) {
554
+ if (error) {
555
+ console.error (error.toString ());
556
+ } else {
557
+ for (var i = 0; i < varbinds.length; i++) {
558
+ // for version 1 we can assume all OIDs were successful
559
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
560
+
561
+ // for version 2c we must check each OID for an error condition
562
+ if (snmp.isVarbindError (varbinds[i]))
563
+ console.error (snmp.varbindError (varbinds[i]));
564
+ else
565
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
566
+ }
567
+ }
568
+ });
569
+
570
+ ## session.inform (typeOrOid, [varbinds], [options], callback)
571
+
572
+ The `inform()` method sends a SNMP inform.
573
+
574
+ The `typeOrOid` parameter can be one of two types; one of the constants
575
+ defined in the `snmp.TrapType` object (excluding the
576
+ `snmp.TrapType.EnterpriseSpecific` constant), or an OID string.
577
+
578
+ The first varbind to be placed in the request message will be for the
579
+ `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`). The value for this varbind will
580
+ be the value returned by the `process.uptime ()` function multiplied by 100
581
+ (this can be overridden by providing `upTime` in the optional `options`
582
+ parameter, as documented below).
583
+
584
+ This will be followed by a second varbind for the `snmpTrapOID.0` OID
585
+ (`1.3.6.1.6.3.1.1.4.1.0`). The value for this will depend on the `typeOrOid`
586
+ parameter. If a constant is specified the trap OID for the constant will be
587
+ used as supplied for the varbinds value, otherwise the OID string specified
588
+ will be used as is for the value of the varbind.
589
+
590
+ The optional `varbinds` parameter is an array of varbinds to include in the
591
+ inform request, and defaults to the empty array `[]`.
592
+
593
+ The optional `options` parameter is an object, and can contain the following
594
+ items:
595
+
596
+ * `upTime` - Value of the `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`) in the
597
+ inform, defaults to the value returned by the `process.uptime ()` function
598
+ multiplied by 100
599
+
600
+ The `callback` function is called once a response to the inform request has
601
+ been received, or an error occurred. The following arguments will be passed
602
+ to the `callback` function:
603
+
604
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
605
+ error occurred
606
+ * `varbinds` - Array of varbinds, will not be provided if an error occurred
607
+
608
+ The varbind in position N in the `varbinds` array will correspond to the
609
+ varbind in position N in the `varbinds` array in the request. The remote host
610
+ should echo back varbinds and their values as specified in the request, and
611
+ the `varbinds` array will contain each varbind as sent back by the remote host.
612
+
613
+ Normally there is no reason to use the contents of the `varbinds` parameter
614
+ since the varbinds are as they were sent in the request.
615
+
616
+ The following example sends a generic cold-start inform to a remote host,
617
+ it does not include any varbinds:
618
+
619
+ session.inform (snmp.TrapType.ColdStart, function (error) {
620
+ if (error)
621
+ console.error (error);
622
+ });
623
+
624
+ The following example sends an enterprise specific inform to a remote host,
625
+ and includes two enterprise specific varbinds:
626
+
627
+ var informOid = "1.3.6.1.4.1.2000.1";
628
+
629
+ var varbinds = [
630
+ {
631
+ oid: "1.3.6.1.4.1.2000.2",
632
+ type: snmp.ObjectType.OctetString,
633
+ value: "Periodic hardware self-check"
634
+ },
635
+ {
636
+ oid: "1.3.6.1.4.1.2000.3",
637
+ type: snmp.ObjectType.OctetString,
638
+ value: "hardware-ok"
639
+ }
640
+ ];
641
+
642
+ // Override sysUpTime, specfiying it as 10 seconds...
643
+ var options = {upTime: 1000};
644
+ session.inform (informOid, varbinds, options, function (error) {
645
+ if (error)
646
+ console.error (error);
647
+ });
648
+
649
+ ## session.set (varbinds, callback)
650
+
651
+ The `set()` method sets the value of one or more OIDs.
652
+
653
+ The `varbinds` parameter is an array of varbind objects. The `callback`
654
+ function is called once the request is complete. The following arguments will
655
+ be passed to the `callback` function:
656
+
657
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
658
+ error occurred
659
+ * `varbinds` - Array of varbinds, will not be provided if an error occurred
660
+
661
+ The varbind in position N in the `varbinds` array will correspond to the
662
+ varbind in position N in the `varbinds` array in the request. The remote host
663
+ should echo back varbinds and their values as specified in the request unless
664
+ an error occurred. The `varbinds` array will contain each varbind as sent
665
+ back by the remote host.
666
+
667
+ Each varbind must be checked for an error condition using the
668
+ `snmp.isVarbindError()` function when using SNMP version 2c.
669
+
670
+ The following example sets the value of the sysName (`1.3.6.1.2.1.1.4.0`) and
671
+ sysLocation (`1.3.6.1.2.1.1.6.0`) OIDs:
672
+
673
+ var varbinds = [
674
+ {
675
+ oid: "1.3.6.1.2.1.1.5.0",
676
+ type: snmp.ObjectType.OctetString,
677
+ value: "host1"
678
+ }, {
679
+ oid: "1.3.6.1.2.1.1.6.0",
680
+ type: snmp.ObjectType.OctetString,
681
+ value: "somewhere"
682
+ }
683
+ ];
684
+
685
+ session.set (varbinds, function (error, varbinds) {
686
+ if (error) {
687
+ console.error (error.toString ());
688
+ } else {
689
+ for (var i = 0; i < varbinds.length; i++) {
690
+ // for version 1 we can assume all OIDs were successful
691
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
692
+
693
+ // for version 2c we must check each OID for an error condition
694
+ if (snmp.isVarbindError (varbinds[i]))
695
+ console.error (snmp.varbindError (varbinds[i]));
696
+ else
697
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
698
+ }
699
+ }
700
+ });
701
+
702
+ ## session.subtree (oid, [maxRepetitions], feedCallback, doneCallback)
703
+
704
+ The `subtree()` method fetches the value for all OIDs lexicographically
705
+ following a specified OID in the MIB tree which have the specified OID as
706
+ there base. For example, the OIDs sysName (`1.3.6.1.2.1.1.5.0`) and
707
+ sysLocation (`1.3.6.1.2.1.1.6.0`) both have the same base system
708
+ (`1.3.6.1.2.1.1`) OID.
709
+
710
+ For SNMP version 1 repeated `get()` calls are made until the one of the
711
+ returned OIDs does not use the specified OID as its base. For SNMP version
712
+ 2c repeated `getBulk()` calls are made until the one of the returned OIDs
713
+ does no used the specified OID as its base.
714
+
715
+ The `oid` parameter is an OID string. The optional `maxRepetitions` parameter
716
+ is passed to `getBulk()` requests when SNMP version 2c is being used.
717
+
718
+ This method will not call a single callback once all OID values are fetched.
719
+ Instead the `feedCallback` function will be called each time a response is
720
+ received from the remote host. The following arguments will be passed to the
721
+ `feedCallback` function:
722
+
723
+ * `varbinds` - Array of varbinds, and will contain at least one varbind
724
+
725
+ Each varbind must be checked for an error condition using the
726
+ `snmp.isVarbindError()` function when using SNMP version 2c.
727
+
728
+ Once at least one of the returned OIDs does not use the specified OID as its
729
+ base, or an error has occurred, the `doneCallback` function will be called.
730
+ The following arguments will be passed to the `doneCallback` function:
731
+
732
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
733
+ error occurred
734
+
735
+ Once the `doneCallback` function has been called the request is complete and
736
+ the `feedCallback` function will no longer be called.
737
+
738
+ If the `feedCallback` function returns a `true` value when called no more
739
+ `get()` or `getBulk()` method calls will be made and the `doneCallback` will
740
+ be called.
741
+
742
+ The following example fetches all OIDS under the system (`1.3.6.1.2.1.1`) OID:
743
+
744
+ var oid = "1.3.6.1.2.1.1";
745
+
746
+ function doneCb (error) {
747
+ if (error)
748
+ console.error (error.toString ());
749
+ }
750
+
751
+ function feedCb (varbinds) {
752
+ for (var i = 0; i < varbinds.length; i++) {
753
+ if (snmp.isVarbindError (varbinds[i]))
754
+ console.error (snmp.varbindError (varbinds[i]));
755
+ else
756
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
757
+ }
758
+ }
759
+
760
+ var maxRepetitions = 20;
761
+
762
+ // The maxRepetitions argument is optional, and will be ignored unless using
763
+ // SNMP verison 2c
764
+ session.subtree (oid, maxRepetitions, feedCb, doneCb);
765
+
766
+ ## session.table (oid, [maxRepetitions], callback)
767
+
768
+ The `table()` method fetches the value for all OIDs lexicographically
769
+ following a specified OID in the MIB tree which have the specified OID as
770
+ there base, much like the `subtree()` method.
771
+
772
+ This method is designed to fetch conceptial tables, for example the ifTable
773
+ (`1.3.6.1.2.1.2.2`) table. The values for returned varbinds will be structured
774
+ into objects to represent conceptual rows. Each row is then placed into an
775
+ object with the rows index being the key, e.g.:
776
+
777
+ var table = {
778
+ // Rows keyed by ifIndex (1 and 2 are shown)
779
+ 1: {
780
+ // ifDescr (column 2) and ifType (columnd 3) are shown
781
+ 2: "interface-1",
782
+ 3: 6,
783
+ ...
784
+ },
785
+ 2: {
786
+ 2: "interface-2",
787
+ 3: 6,
788
+ ...
789
+ },
790
+ ...
791
+ }
792
+
793
+ Internally this method calls the `subtree()` method to obtain the subtree of
794
+ the specified table.
795
+
796
+ The `oid` parameter is an OID string. If an OID string is passed which does
797
+ not represent a table the resulting object produced to hold table data will be
798
+ empty, i.e. it will contain no indexes and rows. The optional
799
+ `maxRepetitions` parameter is passed to the `subtree()` request.
800
+
801
+ The `callback` function will be called once the entire table has been fetched.
802
+ The following arguments will be passed to the `callback` function:
803
+
804
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
805
+ error occurred
806
+ * `table` - Object containing object references representing conceptual
807
+ rows keyed by index (e.g. for the ifTable table rows are keyed by ifIndex),
808
+ each row object will contain values keyed by column number, will not be
809
+ provided if an error occurred
810
+
811
+ If an error occurs with any varbind returned by `subtree()` no table will be
812
+ passed to the `callback` function. The reason for failure, and the related
813
+ OID string (as returned from a call to the `snmp.varbindError()` function),
814
+ will be passed to the `callback` function in the `error` argument as an
815
+ instance of the `RequestFailedError` class.
816
+
817
+ The following example fetches the ifTable (`1.3.6.1.2.1.2.2`) table:
818
+
819
+ var oid = "1.3.6.1.2.1.2.2";
820
+
821
+ function sortInt (a, b) {
822
+ if (a > b)
823
+ return 1;
824
+ else if (b > a)
825
+ return -1;
826
+ else
827
+ return 0;
828
+ }
829
+
830
+ function responseCb (error, table) {
831
+ if (error) {
832
+ console.error (error.toString ());
833
+ } else {
834
+ // This code is purely used to print rows out in index order,
835
+ // ifIndex's are integers so we'll sort them numerically using
836
+ // the sortInt() function above
837
+ var indexes = [];
838
+ for (index in table)
839
+ indexes.push (parseInt (index));
840
+ indexes.sort (sortInt);
841
+
842
+ // Use the sorted indexes we've calculated to walk through each
843
+ // row in order
844
+ for (var i = 0; i < indexes.length; i++) {
845
+ // Like indexes we sort by column, so use the same trick here,
846
+ // some rows may not have the same columns as other rows, so
847
+ // we calculate this per row
848
+ var columns = [];
849
+ for (column in table[indexes[i]])
850
+ columns.push (parseInt (column));
851
+ columns.sort (sortInt);
852
+
853
+ // Print index, then each column indented under the index
854
+ console.log ("row for index = " + indexes[i]);
855
+ for (var j = 0; j < columns.length; j++) {
856
+ console.log (" column " + columns[j] + " = "
857
+ + table[indexes[i]][columns[j]]);
858
+ }
859
+ }
860
+ }
861
+ }
862
+
863
+ var maxRepetitions = 20;
864
+
865
+ // The maxRepetitions argument is optional, and will be ignored unless using
866
+ // SNMP verison 2c
867
+ session.table (oid, maxRepetitions, responseCb);
868
+
869
+ ## session.tableColumns (oid, columns, [maxRepetitions], callback)
870
+
871
+ The `tableColumns()` method implements the same interface as the `table()`
872
+ method. However, only the columns specified in the `columns` parameter will
873
+ be in the resulting table.
874
+
875
+ This method should be used when only selected columns are required, and
876
+ will be many times faster than the `table()` method since a much smaller
877
+ amount of data will be fected.
878
+
879
+ The following example fetches the ifTable (`1.3.6.1.2.1.2.2`) table, and
880
+ specifies that only the ifDescr (`1.3.6.1.2.1.2.2.1.2`) and ifPhysAddress
881
+ (`1.3.6.1.2.1.2.2.1.6`) columns should actually be fetched:
882
+
883
+ var oid = "1.3.6.1.2.1.2.2";
884
+ var columns = [2, 6];
885
+
886
+ function sortInt (a, b) {
887
+ if (a > b)
888
+ return 1;
889
+ else if (b > a)
890
+ return -1;
891
+ else
892
+ return 0;
893
+ }
894
+
895
+ function responseCb (error, table) {
896
+ if (error) {
897
+ console.error (error.toString ());
898
+ } else {
899
+ // This code is purely used to print rows out in index order,
900
+ // ifIndex's are integers so we'll sort them numerically using
901
+ // the sortInt() function above
902
+ var indexes = [];
903
+ for (index in table)
904
+ indexes.push (parseInt (index));
905
+ indexes.sort (sortInt);
906
+
907
+ // Use the sorted indexes we've calculated to walk through each
908
+ // row in order
909
+ for (var i = 0; i < indexes.length; i++) {
910
+ // Like indexes we sort by column, so use the same trick here,
911
+ // some rows may not have the same columns as other rows, so
912
+ // we calculate this per row
913
+ var columns = [];
914
+ for (column in table[indexes[i]])
915
+ columns.push (parseInt (column));
916
+ columns.sort (sortInt);
917
+
918
+ // Print index, then each column indented under the index
919
+ console.log ("row for index = " + indexes[i]);
920
+ for (var j = 0; j < columns.length; j++) {
921
+ console.log (" column " + columns[j] + " = "
922
+ + table[indexes[i]][columns[j]]);
923
+ }
924
+ }
925
+ }
926
+ }
927
+
928
+ var maxRepetitions = 20;
929
+
930
+ // The maxRepetitions argument is optional, and will be ignored unless using
931
+ // SNMP verison 2c
932
+ session.tableColumns (oid, columns, maxRepetitions, responseCb);
933
+
934
+ ## session.trap (typeOrOid, [varbinds], [agentAddrOrOptions], callback)
935
+
936
+ The `trap()` method sends a SNMP trap.
937
+
938
+ The `typeOrOid` parameter can be one of two types; one of the constants
939
+ defined in the `snmp.TrapType` object (excluding the
940
+ `snmp.TrapType.EnterpriseSpecific` constant), or an OID string.
941
+
942
+ For SNMP version 1 when a constant is specified the following fields are set in
943
+ the trap:
944
+
945
+ * The enterprise field is set to the OID `1.3.6.1.4.1`
946
+ * The generic-trap field is set to the constant specified
947
+ * The specific-trap field is set to 0
948
+
949
+ When an OID string is specified the following fields are set in the trap:
950
+
951
+ * The final decimal is stripped from the OID string and set in the
952
+ specific-trap field
953
+ * The remaining OID string is set in the enterprise field
954
+ * The generic-trap field is set to the constant
955
+ `snmp.TrapType.EnterpriseSpecific`
956
+
957
+ In both cases the time-stamp field in the trap PDU is set to the value
958
+ returned by the `process.uptime ()` function multiplied by `100`.
959
+
960
+ SNMP version 2c messages are quite different in comparison with version 1.
961
+ The version 2c trap has a much simpler format, simply a sequence of varbinds.
962
+ The first varbind to be placed in the trap message will be for the
963
+ `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`). The value for this varbind will
964
+ be the value returned by the `process.uptime ()` function multiplied by 100
965
+ (this can be overridden by providing `upTime` in the optional `options`
966
+ parameter, as documented below).
967
+
968
+ This will be followed by a second varbind for the `snmpTrapOID.0` OID
969
+ (`1.3.6.1.6.3.1.1.4.1.0`). The value for this will depend on the `typeOrOid`
970
+ parameter. If a constant is specified the trap OID for the constant
971
+ will be used as supplied for the varbinds value, otherwise the OID string
972
+ specified will be used as is for the value of the varbind.
973
+
974
+ The optional `varbinds` parameter is an array of varbinds to include in the
975
+ trap, and defaults to the empty array `[]`.
976
+
977
+ The optional `agentAddrOrOptions` parameter can be one of two types; one is
978
+ the IP address used to populate the agent-addr field for SNMP version 1 type
979
+ traps, and defaults to `127.0.0.1`, or an object, and can contain the
980
+ following items:
981
+
982
+ * `agentAddr` - IP address used to populate the agent-addr field for SNMP
983
+ version 1 type traps, and defaults to `127.0.0.1`
984
+ * `upTime` - Value of the `sysUptime.0` OID (`1.3.6.1.6.3.1.1.4.1.0`) in the
985
+ trap, defaults to the value returned by the `process.uptime ()` function
986
+ multiplied by 100
987
+
988
+ **NOTE** When using SNMP version 2c the `agentAddr` parameter is ignored if
989
+ specified since version 2c trap messages do not have an agent-addr field.
990
+
991
+ The `callback` function is called once the trap has been sent, or an error
992
+ occurred. The following arguments will be passed to the `callback` function:
993
+
994
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
995
+ error occurred
996
+
997
+ The following example sends an enterprise specific trap to a remote host using
998
+ a SNMP version 1 trap, and includes the sysName (`1.3.6.1.2.1.1.5.0`) varbind
999
+ in the trap. Before the trap is sent the `agentAddr` field is calculated using
1000
+ DNS to resolve the hostname of the local host:
1001
+
1002
+ var enterpriseOid = "1.3.6.1.4.1.2000.1"; // made up, but it may be valid
1003
+
1004
+ var varbinds = [
1005
+ {
1006
+ oid: "1.3.6.1.2.1.1.5.0",
1007
+ type: snmp.ObjectType.OctetString,
1008
+ value: "host1"
1009
+ }
1010
+ ];
1011
+
1012
+ dns.lookup (os.hostname (), function (error, agentAddress) {
1013
+ if (error) {
1014
+ console.error (error);
1015
+ } else {
1016
+ // Override sysUpTime, specfiying it as 10 seconds...
1017
+ var options = {agentAddr: agentAddress, upTime: 1000};
1018
+ session.trap (enterpriseOid, varbinds, agentAddress,
1019
+ function (error) {
1020
+ if (error)
1021
+ console.error (error);
1022
+ });
1023
+ }
1024
+ });
1025
+
1026
+ The following example sends a generic link-down trap to a remote host using a
1027
+ SNMP version 1 trap, it does not include any varbinds or specify the
1028
+ `agentAddr` parameter:
1029
+
1030
+ session.trap (snmp.TrapType.LinkDown, function (error) {
1031
+ if (error)
1032
+ console.error (error);
1033
+ });
1034
+
1035
+ The following example sends an enterprise specific trap to a remote host using
1036
+ a SNMP version 2c trap, and includes two enterprise specific varbinds:
1037
+
1038
+ var trapOid = "1.3.6.1.4.1.2000.1";
1039
+
1040
+ var varbinds = [
1041
+ {
1042
+ oid: "1.3.6.1.4.1.2000.2",
1043
+ type: snmp.ObjectType.OctetString,
1044
+ value: "Hardware health status changed"
1045
+ },
1046
+ {
1047
+ oid: "1.3.6.1.4.1.2000.3",
1048
+ type: snmp.ObjectType.OctetString,
1049
+ value: "status-error"
1050
+ }
1051
+ ];
1052
+
1053
+ // version 2c should have been specified when creating the session
1054
+ session.trap (trapOid, varbinds, function (error) {
1055
+ if (error)
1056
+ console.error (error);
1057
+ });
1058
+
1059
+ ## session.walk (oid, [maxRepetitions], feedCallback, doneCallback)
1060
+
1061
+ The `walk()` method fetches the value for all OIDs lexicographically following
1062
+ a specified OID in the MIB tree.
1063
+
1064
+ For SNMP version 1 repeated `get()` calls are made until the end of the MIB
1065
+ tree is reached. For SNMP version 2c repeated `getBulk()` calls are made
1066
+ until the end of the MIB tree is reached.
1067
+
1068
+ The `oid` parameter is an OID string. The optional `maxRepetitions` parameter
1069
+ is passed to `getBulk()` requests when SNMP version 2c is being used.
1070
+
1071
+ This method will not call a single callback once all OID values are fetched.
1072
+ Instead the `feedCallback` function will be called each time a response is
1073
+ received from the remote host. The following arguments will be passed to the
1074
+ `feedCallback` function:
1075
+
1076
+ * `varbinds` - Array of varbinds, and will contain at least one varbind
1077
+
1078
+ Each varbind must be checked for an error condition using the
1079
+ `snmp.isVarbindError()` function when using SNMP version 2c.
1080
+
1081
+ Once the end of the MIB tree has been reached, or an error has occurred, the
1082
+ `doneCallback` function will be called. The following arguments will be
1083
+ passed to the `doneCallback` function:
1084
+
1085
+ * `error` - Instance of the `Error` class or a sub-class, or `null` if no
1086
+ error occurred
1087
+
1088
+ Once the `doneCallback` function has been called the request is complete and
1089
+ the `feedCallback` function will no longer be called.
1090
+
1091
+ If the `feedCallback` function returns a `true` value when called no more
1092
+ `get()` or `getBulk()` method calls will be made and the `doneCallback` will
1093
+ be called.
1094
+
1095
+ The following example walks to the end of the MIB tree starting from the
1096
+ ifTable (`1.3.6.1.2.1.2.2`) OID:
1097
+
1098
+ var oid = "1.3.6.1.2.1.2.2";
1099
+
1100
+ function doneCb (error) {
1101
+ if (error)
1102
+ console.error (error.toString ());
1103
+ }
1104
+
1105
+ function feedCb (varbinds) {
1106
+ for (var i = 0; i < varbinds.length; i++) {
1107
+ if (snmp.isVarbindError (varbinds[i]))
1108
+ console.error (snmp.varbindError (varbinds[i]));
1109
+ else
1110
+ console.log (varbinds[i].oid + "|" + varbinds[i].value);
1111
+ }
1112
+ }
1113
+
1114
+ var maxRepetitions = 20;
1115
+
1116
+ // The maxRepetitions argument is optional, and will be ignored unless using
1117
+ // SNMP verison 2c
1118
+ session.walk (oid, maxRepetitions, feedCb, doneCb);
1119
+
1120
+ # Example Programs
1121
+
1122
+ Example programs are included under the modules `example` directory.
1123
+
1124
+ # Changes
1125
+
1126
+ ## Version 1.0.0 - 14/01/2013
1127
+
1128
+ * Initial release including only SNMP version 1 support
1129
+
1130
+ ## Version 1.1.0 - 20/01/2013
1131
+
1132
+ * Implement SNMP version 2c support
1133
+
1134
+ ## Version 1.1.1 - 21/01/2013
1135
+
1136
+ * Correct name used in example `require()` call to include this module
1137
+
1138
+ ## Version 1.1.2 - 22/01/2013
1139
+
1140
+ * Implement `subtree()`, `table()` and `walk()` methods
1141
+ * Support IPv6 (added `transport` option to the `createSession()` function)
1142
+ * Re-order some methods in README.md
1143
+
1144
+ ## Version 1.1.3 - 27/01/2013
1145
+
1146
+ * Fix some typos and grammar errors in README.md
1147
+ * Example `snmp-table` program had `snmp-subtree` in its usage message
1148
+ * Implement example `snmp-tail` program to constantly poll for an OIDs value
1149
+ * Add note to README.md about the ability to stop the `walk()` and `subtree()`
1150
+ methods by returning `true`
1151
+
1152
+ ## Version 1.1.4 - 29/01/2013
1153
+
1154
+ * Fix incorrect usage of the term "NPM" in README.md, should be "npm"
1155
+
1156
+ ## Version 1.1.5 - 05/02/2013
1157
+
1158
+ * The `transport` option to `createSession()` was not used
1159
+
1160
+ ## Version 1.1.6 - 12/04/2013
1161
+
1162
+ * Implement `tableColumns()` method
1163
+ * Added example program `snmp-table-columns.js`
1164
+ * Correct name of the `table` parameter to the `table()` callback
1165
+ * Slight OID comparison performance enhancement
1166
+
1167
+ ## Version 1.1.7 - 11/05/2013
1168
+
1169
+ * Use MIT license instead of GPL
1170
+
1171
+ ## Version 1.1.8 - 22/06/2013
1172
+
1173
+ * Added the example program `cisco-device-inventory.js`
1174
+ * Receive `Trap failed: TypeError: value is out of bounds` when sending
1175
+ traps using SNMP version 2c
1176
+
1177
+ ## Version 1.1.9 - 03/11/2013
1178
+
1179
+ * Corrected a few instances of the parameter named `requestCallback` to some
1180
+ methods in the README.md file which should have been `feedCallback`
1181
+ * Null type is used for varbinds with a 0 value
1182
+ * Correct instances of snmp.Type to snmp.ObjectType in the README.md file
1183
+
1184
+ ## Version 1.1.10 - 01/12/2013
1185
+
1186
+ * Error handler in the `dgram.send()` callback in the `send()` method was
1187
+ creating a new instance of the `Error` class from the `error` parameter, but
1188
+ it was already an instance of the `Error` class (thanks Ray Solomon)
1189
+ * Add stack traces to Error classes exported by this module (thanks Ray
1190
+ Solomon)
1191
+ * Allow users to specify `0` retries when creating a session (thanks Ray
1192
+ Solomon)
1193
+ * Update the list of SNMP version 1 related RFCs we adhere to in the
1194
+ `Standards Compliance` section of the README.md file
1195
+
1196
+ ## Version 1.1.11 - 27/12/2013
1197
+
1198
+ * Add `sourceAddress` and `sourcePort` optional options to the
1199
+ `Session` classes `createSession()` method, which can be used to control
1200
+ from which IP address and port messages should be sent
1201
+ * Allow users to specify sysUpTime for SNMP traps and informs
1202
+
1203
+ ## Version 1.1.12 - 02/04/2014
1204
+
1205
+ * The `agentAddr` attribute is not used when passed in the `options` object
1206
+ to the `trap()` method
1207
+
1208
+ ## Version 1.1.13 - 12/08/2014
1209
+
1210
+ * Not catching error events for the UDP socket returned from the
1211
+ `dgram.createSocket()` function
1212
+ * Some request methods do not copy arguments which results in sometimes
1213
+ unexpected behaviour
1214
+ * Use a single UDP socket for all requests in a single SNMP session
1215
+ * Use a try/catch block in the timer callback in the `Session.send()` method
1216
+ * The `Session` can now emit an `error` event to catch errors in a sessions
1217
+ underlying UDP socket
1218
+ * The `Session` can now emit a `close` event to catch close events from a
1219
+ sessions underlying UDP socket, which results in the cancellation of
1220
+ all outstanding requests
1221
+ * Added a `close()` method to `Session` to close a sessions underlying UDP
1222
+ socket, which results a `close` event
1223
+ * Signed integers are treated as unsigned integers when parsing response
1224
+ messages
1225
+
1226
+ ## Version 1.1.14 - 22/09/2015
1227
+
1228
+ * Host repository on GitHub
1229
+
1230
+ ## Version 1.1.15 - 08/02/2016
1231
+
1232
+ * When parsing an invalid response an exception in message parsing does not
1233
+ interupt response processing
1234
+ * Incorrectly passing `req` object in call to `req.responseCb` when handling
1235
+ errors during response processing
1236
+
1237
+ ## Version 1.1.16 - 29/02/2016
1238
+
1239
+ * Address a number of issues detected with the Mocha test suite by a user
1240
+
1241
+ ## Version 1.1.17 - 21/03/2016
1242
+
1243
+ * Correct reference to non-existant `req` variable in the `Session` objects
1244
+ constructor (should be `this`)
1245
+
1246
+ ## Version 1.1.18 - 15/05/2015
1247
+
1248
+ * Correct argument number and names to the `snmp.createSession()` function
1249
+ * Add missing braces to an example in the README.md file
1250
+
1251
+ ## Version 1.1.19 - 26/08/2016
1252
+
1253
+ * Remove 64bit integer check to ensure a maximum of 8 bytes are given in send
1254
+ and received messages
1255
+
1256
+ ## Version 1.2.0 - 22/07/2017
1257
+
1258
+ * Replace asn1 dependancy with asn1-ber
1259
+
1260
+ ## Version 1.2.1 - 11/02/2018
1261
+
1262
+ * Add support of 16bit ids to help interoperate with older devices (added the
1263
+ `idBitsSize` option to the `createSession()` function
1264
+ * Add note to README.md that sessions should be closed when done with
1265
+
1266
+ ## Version 1.2.3 - 06/06/2018
1267
+
1268
+ * Set NoSpaceships Ltd to be the owner and maintainer
1269
+
1270
+ ## Version 1.2.4 - 07/06/2018
1271
+
1272
+ * Remove redundant sections from README.md
1273
+
1274
+ # License
1275
+
1276
+ Copyright (c) 2018 NoSpaceships Ltd <hello@nospaceships.com>
1277
+
1278
+ Copyright (c) 2013 Stephen Vickers <stephen.vickers.sv@gmail.com>
1279
+
1280
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1281
+ of this software and associated documentation files (the "Software"), to deal
1282
+ in the Software without restriction, including without limitation the rights
1283
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1284
+ copies of the Software, and to permit persons to whom the Software is
1285
+ furnished to do so, subject to the following conditions:
1286
+
1287
+ The above copyright notice and this permission notice shall be included in
1288
+ all copies or substantial portions of the Software.
1289
+
1290
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1291
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1292
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1293
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1294
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1295
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1296
+ THE SOFTWARE.