diff --git a/Gruntfile.js b/Gruntfile.js index 4b85222..9b20b76 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,18 +17,19 @@ module.exports = function(grunt) { '**/*', '!**/datasource.js', '!**/module.js', - '!**/queryCtrl.js', + '!**/query.controller.js', '!**/utils.js', - '!**/zabbixAPICoreService.js', - '!**/zabbixAPIService.js', + '!**/zabbixAPICore.service.js', + '!**/zabbixAPI.service.js', + '!**/metricFunctions.js', '!**/*.scss' ], - dest: 'dist/src' + dest: 'dist/' }, pluginDef: { expand: true, src: ['plugin.json', 'README.md'], - dest: 'dist', + dest: 'dist/', } }, @@ -42,7 +43,7 @@ module.exports = function(grunt) { babel: { options: { - sourceMap: true, + sourceMap: false, presets: ["es2015"], plugins: ['transform-es2015-modules-systemjs', "transform-es2015-for-of"], }, @@ -53,13 +54,13 @@ module.exports = function(grunt) { src: [ '**/**/module.js', '**/**/datasource.js', - '**/**/queryCtrl.js', + '**/**/query.controller.js', '**/**/utils.js', - '**/**/zabbixAPICoreService.js', - '**/**/zabbixAPIService.js', + '**/**/zabbixAPICore.service.js', + '**/**/zabbixAPI.service.js', + '**/**/metricFunctions.js' ], - dest: 'dist/src', - ext:'.js' + dest: 'dist/' }] }, }, diff --git a/src/datasource-zabbix/addMetricFunction.js b/src/datasource-zabbix/add-metric-function.directive.js similarity index 100% rename from src/datasource-zabbix/addMetricFunction.js rename to src/datasource-zabbix/add-metric-function.directive.js diff --git a/src/datasource-zabbix/dataProcessingService.js b/src/datasource-zabbix/dataProcessing.service.js similarity index 99% rename from src/datasource-zabbix/dataProcessingService.js rename to src/datasource-zabbix/dataProcessing.service.js index 5bf73a3..b7958ea 100644 --- a/src/datasource-zabbix/dataProcessingService.js +++ b/src/datasource-zabbix/dataProcessing.service.js @@ -238,4 +238,4 @@ function (angular, _, moment, utils) { }; }); -}); \ No newline at end of file +}); diff --git a/src/datasource-zabbix/datasource.js b/src/datasource-zabbix/datasource.js index 77eddba..dce090a 100644 --- a/src/datasource-zabbix/datasource.js +++ b/src/datasource-zabbix/datasource.js @@ -3,16 +3,15 @@ import _ from 'lodash'; import * as dateMath from 'app/core/utils/datemath'; import * as utils from './utils'; import metricFunctions from './metricFunctions'; -import {zabbixHelperSrv} from './helperFunctions'; -import './zabbixAPIService'; -import {ZabbixCachingProxy} from './zabbixCache'; -import {QueryProcessor} from './queryProcessor'; -import {DataProcessingService} from './dataProcessingService'; +import './zabbixAPI.service.js'; +import './zabbixCache.service.js'; +import './queryProcessor.service.js'; +import './dataProcessing.service'; export class ZabbixAPIDatasource { /** @ngInject */ - constructor(instanceSettings, $q, templateSrv, alertSrv, zabbixAPIService, ZabbixCachingProxy, QueryProcessor, zabbixHelperSrv, DataProcessingService) { + constructor(instanceSettings, $q, templateSrv, alertSrv, zabbixAPIService, ZabbixCachingProxy, QueryProcessor, DataProcessingService) { // General data source settings this.name = instanceSettings.name; @@ -46,7 +45,6 @@ export class ZabbixAPIDatasource { this.q = $q; this.templateSrv = templateSrv; this.alertSrv = alertSrv; - this.zabbixHelperSrv = zabbixHelperSrv; this.DataProcessingService = DataProcessingService; console.log(this.zabbixCache); @@ -243,13 +241,13 @@ export class ZabbixAPIDatasource { return []; } else { return this.zabbixAPI.getSLA(target.itservice.serviceid, from, to) - .then(_.bind(zabbixHelperSrv.handleSLAResponse, zabbixHelperSrv, target.itservice, target.slaProperty)); + .then(slaObject => { + return self.queryProcessor.handleSLAResponse(target.itservice, target.slaProperty, slaObject); + }); } } }, this); - var self = this; - // Data for panel (all targets) return this.q.all(_.flatten(promises)) .then(_.flatten) diff --git a/src/datasource-zabbix/metricFunctionEditor.js b/src/datasource-zabbix/metric-function-editor.directive.js similarity index 100% rename from src/datasource-zabbix/metricFunctionEditor.js rename to src/datasource-zabbix/metric-function-editor.directive.js diff --git a/src/datasource-zabbix/metricFunctions.js b/src/datasource-zabbix/metricFunctions.js index c0cc2b3..acfef29 100644 --- a/src/datasource-zabbix/metricFunctions.js +++ b/src/datasource-zabbix/metricFunctions.js @@ -1,105 +1,102 @@ -define([ - 'lodash', - 'jquery' -], -function (_, $) { - 'use strict'; +import _ from 'lodash'; +import $ from 'jquery'; - var index = []; - var categories = { - Transform: [], - Aggregate: [], - Trends: [], - Alias: [] - }; +var index = []; +var categories = { + Transform: [], + Aggregate: [], + Trends: [], + Alias: [] +}; - function addFuncDef(funcDef) { - funcDef.params = funcDef.params || []; - funcDef.defaultParams = funcDef.defaultParams || []; +function addFuncDef(funcDef) { + funcDef.params = funcDef.params || []; + funcDef.defaultParams = funcDef.defaultParams || []; - if (funcDef.category) { - categories[funcDef.category].push(funcDef); - } - index[funcDef.name] = funcDef; - index[funcDef.shortName || funcDef.name] = funcDef; + if (funcDef.category) { + categories[funcDef.category].push(funcDef); } + index[funcDef.name] = funcDef; + index[funcDef.shortName || funcDef.name] = funcDef; +} - addFuncDef({ - name: 'groupBy', - category: 'Transform', - params: [ - { name: 'interval', type: 'string'}, - { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] } - ], - defaultParams: ['1m', 'avg'], - }); +addFuncDef({ + name: 'groupBy', + category: 'Transform', + params: [ + { name: 'interval', type: 'string'}, + { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] } + ], + defaultParams: ['1m', 'avg'], +}); - addFuncDef({ - name: 'sumSeries', - category: 'Aggregate', - params: [], - defaultParams: [], - }); +addFuncDef({ + name: 'sumSeries', + category: 'Aggregate', + params: [], + defaultParams: [], +}); - addFuncDef({ - name: 'median', - category: 'Aggregate', - params: [ - { name: 'interval', type: 'string'} - ], - defaultParams: ['1m'], - }); +addFuncDef({ + name: 'median', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string'} + ], + defaultParams: ['1m'], +}); - addFuncDef({ - name: 'average', - category: 'Aggregate', - params: [ - { name: 'interval', type: 'string' } - ], - defaultParams: ['1m'], - }); +addFuncDef({ + name: 'average', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string' } + ], + defaultParams: ['1m'], +}); - addFuncDef({ - name: 'min', - category: 'Aggregate', - params: [ - { name: 'interval', type: 'string' } - ], - defaultParams: ['1m'], - }); +addFuncDef({ + name: 'min', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string' } + ], + defaultParams: ['1m'], +}); - addFuncDef({ - name: 'max', - category: 'Aggregate', - params: [ - { name: 'interval', type: 'string' } - ], - defaultParams: ['1m'], - }); +addFuncDef({ + name: 'max', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string' } + ], + defaultParams: ['1m'], +}); - addFuncDef({ - name: 'trendValue', - category: 'Trends', - params: [ - { name: 'type', type: 'string', options: ['avg', 'min', 'max'] } - ], - defaultParams: ['avg'], - }); +addFuncDef({ + name: 'trendValue', + category: 'Trends', + params: [ + { name: 'type', type: 'string', options: ['avg', 'min', 'max'] } + ], + defaultParams: ['avg'], +}); - addFuncDef({ - name: 'setAlias', - category: 'Alias', - params: [ - { name: 'alias', type: 'string'} - ], - defaultParams: [], - }); +addFuncDef({ + name: 'setAlias', + category: 'Alias', + params: [ + { name: 'alias', type: 'string'} + ], + defaultParams: [], +}); - _.each(categories, function(funcList, catName) { - categories[catName] = _.sortBy(funcList, 'name'); - }); +_.each(categories, function(funcList, catName) { + categories[catName] = _.sortBy(funcList, 'name'); +}); - function FuncInstance(funcDef, params) { +class FuncInstance { + constructor(funcDef, params) { this.def = funcDef; if (params) { @@ -113,7 +110,7 @@ function (_, $) { this.updateText(); } - FuncInstance.prototype.bindFunction = function(metricFunctions) { + bindFunction(metricFunctions) { var func = metricFunctions[this.def.name]; if (func) { @@ -126,9 +123,9 @@ function (_, $) { } else { throw { message: 'Method not found ' + this.def.name }; } - }; + } - FuncInstance.prototype.render = function(metricExp) { + render(metricExp) { var str = this.def.name + '('; var parameters = _.map(this.params, function(value, index) { @@ -149,17 +146,17 @@ function (_, $) { } return str + parameters.join(', ') + ')'; - }; + } - FuncInstance.prototype._hasMultipleParamsInString = function(strValue, index) { + _hasMultipleParamsInString(strValue, index) { if (strValue.indexOf(',') === -1) { return false; } return this.def.params[index + 1] && this.def.params[index + 1].optional; - }; + } - FuncInstance.prototype.updateParam = function(strValue, index) { + updateParam(strValue, index) { // handle optional parameters // if string contains ',' and next param is optional, split and update both if (this._hasMultipleParamsInString(strValue, index)) { @@ -177,9 +174,9 @@ function (_, $) { } this.updateText(); - }; + } - FuncInstance.prototype.updateText = function () { + updateText() { if (this.params.length === 0) { this.text = this.def.name + '()'; return; @@ -189,26 +186,25 @@ function (_, $) { text += this.params.join(', '); text += ')'; this.text = text; - }; + } +} - return { - createFuncInstance: function(funcDef, params) { - if (_.isString(funcDef)) { - if (!index[funcDef]) { - throw { message: 'Method not found ' + name }; - } - funcDef = index[funcDef]; +export default { + createFuncInstance: function(funcDef, params) { + if (_.isString(funcDef)) { + if (!index[funcDef]) { + throw { message: 'Method not found ' + name }; } - return new FuncInstance(funcDef, params); - }, - - getFuncDef: function(name) { - return index[name]; - }, - - getCategories: function() { - return categories; + funcDef = index[funcDef]; } - }; + return new FuncInstance(funcDef, params); + }, -}); + getFuncDef: function(name) { + return index[name]; + }, + + getCategories: function() { + return categories; + } +}; diff --git a/src/datasource-zabbix/module.js b/src/datasource-zabbix/module.js index d947214..a7cc1d9 100644 --- a/src/datasource-zabbix/module.js +++ b/src/datasource-zabbix/module.js @@ -1,19 +1,19 @@ import {ZabbixAPIDatasource} from './datasource'; -import {ZabbixQueryCtrl} from './queryCtrl'; +import {ZabbixQueryController} from './query.controller'; -class ZabbixConfigCtrl {} -ZabbixConfigCtrl.templateUrl = 'partials/config.html'; +class ZabbixConfigController {} +ZabbixConfigController.templateUrl = 'partials/config.html'; -class ZabbixQueryOptionsCtrl {} -ZabbixQueryOptionsCtrl.templateUrl = 'partials/query.options.html'; +class ZabbixQueryOptionsController {} +ZabbixQueryOptionsController.templateUrl = 'partials/query.options.html'; -class ZabbixAnnotationsQueryCtrl {} -ZabbixAnnotationsQueryCtrl.templateUrl = 'partials/annotations.editor.html'; +class ZabbixAnnotationsQueryController {} +ZabbixAnnotationsQueryController.templateUrl = 'partials/annotations.editor.html'; export { ZabbixAPIDatasource as Datasource, - ZabbixQueryCtrl as QueryCtrl, - ZabbixConfigCtrl as ConfigCtrl, - ZabbixQueryOptionsCtrl as QueryOptionsCtrl, - ZabbixAnnotationsQueryCtrl as AnnotationsQueryCtrl + ZabbixConfigController as ConfigCtrl, + ZabbixQueryController as QueryCtrl, + ZabbixQueryOptionsController as QueryOptionsCtrl, + ZabbixAnnotationsQueryController as AnnotationsQueryCtrl }; diff --git a/src/datasource-zabbix/queryCtrl.js b/src/datasource-zabbix/query.controller.js similarity index 96% rename from src/datasource-zabbix/queryCtrl.js rename to src/datasource-zabbix/query.controller.js index 935fc7a..25f8ac9 100644 --- a/src/datasource-zabbix/queryCtrl.js +++ b/src/datasource-zabbix/query.controller.js @@ -1,17 +1,9 @@ -/*define([ - 'app/plugins/sdk', - 'angular', - 'lodash', - './metricFunctions', - './utils' -],*/ - import {QueryCtrl} from 'app/plugins/sdk'; import _ from 'lodash'; import * as utils from './utils'; import metricFunctions from './metricFunctions'; -export class ZabbixQueryCtrl extends QueryCtrl { +export class ZabbixQueryController extends QueryCtrl { // ZabbixQueryCtrl constructor constructor($scope, $injector, $sce, $q, templateSrv) { @@ -229,9 +221,9 @@ export class ZabbixQueryCtrl extends QueryCtrl { } // Set templateUrl as static property -ZabbixQueryCtrl.templateUrl = 'partials/query.editor.html'; +ZabbixQueryController.templateUrl = 'partials/query.editor.html'; // Get list of metric names for bs-typeahead directive function getMetricNames(scope, metricList) { return _.uniq(_.map(scope.metric[metricList], 'name')); -} \ No newline at end of file +} diff --git a/src/datasource-zabbix/queryProcessor.js b/src/datasource-zabbix/queryProcessor.service.js similarity index 94% rename from src/datasource-zabbix/queryProcessor.js rename to src/datasource-zabbix/queryProcessor.service.js index c5a78ec..ecedaee 100644 --- a/src/datasource-zabbix/queryProcessor.js +++ b/src/datasource-zabbix/queryProcessor.service.js @@ -416,6 +416,27 @@ function (angular, _, utils) { return this.convertHistory(history, addHostName, convertPointCallback); }; + this.handleSLAResponse = function (itservice, slaProperty, slaObject) { + var targetSLA = slaObject[itservice.serviceid].sla[0]; + if (slaProperty.property === 'status') { + var targetStatus = parseInt(slaObject[itservice.serviceid].status); + return { + target: itservice.name + ' ' + slaProperty.name, + datapoints: [ + [targetStatus, targetSLA.to * 1000] + ] + }; + } else { + return { + target: itservice.name + ' ' + slaProperty.name, + datapoints: [ + [targetSLA[slaProperty.property], targetSLA.from * 1000], + [targetSLA[slaProperty.property], targetSLA.to * 1000] + ] + }; + } + }; + function convertHistoryPoint(point) { // Value must be a number for properly work return [ @@ -450,4 +471,4 @@ function (angular, _, utils) { return QueryProcessor; }); -}); \ No newline at end of file +}); diff --git a/src/datasource-zabbix/zabbixAPIService.js b/src/datasource-zabbix/zabbixAPI.service.js similarity index 99% rename from src/datasource-zabbix/zabbixAPIService.js rename to src/datasource-zabbix/zabbixAPI.service.js index d2f89f7..ca74d11 100644 --- a/src/datasource-zabbix/zabbixAPIService.js +++ b/src/datasource-zabbix/zabbixAPI.service.js @@ -1,6 +1,6 @@ import angular from 'angular'; import _ from 'lodash'; -import './zabbixAPICoreService'; +import './zabbixAPICore.service'; /** @ngInject */ function ZabbixAPIService($q, alertSrv, zabbixAPICoreService) { diff --git a/src/datasource-zabbix/zabbixAPICoreService.js b/src/datasource-zabbix/zabbixAPICore.service.js similarity index 100% rename from src/datasource-zabbix/zabbixAPICoreService.js rename to src/datasource-zabbix/zabbixAPICore.service.js diff --git a/src/datasource-zabbix/zabbixCache.js b/src/datasource-zabbix/zabbixCache.service.js similarity index 100% rename from src/datasource-zabbix/zabbixCache.js rename to src/datasource-zabbix/zabbixCache.service.js