queryCtrl and utils module refactor. Suppress "use strict" warnings in modules.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
"curly": true,
|
||||
"eqnull": true,
|
||||
"strict": true,
|
||||
"module": true,
|
||||
"devel": true,
|
||||
"eqeqeq": true,
|
||||
"forin": false,
|
||||
|
||||
@@ -17,6 +17,8 @@ module.exports = function(grunt) {
|
||||
'**/*',
|
||||
'!**/datasource.js',
|
||||
'!**/module.js',
|
||||
'!**/queryCtrl.js',
|
||||
'!**/utils.js',
|
||||
'!**/*.scss'
|
||||
],
|
||||
dest: 'dist/src'
|
||||
@@ -47,8 +49,10 @@ module.exports = function(grunt) {
|
||||
cwd: 'src',
|
||||
expand: true,
|
||||
src: [
|
||||
'**/**/datasource.js',
|
||||
'**/**/module.js',
|
||||
'**/**/datasource.js',
|
||||
'**/**/queryCtrl.js',
|
||||
'**/**/utils.js',
|
||||
],
|
||||
dest: 'dist/src',
|
||||
ext:'.js'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
import {parse as dateMathParse} from 'app/core/utils/datemath';
|
||||
import Utils from './utils';
|
||||
import * as dateMath from 'app/core/utils/datemath';
|
||||
import * as utils from './utils';
|
||||
import metricFunctions from './metricFunctions';
|
||||
import {zabbixHelperSrv} from './helperFunctions';
|
||||
import {ZabbixAPI} from './zabbixAPI';
|
||||
@@ -29,7 +29,7 @@ export class ZabbixAPIDatasource {
|
||||
|
||||
// Set cache update interval
|
||||
var ttl = instanceSettings.jsonData.cacheTTL || '1h';
|
||||
this.cacheTTL = Utils.parseInterval(ttl);
|
||||
this.cacheTTL = utils.parseInterval(ttl);
|
||||
|
||||
// Initialize Zabbix API
|
||||
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
||||
@@ -103,9 +103,9 @@ export class ZabbixAPIDatasource {
|
||||
var self = this;
|
||||
|
||||
// get from & to in seconds
|
||||
var from = Math.ceil(dateMathParse(options.range.from) / 1000);
|
||||
var to = Math.ceil(dateMathParse(options.range.to) / 1000);
|
||||
var useTrendsFrom = Math.ceil(dateMathParse('now-' + this.trendsFrom) / 1000);
|
||||
var from = Math.ceil(dateMath.parse(options.range.from) / 1000);
|
||||
var to = Math.ceil(dateMath.parse(options.range.to) / 1000);
|
||||
var useTrendsFrom = Math.ceil(dateMath.parse('now-' + this.trendsFrom) / 1000);
|
||||
|
||||
// Create request for each target
|
||||
var promises = _.map(options.targets, function(target) {
|
||||
@@ -330,8 +330,8 @@ export class ZabbixAPIDatasource {
|
||||
/////////////////
|
||||
|
||||
annotationQuery(options) {
|
||||
var from = Math.ceil(dateMathParse(options.rangeRaw.from) / 1000);
|
||||
var to = Math.ceil(dateMathParse(options.rangeRaw.to) / 1000);
|
||||
var from = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
||||
var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||
var annotation = options.annotation;
|
||||
var self = this;
|
||||
var showEvents = annotation.showOkEvents ? [0, 1] : 1;
|
||||
@@ -347,9 +347,9 @@ export class ZabbixAPIDatasource {
|
||||
.then(function(triggers) {
|
||||
|
||||
// Filter triggers by description
|
||||
if (Utils.isRegex(annotation.trigger)) {
|
||||
if (utils.isRegex(annotation.trigger)) {
|
||||
triggers = _.filter(triggers, function(trigger) {
|
||||
return Utils.buildRegex(annotation.trigger).test(trigger.description);
|
||||
return utils.buildRegex(annotation.trigger).test(trigger.description);
|
||||
});
|
||||
} else if (annotation.trigger) {
|
||||
triggers = _.filter(triggers, function(trigger) {
|
||||
@@ -393,7 +393,7 @@ export class ZabbixAPIDatasource {
|
||||
// Show event type (OK or Problem)
|
||||
title += Number(e.value) ? 'Problem' : 'OK';
|
||||
|
||||
var formatted_acknowledges = Utils.formatAcknowledges(e.acknowledges);
|
||||
var formatted_acknowledges = utils.formatAcknowledges(e.acknowledges);
|
||||
return {
|
||||
annotation: annotation,
|
||||
time: e.clock * 1000,
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
define([
|
||||
/*define([
|
||||
'app/plugins/sdk',
|
||||
'angular',
|
||||
'lodash',
|
||||
'./metricFunctions',
|
||||
'./utils'
|
||||
],
|
||||
function (sdk, angular, _, metricFunctions, utils) {
|
||||
'use strict';
|
||||
],*/
|
||||
|
||||
var ZabbixQueryCtrl = (function(_super) {
|
||||
import {QueryCtrl} from 'app/plugins/sdk';
|
||||
import _ from 'lodash';
|
||||
import * as utils from './utils';
|
||||
import metricFunctions from './metricFunctions';
|
||||
|
||||
export class ZabbixQueryCtrl extends QueryCtrl {
|
||||
|
||||
// ZabbixQueryCtrl constructor
|
||||
function ZabbixQueryCtrl($scope, $injector, $sce, $q, templateSrv) {
|
||||
constructor($scope, $injector, $sce, $q, templateSrv) {
|
||||
|
||||
// Call superclass constructor
|
||||
_super.call(this, $scope, $injector);
|
||||
super($scope, $injector);
|
||||
|
||||
this.editorModes = {
|
||||
0: 'num',
|
||||
@@ -86,36 +89,29 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
this.init();
|
||||
}
|
||||
|
||||
ZabbixQueryCtrl.templateUrl = 'partials/query.editor.html';
|
||||
|
||||
ZabbixQueryCtrl.prototype = Object.create(_super.prototype);
|
||||
ZabbixQueryCtrl.prototype.constructor = ZabbixQueryCtrl;
|
||||
|
||||
var p = ZabbixQueryCtrl.prototype;
|
||||
|
||||
p.initFilters = function () {
|
||||
initFilters() {
|
||||
this.filterGroups();
|
||||
this.filterHosts();
|
||||
this.filterApplications();
|
||||
this.filterItems();
|
||||
};
|
||||
}
|
||||
|
||||
p.filterHosts = function () {
|
||||
filterHosts() {
|
||||
var self = this;
|
||||
var groupFilter = this.templateSrv.replace(this.target.group.filter);
|
||||
this.datasource.queryProcessor.filterHosts(groupFilter).then(function(hosts) {
|
||||
self.metric.filteredHosts = hosts;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
p.filterGroups = function() {
|
||||
filterGroups() {
|
||||
var self = this;
|
||||
this.datasource.queryProcessor.filterGroups().then(function(groups) {
|
||||
self.metric.groupList = groups;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
p.filterApplications = function () {
|
||||
filterApplications() {
|
||||
var self = this;
|
||||
var groupFilter = this.templateSrv.replace(this.target.group.filter);
|
||||
var hostFilter = this.templateSrv.replace(this.target.host.filter);
|
||||
@@ -123,9 +119,9 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
.then(function(apps) {
|
||||
self.metric.filteredApplications = apps;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
p.filterItems = function () {
|
||||
filterItems() {
|
||||
var self = this;
|
||||
var item_type = this.editorModes[this.target.mode];
|
||||
var groupFilter = this.templateSrv.replace(this.target.group.filter);
|
||||
@@ -135,32 +131,34 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
item_type, this.target.showDisabledItems).then(function(items) {
|
||||
self.metric.filteredItems = items;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
p.onTargetPartChange = function (targetPart) {
|
||||
onTargetPartChange(targetPart) {
|
||||
var regexStyle = {'color': '#CCA300'};
|
||||
targetPart.isRegex = utils.isRegex(targetPart.filter);
|
||||
targetPart.style = targetPart.isRegex ? regexStyle : {};
|
||||
};
|
||||
}
|
||||
|
||||
p.onTargetBlur = function() {
|
||||
onTargetBlur() {
|
||||
this.initFilters();
|
||||
this.parseTarget();
|
||||
this.panelCtrl.refresh();
|
||||
};
|
||||
}
|
||||
|
||||
p.parseTarget = function() {
|
||||
parseTarget() {
|
||||
// Parse target
|
||||
};
|
||||
}
|
||||
|
||||
// Validate target and set validation info
|
||||
p.validateTarget = function () {};
|
||||
validateTarget() {
|
||||
// validate
|
||||
}
|
||||
|
||||
p.targetChanged = function() {
|
||||
targetChanged() {
|
||||
this.panelCtrl.refresh();
|
||||
};
|
||||
}
|
||||
|
||||
p.addFunction = function(funcDef) {
|
||||
addFunction(funcDef) {
|
||||
var newFunc = metricFunctions.createFuncInstance(funcDef);
|
||||
newFunc.added = true;
|
||||
this.target.functions.push(newFunc);
|
||||
@@ -171,14 +169,14 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
newFunc.def.params.length === 0) {
|
||||
this.targetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
p.removeFunction = function(func) {
|
||||
removeFunction(func) {
|
||||
this.target.functions = _.without(this.target.functions, func);
|
||||
this.targetChanged();
|
||||
};
|
||||
}
|
||||
|
||||
p.moveAliasFuncLast = function() {
|
||||
moveAliasFuncLast() {
|
||||
var aliasFunc = _.find(this.target.functions, function(func) {
|
||||
return func.def.name === 'alias' ||
|
||||
func.def.name === 'aliasByNode' ||
|
||||
@@ -189,7 +187,7 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
this.target.functions = _.without(this.target.functions, aliasFunc);
|
||||
this.target.functions.push(aliasFunc);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch query editor to specified mode.
|
||||
@@ -198,10 +196,10 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
* 1 - IT services
|
||||
* 2 - Text metrics
|
||||
*/
|
||||
p.switchEditorMode = function (mode) {
|
||||
switchEditorMode(mode) {
|
||||
this.target.mode = mode;
|
||||
this.init();
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// IT Services //
|
||||
@@ -210,33 +208,30 @@ function (sdk, angular, _, metricFunctions, utils) {
|
||||
/**
|
||||
* Update list of IT services
|
||||
*/
|
||||
p.updateITServiceList = function () {
|
||||
updateITServiceList() {
|
||||
var self = this;
|
||||
this.datasource.zabbixAPI.getITService().then(function (iteservices) {
|
||||
self.itserviceList = [];
|
||||
self.itserviceList = self.itserviceList.concat(iteservices);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when IT service is selected.
|
||||
*/
|
||||
p.selectITService = function () {
|
||||
selectITService() {
|
||||
if (!_.isEqual(this.oldTarget, this.target) && _.isEmpty(this.target.errors)) {
|
||||
this.oldTarget = angular.copy(this.target);
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
return ZabbixQueryCtrl;
|
||||
|
||||
})(sdk.QueryCtrl);
|
||||
|
||||
return ZabbixQueryCtrl;
|
||||
|
||||
// Get list of metric names for bs-typeahead directive
|
||||
function getMetricNames(scope, metricList) {
|
||||
return _.uniq(_.map(scope.metric[metricList], 'name'));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// Set templateUrl as static property
|
||||
ZabbixQueryCtrl.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'));
|
||||
}
|
||||
@@ -1,20 +1,15 @@
|
||||
define([
|
||||
'lodash',
|
||||
'moment'
|
||||
],
|
||||
function (_, moment) {
|
||||
'use strict';
|
||||
import _ from 'lodash';
|
||||
import moment from 'moment';
|
||||
|
||||
function Utils() {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Expand Zabbix item name
|
||||
*
|
||||
* @param {string} name item name, ie "CPU $2 time"
|
||||
* @param {string} key item key, ie system.cpu.util[,system,avg1]
|
||||
* @return {string} expanded name, ie "CPU system time"
|
||||
*/
|
||||
this.expandItemName = function(name, key) {
|
||||
export function expandItemName(name, key) {
|
||||
|
||||
// extract params from key:
|
||||
// "system.cpu.util[,system,avg1]" --> ["", "system", "avg1"]
|
||||
@@ -25,35 +20,35 @@ function (_, moment) {
|
||||
name = name.replace('$' + i, key_params[i - 1]);
|
||||
}
|
||||
return name;
|
||||
};
|
||||
}
|
||||
|
||||
// Pattern for testing regex
|
||||
var regexPattern = /^\/(.*)\/([gmi]*)$/m;
|
||||
// Pattern for testing regex
|
||||
var regexPattern = /^\/(.*)\/([gmi]*)$/m;
|
||||
|
||||
this.isRegex = function (str) {
|
||||
export function isRegex(str) {
|
||||
return regexPattern.test(str);
|
||||
};
|
||||
}
|
||||
|
||||
this.buildRegex = function (str) {
|
||||
export function buildRegex(str) {
|
||||
var matches = str.match(regexPattern);
|
||||
var pattern = matches[1];
|
||||
var flags = matches[2] !== "" ? matches[2] : undefined;
|
||||
return new RegExp(pattern, flags);
|
||||
};
|
||||
}
|
||||
|
||||
this.parseInterval = function(interval) {
|
||||
export function parseInterval(interval) {
|
||||
var intervalPattern = /(^[\d]+)(y|M|w|d|h|m|s)/g;
|
||||
var momentInterval = intervalPattern.exec(interval);
|
||||
return moment.duration(Number(momentInterval[1]), momentInterval[2]).valueOf();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Format acknowledges.
|
||||
*
|
||||
* @param {array} acknowledges array of Zabbix acknowledge objects
|
||||
* @return {string} HTML-formatted table
|
||||
*/
|
||||
this.formatAcknowledges = function(acknowledges) {
|
||||
export function formatAcknowledges(acknowledges) {
|
||||
if (acknowledges.length) {
|
||||
var formatted_acknowledges = '<br><br>Acknowledges:<br><table><tr><td><b>Time</b></td>'
|
||||
+ '<td><b>User</b></td><td><b>Comments</b></td></tr>';
|
||||
@@ -69,9 +64,4 @@ function (_, moment) {
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return new Utils();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user