universal node.js shebang; snmp.node.js now appends range id without adding a dot
Costa Tsaousis (ktsaou) committed
Feb 17, 2016 at 23:11 UTC
29e3d0e870346f2f2dc26f59c5bd3253ec01647d
2 files changed
+29
-10
node.d/snmp.node.js
+18
-9
@@ -21,13 +21,13 @@
21
"priority": 1,
22
"dimensions": {
23
"in": {
24
- "oid": "1.3.6.1.2.1.2.2.1.10.1",
24
+ "oid": ".1.3.6.1.2.1.2.2.1.10.1",
25
"algorithm": "incremental",
26
"multiplier": 8,
27
"divisor": 1024
28
},
29
"out": {
30
- "oid": "1.3.6.1.2.1.2.2.1.16.1",
30
+ "oid": ".1.3.6.1.2.1.2.2.1.16.1",
31
"algorithm": "incremental",
32
"multiplier": -8,
33
"divisor": 1024
@@ -41,13 +41,13 @@
41
"priority": 1,
42
"dimensions": {
43
"in": {
44
- "oid": "1.3.6.1.2.1.2.2.1.10.2",
44
+ "oid": ".1.3.6.1.2.1.2.2.1.10.2",
45
"algorithm": "incremental",
46
"multiplier": 8,
47
"divisor": 1024
48
},
49
"out": {
50
- "oid": "1.3.6.1.2.1.2.2.1.16.2",
50
+ "oid": ".1.3.6.1.2.1.2.2.1.16.2",
51
"algorithm": "incremental",
52
"multiplier": -8,
53
"divisor": 1024
@@ -82,13 +82,13 @@
82
"multiply_range": [ 1, 24 ],
83
"dimensions": {
84
"in": {
85
- "oid": "1.3.6.1.2.1.2.2.1.10",
85
+ "oid": ".1.3.6.1.2.1.2.2.1.10.",
86
"algorithm": "incremental",
87
"multiplier": 8,
88
"divisor": 1024
89
},
90
"out": {
91
- "oid": "1.3.6.1.2.1.2.2.1.16",
91
+ "oid": ".1.3.6.1.2.1.2.2.1.16.",
92
"algorithm": "incremental",
93
"multiplier": -8,
94
"divisor": 1024
@@ -110,6 +110,13 @@ if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plug
110
netdata.processors.snmp = {
111
name: 'snmp',
112
113
+ fixoid: function(oid) {
114
+ if(oid.charAt(0) === '.')
115
+ return oid.substring(1, oid.length);
116
+
117
+ return oid;
118
+ },
119
+
120
process: function(service, callback) {
121
if(typeof service.snmp_oids === 'undefined' || service.snmp_oids === null || service.snmp_oids.length === 0) {
122
// this is the first time we see this service
@@ -128,11 +135,13 @@ netdata.processors.snmp = {
135
for(var d in service.request.charts[c].dimensions) {
136
// for each dimension in the chart
137
138
+ var oid = this.fixoid(service.request.charts[c].dimensions[d].oid);
139
+
140
if(netdata.options.DEBUG === true)
132
- netdata.debug(service.module.name + ': ' + service.name + ': indexing ' + this.name + ' chart: ' + c + ', dimension: ' + d + ', OID: ' + service.request.charts[c].dimensions[d].oid);
141
+ netdata.debug(service.module.name + ': ' + service.name + ': indexing ' + this.name + ' chart: ' + c + ', dimension: ' + d + ', OID: ' + oid);
142
143
// link it to the point we need to set the value to
135
- service.snmp_oids_index[service.request.charts[c].dimensions[d].oid] = service.request.charts[c].dimensions[d];
144
+ service.snmp_oids_index[oid] = service.request.charts[c].dimensions[d];
145
146
// and set the value to null
147
service.request.charts[c].dimensions[d].value = null;
@@ -291,7 +300,7 @@ var snmp = {
300
chart.title += from.toString();
301
chart.priority = prio++;
302
for(var d in chart.dimensions) {
294
- chart.dimensions[d].oid += '.' + from.toString();
303
+ chart.dimensions[d].oid += from.toString();
304
}
305
service.request.charts[id] = chart;
306
from++;
plugins.d/node.d.plugin
+11
-1
@@ -1,4 +1,14 @@
1
-#!/usr/bin/env node
1
+#!/bin/sh
2
+':' //; exec "$(command -v nodejs || command -v node || command -v js || echo "ERROR node.js IS NOT AVAILABLE IN THIS SYSTEM")" "$0" "$@"
3
+
4
+// shebang hack from:
5
+// http://unix.stackexchange.com/questions/65235/universal-node-js-shebang
6
+
7
+// Initially this is run as a shell script (#!/bin/sh).
8
+// Then, the second line, finds nodejs or node or js in the system path
9
+// and executes it with the shell parameters.
10
+
11
+// --------------------------------------------------------------------------------------------------------------------
12
13
'use strict';
14