From 12be5fff5668e07687ace0cc41cf2016ad848aa8 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Fri, 24 Jul 2015 19:33:22 +0300 Subject: [PATCH] Refactoring - resolve code inspection problems. --- zabbix/datasource.js | 4 +- zabbix/helperFunctions.js | 12 ++- zabbix/partials/annotations.editor.html | 24 +++-- zabbix/partials/config.html | 20 +++- zabbix/partials/query.editor.html | 117 +++++++++++++----------- zabbix/zabbixAPIWrapper.js | 6 +- 6 files changed, 107 insertions(+), 76 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index e77b35e..8099ad7 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -115,7 +115,7 @@ function (angular, _, kbn) { // Remove hostnames from item names and then // extract item names // "hostname: itemname" --> "itemname" - var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g; + var delete_hostname_pattern = /(?:\[[\w\.]+]:\s)/g; var itemnames = zabbixHelperSrv.splitMetrics(itemname.replace(delete_hostname_pattern, '')); // Find items by item names and perform queries @@ -323,7 +323,7 @@ function (angular, _, kbn) { annotation: annotation, time: e.clock * 1000, title: Number(e.value) ? 'Problem' : 'OK', - text: objects[e.objectid].description + formatted_acknowledges, + text: objects[e.objectid].description + formatted_acknowledges }); }); return events; diff --git a/zabbix/helperFunctions.js b/zabbix/helperFunctions.js index 34bb84e..881c69b 100644 --- a/zabbix/helperFunctions.js +++ b/zabbix/helperFunctions.js @@ -14,6 +14,8 @@ function (angular, _) { * Convert Zabbix API history.get response to Grafana format * * @param {Array} items Array of Zabbix Items + * @param alias + * @param scale * @param {Array} history Array of Zabbix History * * @return {Array} Array of timeseries in Grafana format @@ -44,7 +46,7 @@ function (angular, _) { var self = this; return $q.when(_.map(grouped_history, function (history, itemid) { var item = indexed_items[itemid]; - var series = { + return { target: (item.hosts ? item.hosts[0].name+': ' : '') + (alias ? alias : self.expandItemName(item)), datapoints: _.map(history, function (p) { @@ -59,7 +61,6 @@ function (angular, _) { return [value, p.clock * 1000]; }) }; - return series; })).then(function (result) { return _.sortBy(result, 'target'); }); @@ -69,6 +70,8 @@ function (angular, _) { * Convert Zabbix API trends.get response to Grafana format * * @param {Array} items Array of Zabbix Items + * @param alias + * @param scale * @param {Array} trends Array of Zabbix Trends * * @return {Array} Array of timeseries in Grafana format @@ -86,7 +89,7 @@ function (angular, _) { var self = this; return $q.when(_.map(grouped_trends, function (trends, itemid) { var item = indexed_items[itemid]; - var series = { + return { target: (item.hosts ? item.hosts[0].name+': ' : '') + (alias ? alias : self.expandItemName(item)), datapoints: _.map(trends, function (p) { @@ -101,7 +104,6 @@ function (angular, _) { return [value, p.clock * 1000]; }) }; - return series; })).then(function (result) { return _.sortBy(result, 'target'); }); @@ -112,7 +114,7 @@ function (angular, _) { * CPU $2 time ($3) --> CPU system time (avg1) * * @param item: zabbix api item object - * @return: expanded item name (string) + * @return {string} expanded item name (string) */ this.expandItemName = function(item) { var name = item.name; diff --git a/zabbix/partials/annotations.editor.html b/zabbix/partials/annotations.editor.html index 1dcfe6f..1e9caba 100644 --- a/zabbix/partials/annotations.editor.html +++ b/zabbix/partials/annotations.editor.html @@ -1,16 +1,24 @@
-
-
Zabbix trigger Example: Lack of free swap space
-
- -
-
+
+
Zabbix trigger + Example: Lack of free swap space +
+
+ +
+
Options
- - + +
diff --git a/zabbix/partials/config.html b/zabbix/partials/config.html index de32561..fed5320 100644 --- a/zabbix/partials/config.html +++ b/zabbix/partials/config.html @@ -10,13 +10,17 @@ User
  • - +
  • Password
  • - +
  • @@ -28,14 +32,18 @@
  • Enable  - +
  • Use trends from
  • - +
  • @@ -46,7 +54,9 @@ Metrics limit
  • - +
  • diff --git a/zabbix/partials/query.editor.html b/zabbix/partials/query.editor.html index 6fc6627..30b767b 100644 --- a/zabbix/partials/query.editor.html +++ b/zabbix/partials/query.editor.html @@ -1,18 +1,18 @@
    -
    +
    -
    @@ -218,7 +227,9 @@
    Max data points
      -
    • Grafana-Zabbix plugin uses maxDataPoints parameter to consolidate the real number of values down to this number
    • +
    • Grafana-Zabbix plugin uses maxDataPoints parameter to consolidate the real number of values down to this + number +
    • If there are more real values, then by default they will be consolidated using averages
    • This could hide real peaks and max values in your series
    • Point consolidation will effect series legend values (min,max,total,current)
    • diff --git a/zabbix/zabbixAPIWrapper.js b/zabbix/zabbixAPIWrapper.js index 45a14d1..0399915 100644 --- a/zabbix/zabbixAPIWrapper.js +++ b/zabbix/zabbixAPIWrapper.js @@ -1,7 +1,7 @@ define([ 'angular', - 'lodash', -], + 'lodash' + ], function (angular, _) { 'use strict'; @@ -94,7 +94,7 @@ function (angular, _) { }, auth: null, id: 1 - }, + } }; if (this.basicAuth || this.withCredentials) {