]> arthur.barton.de Git - netdata.git/commitdiff
improvements suggested by codeclimate
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 7 Jan 2017 13:05:32 +0000 (15:05 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 7 Jan 2017 16:51:33 +0000 (18:51 +0200)
.codeclimate.yml
node.d/snmp.node.js
web/dashboard.js
web/index.html

index 4fd4e3b6eb7f0e7436900c8f09b551b847025cb4..91e0babae88d9a16d1f68e0673b531e25712f0e1 100644 (file)
@@ -20,6 +20,14 @@ engines:
         enabled: false
       complexity:
         enabled: false
+      no-eval:
+        enabled: false
+      no-extend-native:
+        enabled: false
+      no-void:
+        enabled: false
+      no-alert:
+        enabled: false
   fixme:
     enabled: false
   phpmd:
index b38ac1666e25dffeb29e5cc657aa0befd40ae905..5a478937e99e56e8516cd4e80033cc20aac2abcc 100644 (file)
@@ -109,7 +109,7 @@ var net_snmp = require('net-snmp');
 var extend = require('extend');
 var netdata = require('netdata');
 
-if(netdata.options.DEBUG === true) netdata.debug('loaded ' + __filename + ' plugin');
+if(netdata.options.DEBUG === true) netdata.debug('loaded', __filename, ' plugin');
 
 netdata.processors.snmp = {
     name: 'snmp',
@@ -125,62 +125,72 @@ netdata.processors.snmp = {
     },
 
     prepare: function(service) {
+        var __DEBUG = netdata.options.DEBUG;
+
         if(typeof service.snmp_oids === 'undefined' || service.snmp_oids === null || service.snmp_oids.length === 0) {
             // this is the first time we see this service
 
-            if(netdata.options.DEBUG === true)
+            if(__DEBUG === true)
                 netdata.debug(service.module.name + ': ' + service.name + ': preparing ' + this.name + ' OIDs');
 
             // build an index of all OIDs
             service.snmp_oids_index = {};
-            for(var c in service.request.charts) {
+            var chart_keys = Object.keys(service.request.charts);
+            var chart_keys_len = chart_keys.length;
+            while(chart_keys_len--) {
+                var c = chart_keys[chart_keys_len];
+                var chart = service.request.charts[c];
+
                 // for each chart
 
-                if(netdata.options.DEBUG === true)
+                if(__DEBUG === true)
                     netdata.debug(service.module.name + ': ' + service.name + ': indexing ' + this.name + ' chart: ' + c);
 
-                if(typeof service.request.charts[c].titleoid !== 'undefined') {
-                        service.snmp_oids_index[this.fixoid(service.request.charts[c].titleoid)] = {
+                if(typeof chart.titleoid !== 'undefined') {
+                        service.snmp_oids_index[this.fixoid(chart.titleoid)] = {
                             type: 'title',
-                            link: service.request.charts[c]
+                            link: chart
                         };
                     }
 
-                for(var d in service.request.charts[c].dimensions) {
+                var dim_keys = Object.keys(chart.dimensions);
+                var dim_keys_len = dim_keys.length;
+                while(dim_keys_len--) {
+                    var d = dim_keys[dim_keys_len];
+                    var dim = chart.dimensions[d];
+
                     // for each dimension in the chart
 
-                    var oid = this.fixoid(service.request.charts[c].dimensions[d].oid);
-                    var oidname = this.fixoid(service.request.charts[c].dimensions[d].oidname);
+                    var oid = this.fixoid(dim.oid);
+                    var oidname = this.fixoid(dim.oidname);
                     
-                    if(netdata.options.DEBUG === true)
+                    if(__DEBUG === true)
                         netdata.debug(service.module.name + ': ' + service.name + ': indexing ' + this.name + ' chart: ' + c + ', dimension: ' + d + ', OID: ' + oid + ", OID name: " + oidname);
 
                     // link it to the point we need to set the value to
                     service.snmp_oids_index[oid] = {
                         type: 'value',
-                        link: service.request.charts[c].dimensions[d]
+                        link: dim
                     };
 
                     if(typeof oidname !== 'undefined')
                         service.snmp_oids_index[oidname] = {
                             type: 'name',
-                            link: service.request.charts[c].dimensions[d]
+                            link: dim
                         };
 
                     // and set the value to null
-                    service.request.charts[c].dimensions[d].value = null;
+                    dim.value = null;
                 }
             }
 
-            if(netdata.options.DEBUG === true)
+            if(__DEBUG === true)
                 netdata.debug(service.module.name + ': ' + service.name + ': indexed ' + this.name + ' OIDs: ' + netdata.stringify(service.snmp_oids_index));
 
             // now create the array of OIDs needed by net-snmp
-            service.snmp_oids = new Array();
-            for(var o in service.snmp_oids_index)
-                service.snmp_oids.push(o);
+            service.snmp_oids = Object.keys(service.snmp_oids_index);
 
-            if(netdata.options.DEBUG === true)
+            if(__DEBUG === true)
                 netdata.debug(service.module.name + ': ' + service.name + ': final list of ' + this.name + ' OIDs: ' + netdata.stringify(service.snmp_oids));
 
             service.snmp_oids_cleaned = 0;
@@ -189,14 +199,19 @@ netdata.processors.snmp = {
             service.snmp_oids_cleaned = 1;
 
             // the second time, keep only values
+
             service.snmp_oids = new Array();
-            for(var o in service.snmp_oids_index)
-                if(service.snmp_oids_index[o].type === 'value')
-                    service.snmp_oids.push(o);
+            var oid_keys = Object.keys(service.snmp_oids_index);
+            var oid_keys_len = oid_keys.length;
+            while(oid_keys_len--) {
+                if (service.snmp_oids_index[oid_keys[oid_keys_len]].type === 'value')
+                    service.snmp_oids.push(oid_keys[oid_keys_len]);
+            }
         }
     },
 
     getdata: function(service, index, ok, failed, callback) {
+        var __DEBUG = netdata.options.DEBUG;
         var that = this;
 
         if(index >= service.snmp_oids.length) {
@@ -218,7 +233,7 @@ netdata.processors.snmp = {
             index += service.request.max_request_size;
         }
 
-        if(netdata.options.DEBUG === true)
+        if(__DEBUG === true)
             netdata.debug(service.module.name + ': ' + service.name + ': making ' + slice.length + ' entries request, max is: ' + service.request.max_request_size);
 
         service.snmp_session.get(slice, function(error, varbinds) {
@@ -231,14 +246,15 @@ netdata.processors.snmp = {
                     service.snmp_oids_index[slice[len]].value = null;
             }
             else {
-                if(netdata.options.DEBUG === true)
+                if(__DEBUG === true)
                     netdata.debug(service.module.name + ': ' + service.name + ': got valid ' + service.module.name + ' response: ' + netdata.stringify(varbinds));
 
-                for(var i = 0; i < varbinds.length; i++) {
+                var varbinds_len = varbinds.length;
+                for(var i = 0; i < varbinds_len ; i++) {
                     var value = null;
 
                     if(net_snmp.isVarbindError(varbinds[i])) {
-                        if(netdata.options.DEBUG === true)
+                        if(__DEBUG === true)
                             netdata.debug(service.module.name + ': ' + service.name + ': failed ' + service.module.name + ' get for OIDs ' + varbinds[i].oid);
 
                         service.error('OID ' + varbinds[i].oid + ' gave error: ' + snmp.varbindError(varbinds[i]));
@@ -246,7 +262,7 @@ netdata.processors.snmp = {
                         failed++;
                     }
                     else {
-                        if(netdata.options.DEBUG === true)
+                        if(__DEBUG === true)
                             netdata.debug(service.module.name + ': ' + service.name + ': found ' + service.module.name + ' value of OIDs ' + varbinds[i].oid + " = " + varbinds[i].value);
 
                         if(varbinds[i].type === net_snmp.ObjectType.OctetString)
@@ -266,7 +282,7 @@ netdata.processors.snmp = {
                     }
                 }
 
-                if(netdata.options.DEBUG === true)
+                if(__DEBUG === true)
                     netdata.debug(service.module.name + ': ' + service.name + ': finished ' + service.module.name + ' with ' + ok + ' successful and ' + failed + ' failed values');
             }
             that.getdata(service, index, ok, failed, callback);
@@ -274,12 +290,14 @@ netdata.processors.snmp = {
     },
 
     process: function(service, callback) {
+        var __DEBUG = netdata.options.DEBUG;
+
         this.prepare(service);
 
         if(service.snmp_oids.length === 0) {
             // no OIDs found for this service
 
-            if(netdata.options.DEBUG === true)
+            if(__DEBUG === true)
                 service.error('no OIDs to process.');
 
             callback(null);
@@ -290,13 +308,13 @@ netdata.processors.snmp = {
             // no SNMP session has been created for this service
             // the SNMP session is just the initialization of NET-SNMP
 
-            if(netdata.options.DEBUG === true)
+            if(__DEBUG === true)
                 netdata.debug(service.module.name + ': ' + service.name + ': opening ' + this.name + ' session on ' + service.request.hostname + ' community ' + service.request.community + ' options ' + netdata.stringify(service.request.options));
 
             // create the SNMP session
             service.snmp_session = net_snmp.createSession (service.request.hostname, service.request.community, service.request.options);
 
-            if(netdata.options.DEBUG === true)
+            if(__DEBUG === true)
                 netdata.debug(service.module.name + ': ' + service.name + ': got ' + this.name + ' session: ' + netdata.stringify(service.snmp_session));
 
             // if we later need traps, this is how to do it:
@@ -323,19 +341,28 @@ var snmp = {
             if(service.added !== true)
                 service.commit();
 
-            for(var c in service.request.charts) {
-                var chart = snmp.charts[c];
+            var chart_keys = Object.keys(service.request.charts);
+            var chart_keys_len = chart_keys.length;
+            for(var i = 0; i < chart_keys_len; i++) {
+                var c = chart_keys[i];
 
+                var chart = snmp.charts[c];
                 if(typeof chart === 'undefined') {
                     chart = service.chart(c, service.request.charts[c]);
                     snmp.charts[c] = chart;
                 }
 
                 service.begin(chart);
-                
-                for( var d in service.request.charts[c].dimensions )
-                    if(service.request.charts[c].dimensions[d].value !== null)
-                        service.set(d, service.request.charts[c].dimensions[d].value);
+
+                var dimensions = service.request.charts[c].dimensions;
+                var dim_keys = Object.keys(dimensions);
+                var dim_keys_len = dim_keys.length;
+                for(var j = 0; j < dim_keys_len ; j++) {
+                    var d = dim_keys[j];
+
+                    if (dimensions[d].value !== null)
+                        service.set(d, dimensions[d].value);
+                }
 
                 service.end();
             }
@@ -347,7 +374,9 @@ var snmp = {
     // its purpose is to prepare the request and call
     // netdata.serviceExecute()
     serviceExecute: function(conf) {
-        if(netdata.options.DEBUG === true)
+        var __DEBUG = netdata.options.DEBUG;
+
+        if(__DEBUG === true)
             netdata.debug(this.name + ': snmp hostname: ' + conf.hostname + ', update_every: ' + conf.update_every);
 
         var service = netdata.service({
@@ -359,30 +388,40 @@ var snmp = {
         });
 
         // multiply the charts, if required
-        for(var c in service.request.charts) {
-            if(netdata.options.DEBUG === true)
+        var chart_keys = Object.keys(service.request.charts);
+        var chart_keys_len = chart_keys.length;
+        for( var i = 0; i < chart_keys_len ; i++ ) {
+            var c = chart_keys[i];
+            var service_request_chart = service.request.charts[c];
+
+            if(__DEBUG === true)
                 netdata.debug(this.name + ': snmp hostname: ' + conf.hostname + ', examining chart: ' + c);
 
-            if(typeof service.request.charts[c].update_every === 'undefined')
-                service.request.charts[c].update_every = service.update_every;
+            if(typeof service_request_chart.update_every === 'undefined')
+                service_request_chart.update_every = service.update_every;
 
-            if(typeof service.request.charts[c].multiply_range !== 'undefined') {
-                var from = service.request.charts[c].multiply_range[0];
-                var to = service.request.charts[c].multiply_range[1];
-                var prio = service.request.charts[c].priority || 1;
+            if(typeof service_request_chart.multiply_range !== 'undefined') {
+                var from = service_request_chart.multiply_range[0];
+                var to = service_request_chart.multiply_range[1];
+                var prio = service_request_chart.priority || 1;
 
                 if(prio < snmp.base_priority) prio += snmp.base_priority;
 
                 while(from <= to) {
                     var id = c + from.toString();
-                    var chart = extend(true, {}, service.request.charts[c]);
+                    var chart = extend(true, {}, service_request_chart);
                     chart.title += from.toString();
                     
                     if(typeof chart.titleoid !== 'undefined')
                         chart.titleoid += from.toString();
 
                     chart.priority = prio++;
-                    for(var d in chart.dimensions) {
+
+                    var dim_keys = Object.keys(chart.dimensions);
+                    var dim_keys_len = dim_keys.length;
+                    for(var j = 0; j < dim_keys_len ; j++) {
+                        var d = dim_keys[j];
+
                         chart.dimensions[d].oid += from.toString();
 
                         if(typeof chart.dimensions[d].oidname !== 'undefined')
@@ -434,7 +473,7 @@ var snmp = {
             service.module.processResponse(serv, data);
             callback();
         });
-    },
+    }
 };
 
 module.exports = snmp;
index 23c8cfbccf5e2a343be5ae8af8295c12165659e5..5bf42ff8b8fbfd2eded57b33675380f5b6481bcd 100644 (file)
@@ -32,7 +32,7 @@
 // global namespace
 var NETDATA = window.NETDATA || {};
 
-(function(window, document, undefined) {
+(function(window, document) {
     // ------------------------------------------------------------------------
     // compatibility fixes
 
@@ -194,10 +194,7 @@ var NETDATA = window.NETDATA || {};
 
     if(typeof netdataRegistry === 'undefined') {
         // backward compatibility
-        if(typeof netdataNoRegistry !== 'undefined' && netdataNoRegistry === false)
-            netdataRegistry = true;
-        else
-            netdataRegistry = false;
+        netdataRegistry = (typeof netdataNoRegistry !== 'undefined' && netdataNoRegistry === false);
     }
     if(netdataRegistry === false && typeof netdataRegistryCallback === 'function')
         netdataRegistry = true;
@@ -333,7 +330,7 @@ var NETDATA = window.NETDATA || {};
 
             retries_on_data_failures: 3, // how many retries to make if we can't fetch chart data from the server
 
-            setOptionCallback: function() { }
+            setOptionCallback: function() { }
         },
 
         debug: {
@@ -342,7 +339,7 @@ var NETDATA = window.NETDATA || {};
             focus:              false,
             visibility:         false,
             chart_data_url:     false,
-            chart_errors:       false, // FIXME
+            chart_errors:       false, // FIXME: remember to set it to false before merging
             chart_timing:       false,
             chart_calls:        false,
             libraries:          false,
@@ -431,7 +428,11 @@ var NETDATA = window.NETDATA || {};
     };
 
     NETDATA.localStorageGetRecursive = function(obj, prefix, callback) {
-        for(var i in obj) {
+        var keys = Object.keys(obj);
+        var len = keys.length;
+        while(len--) {
+            var i = keys[len];
+
             if(typeof obj[i] === 'object') {
                 //console.log('object ' + prefix + '.' + i.toString());
                 NETDATA.localStorageGetRecursive(obj[i], prefix + '.' + i.toString(), callback);
@@ -478,7 +479,10 @@ var NETDATA = window.NETDATA || {};
     NETDATA.setOption('stop_updates_when_focus_is_lost', true);
 
     NETDATA.resetOptions = function() {
-        for(var i in NETDATA.localStorage.default) {
+        var keys = Object.keys(NETDATA.localStorage.default);
+        var len = keys.length;
+        while(len--) {
+            var i = keys[len];
             var a = i.split('.');
 
             if(a[0] === 'options') {
@@ -494,7 +498,7 @@ var NETDATA = window.NETDATA || {};
                 }
             }
         }
-    }
+    };
 
     // ----------------------------------------------------------------------------------------------------------------
 
@@ -788,6 +792,13 @@ var NETDATA = window.NETDATA || {};
     // Every time we download a chart definition, we save it here with .add()
     // Then we try to get it back with .get(). If that fails, we download it.
 
+    NETDATA.fixHost = function(host) {
+        while(host.slice(-1) === '/')
+            host = host.substring(0, host.length - 1);
+
+        return host;
+    };
+
     NETDATA.chartRegistry = {
         charts: {},
 
@@ -821,8 +832,7 @@ var NETDATA = window.NETDATA || {};
         },
 
         downloadAll: function(host, callback) {
-            while(host.slice(-1) === '/')
-                host = host.substring(0, host.length - 1);
+            host = NETDATA.fixHost(host);
 
             var self = this;
 
@@ -840,13 +850,13 @@ var NETDATA = window.NETDATA || {};
                 else NETDATA.error(406, host + '/api/v1/charts');
 
                 if(typeof callback === 'function')
-                    callback(data);
+                    return callback(data);
             })
             .fail(function() {
                 NETDATA.error(405, host + '/api/v1/charts');
 
                 if(typeof callback === 'function')
-                    callback(null);
+                    return callback(null);
             });
         }
     };
@@ -971,7 +981,7 @@ var NETDATA = window.NETDATA || {};
     dimensionStatus.prototype.setOptions = function(name_div, value_div, color) {
         this.color = color;
 
-        if(this.name_div != name_div) {
+        if(this.name_div !== name_div) {
             this.name_div = name_div;
             this.name_div.title = this.label;
             this.name_div.style.color = this.color;
@@ -981,7 +991,7 @@ var NETDATA = window.NETDATA || {};
                 this.name_div.className = 'netdata-legend-name selected';
         }
 
-        if(this.value_div != value_div) {
+        if(this.value_div !== value_div) {
             this.value_div = value_div;
             this.value_div.title = this.label;
             this.value_div.style.color = this.color;
@@ -1086,26 +1096,34 @@ var NETDATA = window.NETDATA || {};
     };
 
     dimensionsVisibility.prototype.invalidateAll = function() {
-        for(var d in this.dimensions)
-            this.dimensions[d].invalidate();
+        var keys = Object.keys(this.dimensions);
+        var len = keys.length;
+        while(len--)
+            this.dimensions[keys[len]].invalidate();
     };
 
     dimensionsVisibility.prototype.selectAll = function() {
-        for(var d in this.dimensions)
-            this.dimensions[d].select();
+        var keys = Object.keys(this.dimensions);
+        var len = keys.length;
+        while(len--)
+            this.dimensions[keys[len]].select();
     };
 
     dimensionsVisibility.prototype.countSelected = function() {
-        var i = 0;
-        for(var d in this.dimensions)
-            if(this.dimensions[d].isSelected()) i++;
+        var selected = 0;
+        var keys = Object.keys(this.dimensions);
+        var len = keys.length;
+        while(len--)
+            if(this.dimensions[keys[len]].isSelected()) selected++;
 
-        return i;
+        return selected;
     };
 
     dimensionsVisibility.prototype.selectNone = function() {
-        for(var d in this.dimensions)
-            this.dimensions[d].unselect();
+        var keys = Object.keys(this.dimensions);
+        var len = keys.length;
+        while(len--)
+            this.dimensions[keys[len]].unselect();
     };
 
     dimensionsVisibility.prototype.selected2BooleanArray = function(array) {
@@ -1289,13 +1307,11 @@ var NETDATA = window.NETDATA || {};
         this.view_before = 0;
 
         this.value_decimal_detail = -1;
-        {
-            var d = self.data('decimal-digits');
-            if(typeof d === 'number') {
-                this.value_decimal_detail = 1;
-                while(d-- > 0)
-                    this.value_decimal_detail *= 10;
-            }
+        var d = self.data('decimal-digits');
+        if(typeof d === 'number') {
+            this.value_decimal_detail = 1;
+            while(d-- > 0)
+                this.value_decimal_detail *= 10;
         }
 
         this.auto = {
@@ -1729,7 +1745,7 @@ var NETDATA = window.NETDATA || {};
             this.event_resize.chart_last_h = this.element.clientHeight;
 
             var now = Date.now();
-            if(now - this.event_resize.last <= NETDATA.options.current.double_click_speed && this.element_legend_childs.perfect_scroller != null) {
+            if(now - this.event_resize.last <= NETDATA.options.current.double_click_speed && this.element_legend_childs.perfect_scroller !== null) {
                 // double click / double tap event
 
                 // console.dir(this.element_legend_childs.content);
@@ -1742,21 +1758,21 @@ var NETDATA = window.NETDATA || {};
                         - this.element_legend_childs.perfect_scroller.clientHeight;
 
                 // if we are not optimal, be optimal
-                if(this.event_resize.chart_last_h != optimal) {
+                if(this.event_resize.chart_last_h !== optimal) {
                     // this.log('resize to optimal, current = ' + this.event_resize.chart_last_h.toString() + 'px, original = ' + this.event_resize.chart_original_h.toString() + 'px, optimal = ' + optimal.toString() + 'px, internal = ' + this.height_original.toString());
                     resizeChartToHeight(optimal.toString() + 'px');
                 }
 
                 // else if the current height is not the original/saved height
                 // reset to the original/saved height
-                else if(this.event_resize.chart_last_h != this.event_resize.chart_original_h) {
+                else if(this.event_resize.chart_last_h !== this.event_resize.chart_original_h) {
                     // this.log('resize to original, current = ' + this.event_resize.chart_last_h.toString() + 'px, original = ' + this.event_resize.chart_original_h.toString() + 'px, optimal = ' + optimal.toString() + 'px, internal = ' + this.height_original.toString());
                     resizeChartToHeight(this.event_resize.chart_original_h.toString() + 'px');
                 }
 
                 // else if the current height is not the internal default height
                 // reset to the internal default height
-                else if((this.event_resize.chart_last_h.toString() + 'px') != this.height_original) {
+                else if((this.event_resize.chart_last_h.toString() + 'px') !== this.height_original) {
                     // this.log('resize to internal default, current = ' + this.event_resize.chart_last_h.toString() + 'px, original = ' + this.event_resize.chart_original_h.toString() + 'px, optimal = ' + optimal.toString() + 'px, internal = ' + this.height_original.toString());
                     resizeChartToHeight(this.height_original.toString());
                 }
@@ -1773,7 +1789,7 @@ var NETDATA = window.NETDATA || {};
                     // console.log(wanted);
 
                     // this.log('resize to firstChild, current = ' + this.event_resize.chart_last_h.toString() + 'px, original = ' + this.event_resize.chart_original_h.toString() + 'px, optimal = ' + optimal.toString() + 'px, internal = ' + this.height_original.toString() + 'px, firstChild = ' + wanted.toString() + 'px' );
-                    if(this.event_resize.chart_last_h != wanted)
+                    if(this.event_resize.chart_last_h !== wanted)
                         resizeChartToHeight(wanted.toString() + 'px');
                 }
             }
@@ -1890,10 +1906,7 @@ var NETDATA = window.NETDATA || {};
         };
 
         this.globalSelectionSyncIsMaster = function() {
-            if(NETDATA.globalSelectionSync.state === this)
-                return true;
-            else
-                return false;
+            return (NETDATA.globalSelectionSync.state === this);
         };
 
         // this chart is the master of the global selection sync
@@ -1962,12 +1975,8 @@ var NETDATA = window.NETDATA || {};
         // sync all the visible charts to the given time
         // this is to be called from the chart libraries
         this.globalSelectionSync = function(t) {
-            if(this.globalSelectionSyncAbility() === false) {
-                if(this.debug === true)
-                    this.log('sync: cannot sync (yet?).');
-
+            if(this.globalSelectionSyncAbility() === false)
                 return;
-            }
 
             if(this.globalSelectionSyncIsMaster() === false) {
                 if(this.debug === true)
@@ -1975,12 +1984,8 @@ var NETDATA = window.NETDATA || {};
 
                 this.globalSelectionSyncBeMaster();
 
-                if(this.globalSelectionSyncAbility() === false) {
-                    if(this.debug === true)
-                        this.log('sync: cannot sync (yet?).');
-
+                if(this.globalSelectionSyncAbility() === false)
                     return;
-                }
             }
 
             NETDATA.globalSelectionSync.last_t = t;
@@ -2429,7 +2434,7 @@ var NETDATA = window.NETDATA || {};
         };
 
         this.legendUpdateDOM = function() {
-            var needed = false;
+            var needed = false, dim, keys, len, i;
 
             // check that the legend DOM is up to date for the downloaded dimensions
             if(typeof this.element_legend_childs.series !== 'object' || this.element_legend_childs.series === null) {
@@ -2473,9 +2478,12 @@ var NETDATA = window.NETDATA || {};
             if(this.colors === null) {
                 // this is the first time we update the chart
                 // let's assign colors to all dimensions
-                if(this.library.track_colors() === true)
-                    for(var dim in this.chart.dimensions)
-                        this._chartDimensionColor(this.chart.dimensions[dim].name);
+                if(this.library.track_colors() === true) {
+                    keys = Object.keys(this.chart.dimensions);
+                    len = keys.length;
+                    for(i = 0; i < len ;i++)
+                        this._chartDimensionColor(this.chart.dimensions[keys[i]].name);
+                }
             }
             // we will re-generate the colors for the chart
             // based on the selected dimensions
@@ -2554,7 +2562,7 @@ var NETDATA = window.NETDATA || {};
 
                 if(this.library.toolboxPanAndZoom !== null) {
 
-                    function get_pan_and_zoom_step(event) {
+                    var get_pan_and_zoom_step = function(event) {
                         if (event.ctrlKey)
                             return NETDATA.options.current.pan_and_zoom_factor * NETDATA.options.current.pan_and_zoom_factor_multiplier_control;
 
@@ -2566,7 +2574,7 @@ var NETDATA = window.NETDATA || {};
 
                         else
                             return NETDATA.options.current.pan_and_zoom_factor;
-                    }
+                    };
 
                     this.element_legend_childs.toolbox.className += ' netdata-legend-toolbox';
                     this.element.appendChild(this.element_legend_childs.toolbox);
@@ -2786,13 +2794,15 @@ var NETDATA = window.NETDATA || {};
                 if(this.debug === true)
                     this.log('labels from data: "' + this.element_legend_childs.series.labels_key + '"');
 
-                for(var i = 0, len = this.data.dimension_names.length; i < len ;i++) {
+                for(i = 0, len = this.data.dimension_names.length; i < len ;i++) {
                     genLabel(this, content, this.data.dimension_ids[i], this.data.dimension_names[i], i);
                 }
             }
             else {
                 var tmp = new Array();
-                for(var dim in this.chart.dimensions) {
+                keys = Object.keys(this.chart.dimensions);
+                for(i = 0, len = keys.length; i < len ;i++) {
+                    dim = keys[i];
                     tmp.push(this.chart.dimensions[dim].name);
                     genLabel(this, content, dim, this.chart.dimensions[dim].name, i);
                 }
@@ -3088,8 +3098,10 @@ var NETDATA = window.NETDATA || {};
                 if(this.debug === true)
                     this.log('I am already updating...');
 
-                if(typeof callback === 'function') callback();
-                return false;
+                if(typeof callback === 'function')
+                    return callback();
+
+                return;
             }
 
             // due to late initialization of charts and libraries
@@ -3098,29 +3110,37 @@ var NETDATA = window.NETDATA || {};
                 if(this.debug === true)
                     this.log('I am not enabled');
 
-                if(typeof callback === 'function') callback();
-                return false;
+                if(typeof callback === 'function')
+                    return callback();
+
+                return;
             }
 
             if(canBeRendered() === false) {
-                if(typeof callback === 'function') callback();
-                return false;
-            }
+                if(typeof callback === 'function')
+                    return callback();
 
-            if(this.chart === null) {
-                this.getChart(function() { that.updateChart(callback); });
-                return false;
+                return;
             }
 
+            if(this.chart === null)
+                return this.getChart(function() {
+                    return that.updateChart(callback);
+                });
+
             if(this.library.initialized === false) {
                 if(this.library.enabled === true) {
-                    this.library.initialize(function() { that.updateChart(callback); });
-                    return false;
+                    return this.library.initialize(function () {
+                        return that.updateChart(callback);
+                    });
                 }
                 else {
                     error('chart library "' + this.library_name + '" is not available.');
-                    if(typeof callback === 'function') callback();
-                    return false;
+
+                    if(typeof callback === 'function')
+                        return callback();
+
+                    return;
                 }
             }
 
@@ -3178,10 +3198,10 @@ var NETDATA = window.NETDATA || {};
 
                 NETDATA.statistics.refreshes_active--;
                 that._updating = false;
-                if(typeof callback === 'function') callback();
-            });
 
-            return true;
+                if(typeof callback === 'function')
+                    return callback();
+            });
         };
 
         this.isVisible = function(nocache) {
@@ -3345,12 +3365,12 @@ var NETDATA = window.NETDATA || {};
                     state.running = false;
 
                     if(typeof callback !== 'undefined')
-                        callback();
+                        return callback();
                 });
             }
             else {
                 if(typeof callback !== 'undefined')
-                    callback();
+                    return callback();
             }
         };
 
@@ -3373,7 +3393,9 @@ var NETDATA = window.NETDATA || {};
             this.chart = NETDATA.chartRegistry.get(this.host, this.id);
             if(this.chart) {
                 this._defaultsFromDownloadedChart(this.chart);
-                if(typeof callback === 'function') callback();
+
+                if(typeof callback === 'function')
+                    return callback();
             }
             else {
                 this.chart_url = "/api/v1/chart?chart=" + this.id;
@@ -3397,7 +3419,8 @@ var NETDATA = window.NETDATA || {};
                     error('chart not found on url "' + that.chart_url + '"');
                 })
                 .always(function() {
-                    if(typeof callback === 'function') callback();
+                    if(typeof callback === 'function')
+                        return callback();
                 });
             }
         };
@@ -3458,7 +3481,7 @@ var NETDATA = window.NETDATA || {};
             script.src = NETDATA.jQuery;
 
             // script.onabort = onError;
-            script.onerror = function(err, t) { NETDATA.error(101, NETDATA.jQuery); };
+            script.onerror = function() { NETDATA.error(101, NETDATA.jQuery); };
             if(typeof callback === "function")
                 script.onload = callback;
 
@@ -3466,7 +3489,7 @@ var NETDATA = window.NETDATA || {};
             s.parentNode.insertBefore(script, s);
         }
         else if(typeof callback === "function")
-            callback();
+            return callback();
     };
 
     NETDATA._loadCSS = function(filename) {
@@ -3543,10 +3566,12 @@ var NETDATA = window.NETDATA || {};
     };
 
     NETDATA.pause = function(callback) {
-        if(NETDATA.options.pause === true)
-            callback();
-        else
-            NETDATA.options.pauseCallback = callback;
+        if(typeof callback === 'function') {
+            if (NETDATA.options.pause === true)
+                return callback();
+            else
+                NETDATA.options.pauseCallback = callback;
+        }
     };
 
     NETDATA.unpause = function() {
@@ -3725,7 +3750,8 @@ var NETDATA = window.NETDATA || {};
             NETDATA.options.targets.push(NETDATA.chartState(targets[len]));
         }
 
-        if(typeof callback === 'function') callback();
+        if(typeof callback === 'function')
+            return callback();
     };
 
     // this is the main function - where everything starts
@@ -3801,13 +3827,13 @@ var NETDATA = window.NETDATA || {};
             })
             .always(function() {
                 if(typeof callback === "function")
-                    callback();
+                    return callback();
             });
         }
         else {
             NETDATA.chartLibraries.peity.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -3863,13 +3889,13 @@ var NETDATA = window.NETDATA || {};
             })
             .always(function() {
                 if(typeof callback === "function")
-                    callback();
+                    return callback();
             });
         }
         else {
             NETDATA.chartLibraries.sparkline.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -4050,7 +4076,7 @@ var NETDATA = window.NETDATA || {};
         })
         .always(function() {
             if(typeof callback === "function")
-                callback();
+                return callback();
         });
     };
 
@@ -4073,13 +4099,13 @@ var NETDATA = window.NETDATA || {};
                 if(NETDATA.chartLibraries.dygraph.enabled === true && NETDATA.options.current.smooth_plot === true)
                     NETDATA.dygraphSmoothInitialize(callback);
                 else if(typeof callback === "function")
-                    callback();
+                    return callback();
             });
         }
         else {
             NETDATA.chartLibraries.dygraph.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -4527,7 +4553,7 @@ var NETDATA = window.NETDATA || {};
 
                         // http://dygraphs.com/gallery/interaction-api.js
                         var normal_def;
-                        if(typeof event.wheelDelta === 'number' && event.wheelDelta != NaN)
+                        if(typeof event.wheelDelta === 'number' && !isNaN(event.wheelDelta))
                             // chrome
                             normal_def = event.wheelDelta / 40;
                         else
@@ -4688,7 +4714,7 @@ var NETDATA = window.NETDATA || {};
                 else {
                     NETDATA.chartLibraries.morris.enabled = false;
                     if(typeof callback === "function")
-                        callback();
+                        return callback();
                 }
             }
             else {
@@ -4709,14 +4735,14 @@ var NETDATA = window.NETDATA || {};
                 })
                 .always(function() {
                     if(typeof callback === "function")
-                        callback();
+                        return callback();
                 });
             }
         }
         else {
             NETDATA.chartLibraries.morris.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -4775,13 +4801,13 @@ var NETDATA = window.NETDATA || {};
             })
             .always(function() {
                 if(typeof callback === "function")
-                    callback();
+                    return callback();
             });
         }
         else {
             NETDATA.chartLibraries.raphael.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -4819,7 +4845,7 @@ var NETDATA = window.NETDATA || {};
                 else {
                     NETDATA.chartLibraries.c3.enabled = false;
                     if(typeof callback === "function")
-                        callback();
+                        return callback();
                 }
             }
             else {
@@ -4840,14 +4866,14 @@ var NETDATA = window.NETDATA || {};
                 })
                 .always(function() {
                     if(typeof callback === "function")
-                        callback();
+                        return callback();
                 });
             }
         }
         else {
             NETDATA.chartLibraries.c3.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -4939,13 +4965,13 @@ var NETDATA = window.NETDATA || {};
             })
             .always(function() {
                 if(typeof callback === "function")
-                    callback();
+                    return callback();
             });
         }
         else {
             NETDATA.chartLibraries.d3.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -4979,13 +5005,13 @@ var NETDATA = window.NETDATA || {};
                 NETDATA.chartLibraries.google.enabled = false;
                 NETDATA.error(100, NETDATA.google_js);
                 if(typeof callback === "function")
-                    callback();
+                    return callback();
             });
         }
         else {
             NETDATA.chartLibraries.google.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -5136,13 +5162,13 @@ var NETDATA = window.NETDATA || {};
                 })
                 .always(function() {
                     if(typeof callback === "function")
-                        callback();
+                        return callback();
                 })
         }
         else {
             NETDATA.chartLibraries.easypiechart.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -5348,13 +5374,13 @@ var NETDATA = window.NETDATA || {};
                 })
                 .always(function() {
                     if(typeof callback === "function")
-                        callback();
+                        return callback();
                 })
         }
         else {
             NETDATA.chartLibraries.gauge.enabled = false;
             if(typeof callback === "function")
-                callback();
+                return callback();
         }
     };
 
@@ -5382,7 +5408,7 @@ var NETDATA = window.NETDATA || {};
             min = max;
             max = t;
         }
-        else if(min == max)
+        else if(min === max)
             max = min + 1;
 
         // gauge.js has an issue if the needle
@@ -5909,7 +5935,7 @@ var NETDATA = window.NETDATA || {};
             async: false,
             isAlreadyLoaded: function() {
                 // check if bootstrap is loaded
-                if(typeof $().emulateTransitionEnd == 'function')
+                if(typeof $().emulateTransitionEnd === 'function')
                     return true;
                 else {
                     if(typeof netdataNoBootstrap !== 'undefined' && netdataNoBootstrap)
@@ -5949,7 +5975,7 @@ var NETDATA = window.NETDATA || {};
     NETDATA.loadRequiredJs = function(index, callback) {
         if(index >= NETDATA.requiredJs.length) {
             if(typeof callback === 'function')
-                callback();
+                return callback();
             return;
         }
 
@@ -6041,7 +6067,7 @@ var NETDATA = window.NETDATA || {};
             var value = entry.value;
             if(NETDATA.alarms.current !== null) {
                 var t = NETDATA.alarms.current.alarms[entry.chart + '.' + entry.name];
-                if(typeof t !== 'undefined' && entry.status == t.status)
+                if(typeof t !== 'undefined' && entry.status === t.status)
                     value = t.value;
             }
 
@@ -6253,13 +6279,13 @@ var NETDATA = window.NETDATA || {};
                         NETDATA.alarms.first_notification_id = data.latest_alarm_log_unique_id;
 
                     if(typeof callback === 'function')
-                        callback(data);
+                        return callback(data);
                 })
                 .fail(function() {
                     NETDATA.error(415, NETDATA.alarms.server);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         },
 
@@ -6298,23 +6324,21 @@ var NETDATA = window.NETDATA || {};
             })
                 .done(function(data) {
                     if(typeof callback === 'function')
-                        callback(data);
+                        return callback(data);
                 })
                 .fail(function() {
                     NETDATA.error(416, NETDATA.alarms.server);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         },
 
         init: function() {
-            var host = NETDATA.serverDefault;
-            while(host.slice(-1) === '/')
-                host = host.substring(0, host.length - 1);
-            NETDATA.alarms.server = host;
+            NETDATA.alarms.server = NETDATA.fixHost(NETDATA.serverDefault);
 
-            NETDATA.alarms.last_notification_id = NETDATA.localStorageGet('last_notification_id', NETDATA.alarms.last_notification_id, null);
+            NETDATA.alarms.last_notification_id =
+                NETDATA.localStorageGet('last_notification_id', NETDATA.alarms.last_notification_id, null);
 
             if(NETDATA.alarms.onclick === null)
                 NETDATA.alarms.onclick = NETDATA.alarms.scrollToAlarm;
@@ -6410,8 +6434,7 @@ var NETDATA = window.NETDATA || {};
         },
 
         hello: function(host, callback) {
-            while(host.slice(-1) === '/')
-                host = host.substring(0, host.length - 1);
+            host = NETDATA.fixHost(host);
 
             // send HELLO to a netdata server:
             // 1. verifies the server is reachable
@@ -6433,13 +6456,13 @@ var NETDATA = window.NETDATA || {};
                     }
 
                     if(typeof callback === 'function')
-                        callback(data);
+                        return callback(data);
                 })
                 .fail(function() {
                     NETDATA.error(407, host);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         },
 
@@ -6476,7 +6499,7 @@ var NETDATA = window.NETDATA || {};
                         }
                         else {
                             if(typeof callback === 'function')
-                                callback(null);
+                                return callback(null);
                         }
                     }
                     else {
@@ -6484,14 +6507,14 @@ var NETDATA = window.NETDATA || {};
                             NETDATA.registry.person_guid = data.person_guid;
 
                         if(typeof callback === 'function')
-                            callback(data.urls);
+                            return callback(data.urls);
                     }
                 })
                 .fail(function() {
                     NETDATA.error(410, NETDATA.registry.server);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         },
 
@@ -6514,13 +6537,13 @@ var NETDATA = window.NETDATA || {};
                     }
 
                     if(typeof callback === 'function')
-                        callback(data);
+                        return callback(data);
                 })
                 .fail(function() {
                     NETDATA.error(412, NETDATA.registry.server);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         },
 
@@ -6543,13 +6566,13 @@ var NETDATA = window.NETDATA || {};
                     }
 
                     if(typeof callback === 'function')
-                        callback(data);
+                        return callback(data);
                 })
                 .fail(function() {
                     NETDATA.error(418, NETDATA.registry.server);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         },
 
@@ -6572,13 +6595,13 @@ var NETDATA = window.NETDATA || {};
                     }
 
                     if(typeof callback === 'function')
-                        callback(data);
+                        return callback(data);
                 })
                 .fail(function() {
                     NETDATA.error(414, NETDATA.registry.server);
 
                     if(typeof callback === 'function')
-                        callback(null);
+                        return callback(null);
                 });
         }
     };
index 8421c48df3a822fdecc6b682bce9d2433dc31fd3..87a17c53cdec23136794128cf44b9ec9768471dd 100644 (file)
     </div>
 </body>
 </html>
-<script type="text/javascript" src="dashboard.js?v20170105-7"></script>
+<script type="text/javascript" src="dashboard.js?v20170107-5"></script>