Merge branch 'master' into backend

This commit is contained in:
Alexander Zobnin
2020-05-29 10:33:11 +03:00
4 changed files with 1335 additions and 237 deletions

View File

@@ -26,68 +26,68 @@
"url": "https://github.com/alexanderzobnin/grafana-zabbix/issues" "url": "https://github.com/alexanderzobnin/grafana-zabbix/issues"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.7.7", "@babel/core": "7.7.7",
"@babel/preset-env": "^7.7.7", "@babel/preset-env": "7.7.7",
"@babel/preset-react": "^7.6.3", "@babel/preset-react": "7.6.3",
"@emotion/core": "^10.0.27", "@emotion/core": "10.0.27",
"@grafana/data": "^6.7.3", "@grafana/data": "6.7.3",
"@grafana/runtime": "^6.7.3", "@grafana/runtime": "6.7.3",
"@grafana/ui": "^6.7.3", "@grafana/ui": "6.7.3",
"@popperjs/core": "^2.4.0", "@popperjs/core": "2.4.0",
"@types/classnames": "^2.2.6", "@types/classnames": "2.2.9",
"@types/grafana": "github:CorpGlory/types-grafana", "@types/grafana": "github:CorpGlory/types-grafana",
"@types/jest": "^23.1.1", "@types/jest": "24.0.13",
"@types/jquery": "^3.3.0", "@types/jquery": "3.3.32",
"@types/lodash": "^4.14.104", "@types/lodash": "4.14.149",
"@types/moment": "^2.13.0", "@types/react": "16.8.16",
"@types/react": "^16.4.6", "@types/react-dom": "16.8.4",
"@types/react-dom": "^16.0.11", "@types/react-transition-group": "4.2.4",
"@types/react-transition-group": "^2.0.15", "babel-jest": "24.8.0",
"babel-jest": "^24.9.0", "babel-loader": "8.0.6",
"babel-loader": "^8.0.6", "babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-angularjs-annotate": "0.10.0",
"benchmark": "^2.1.4", "benchmark": "^2.1.4",
"classnames": "^2.2.6", "classnames": "2.2.6",
"clean-webpack-plugin": "^0.1.19", "clean-webpack-plugin": "^0.1.19",
"codecov": "^3.1.0", "codecov": "^3.1.0",
"copy-webpack-plugin": "^5.1.1", "copy-webpack-plugin": "^5.1.1",
"css-loader": "2.1.1", "css-loader": "3.4.2",
"extract-text-webpack-plugin": "^4.0.0-beta.0", "extract-text-webpack-plugin": "^4.0.0-beta.0",
"grunt": "^1.0.3", "grunt": "1.0.4",
"grunt-benchmark": "^1.0.0", "grunt-benchmark": "^1.0.0",
"grunt-cli": "^1.3.1", "grunt-cli": "1.3.2",
"grunt-execute": "^0.2.2", "grunt-execute": "^0.2.2",
"html-loader": "^0.5.5", "html-loader": "0.5.5",
"jest": "^24.9.0", "jest": "24.8.0",
"jscs": "^3.0.7", "jscs": "^3.0.7",
"jsdom": "~11.3.0", "jsdom": "~11.3.0",
"jshint": "^2.9.6", "jshint": "^2.9.6",
"jshint-stylish": "^2.1.0", "jshint-stylish": "^2.1.0",
"load-grunt-tasks": "~3.2.0", "load-grunt-tasks": "~3.2.0",
"lodash": "~4.17.13", "lodash": "4.17.15",
"memoize-one": "^5.1.1", "memoize-one": "5.1.1",
"moment": "~2.21.0", "moment": "2.24.0",
"ng-annotate-webpack-plugin": "^0.3.0", "ng-annotate-webpack-plugin": "0.3.0",
"node-sass": "^4.13.0", "node-sass": "4.13.1",
"prop-types": "^15.6.2", "prop-types": "15.7.2",
"react": "16.12.0", "react": "16.12.0",
"react-dom": "16.12.0", "react-dom": "16.12.0",
"react-popper": "^2.2.3", "react-popper": "^2.2.3",
"react-table-6": "^6.8.6", "react-table-6": "^6.8.6",
"react-test-renderer": "^16.7.0", "react-test-renderer": "^16.7.0",
"react-transition-group": "^2.5.2", "react-transition-group": "4.3.0",
"rst2html": "github:thoward/rst2html#990cb89", "rst2html": "github:thoward/rst2html#990cb89",
"sass-loader": "7.1.0", "sass-loader": "8.0.2",
"semver": "^7.3.2", "semver": "^7.3.2",
"style-loader": "^0.23.1", "style-loader": "1.1.3",
"tether-drop": "^1.4.2", "tether-drop": "^1.4.2",
"ts-jest": "^24.2.0", "ts-jest": "24.1.0",
"ts-loader": "^4.4.1", "ts-loader": "4.4.1",
"tslint": "5.20.1", "tslint": "5.20.1",
"typescript": "^3.9.2", "typescript": "3.9.2",
"webpack": "4.29.6", "webpack": "4.41.5",
"webpack-cli": "3.2.3" "webpack-cli": "3.3.10"
}, },
"resolutions": { "resolutions": {
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",

View File

@@ -306,6 +306,7 @@ class FuncInstance {
def: any; def: any;
params: any; params: any;
text: string; text: string;
added: boolean;
constructor(funcDef, params) { constructor(funcDef, params) {
this.def = funcDef; this.def = funcDef;
@@ -408,7 +409,7 @@ class FuncInstance {
} }
} }
export function createFuncInstance(funcDef, params) { export function createFuncInstance(funcDef, params?) {
if (_.isString(funcDef)) { if (_.isString(funcDef)) {
if (!index[funcDef]) { if (!index[funcDef]) {
throw { message: 'Method not found ' + name }; throw { message: 'Method not found ' + name };

View File

@@ -58,6 +58,32 @@ function getSeverityOptions() {
} }
export class ZabbixQueryController extends QueryCtrl { export class ZabbixQueryController extends QueryCtrl {
static templateUrl: string;
zabbix: any;
replaceTemplateVars: any;
templateSrv: any;
editorModes: Array<{ value: string; text: string; queryType: number; }>;
slaPropertyList: Array<{ name: string; property: string; }>;
slaIntervals: Array<{ text: string; value: string; }>;
ackFilters: Array<{ text: string; value: number; }>;
problemAckFilters: string[];
sortByFields: Array<{ text: string; value: string; }>;
showEventsFields: Array<{ text: string; value: number[]; } | { text: string; value: number; }>;
showProblemsOptions: Array<{ text: string; value: string; }>;
resultFormats: Array<{ text: string; value: string; }>;
severityOptions: Array<{ val: number; text: string; }>;
getGroupNames: (...args: any[]) => any;
getHostNames: (...args: any[]) => any;
getApplicationNames: (...args: any[]) => any;
getItemNames: (...args: any[]) => any;
getITServices: (...args: any[]) => any;
getProxyNames: (...args: any[]) => any;
getVariables: (...args: any[]) => any;
init: () => void;
queryOptionsText: string;
metric: any;
showQueryOptions: boolean;
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, $rootScope, $sce, templateSrv) { constructor($scope, $injector, $rootScope, $sce, templateSrv) {
@@ -156,12 +182,12 @@ export class ZabbixQueryController extends QueryCtrl {
}); });
this.init = function() { this.init = function() {
var target = this.target; let target = this.target;
// Migrate old targets // Migrate old targets
target = migrations.migrate(target); target = migrations.migrate(target);
var scopeDefaults = { const scopeDefaults = {
metric: {}, metric: {},
oldTarget: _.cloneDeep(this.target), oldTarget: _.cloneDeep(this.target),
queryOptionsText: this.renderQueryOptionsText() queryOptionsText: this.renderQueryOptionsText()
@@ -177,7 +203,7 @@ export class ZabbixQueryController extends QueryCtrl {
} }
// Create function instances from saved JSON // Create function instances from saved JSON
target.functions = _.map(target.functions, function(func) { target.functions = _.map(target.functions, func => {
return metricFunctions.createFuncInstance(func.def, func.params); return metricFunctions.createFuncInstance(func.def, func.params);
}); });
@@ -204,8 +230,8 @@ export class ZabbixQueryController extends QueryCtrl {
} }
initFilters() { initFilters() {
let itemtype = _.find(this.editorModes, {'queryType': this.target.queryType}); const mode = _.find(this.editorModes, {'queryType': this.target.queryType});
itemtype = itemtype ? itemtype.value : null; const itemtype = mode ? mode.value : null;
const promises = [ const promises = [
this.suggestGroups(), this.suggestGroups(),
this.suggestHosts(), this.suggestHosts(),
@@ -222,7 +248,7 @@ export class ZabbixQueryController extends QueryCtrl {
// Get list of metric names for bs-typeahead directive // Get list of metric names for bs-typeahead directive
getMetricNames(metricList, addAllValue) { getMetricNames(metricList, addAllValue) {
let metrics = _.uniq(_.map(this.metric[metricList], 'name')); const metrics = _.uniq(_.map(this.metric[metricList], 'name'));
// Add template variables // Add template variables
_.forEach(this.templateSrv.variables, variable => { _.forEach(this.templateSrv.variables, variable => {
@@ -251,7 +277,7 @@ export class ZabbixQueryController extends QueryCtrl {
} }
suggestHosts() { suggestHosts() {
let groupFilter = this.replaceTemplateVars(this.target.group.filter); const groupFilter = this.replaceTemplateVars(this.target.group.filter);
return this.zabbix.getAllHosts(groupFilter) return this.zabbix.getAllHosts(groupFilter)
.then(hosts => { .then(hosts => {
this.metric.hostList = hosts; this.metric.hostList = hosts;
@@ -260,8 +286,8 @@ export class ZabbixQueryController extends QueryCtrl {
} }
suggestApps() { suggestApps() {
let groupFilter = this.replaceTemplateVars(this.target.group.filter); const groupFilter = this.replaceTemplateVars(this.target.group.filter);
let hostFilter = this.replaceTemplateVars(this.target.host.filter); const hostFilter = this.replaceTemplateVars(this.target.host.filter);
return this.zabbix.getAllApps(groupFilter, hostFilter) return this.zabbix.getAllApps(groupFilter, hostFilter)
.then(apps => { .then(apps => {
this.metric.appList = apps; this.metric.appList = apps;
@@ -270,10 +296,10 @@ export class ZabbixQueryController extends QueryCtrl {
} }
suggestItems(itemtype = 'num') { suggestItems(itemtype = 'num') {
let groupFilter = this.replaceTemplateVars(this.target.group.filter); const groupFilter = this.replaceTemplateVars(this.target.group.filter);
let hostFilter = this.replaceTemplateVars(this.target.host.filter); const hostFilter = this.replaceTemplateVars(this.target.host.filter);
let appFilter = this.replaceTemplateVars(this.target.application.filter); const appFilter = this.replaceTemplateVars(this.target.application.filter);
let options = { const options = {
itemtype: itemtype, itemtype: itemtype,
showDisabledItems: this.target.options.showDisabledItems showDisabledItems: this.target.options.showDisabledItems
}; };
@@ -312,12 +338,15 @@ export class ZabbixQueryController extends QueryCtrl {
} }
onTargetBlur() { onTargetBlur() {
var newTarget = _.cloneDeep(this.target); const newTarget = _.cloneDeep(this.target);
if (!_.isEqual(this.oldTarget, this.target)) { if (!_.isEqual(this.oldTarget, this.target)) {
this.oldTarget = newTarget; this.oldTarget = newTarget;
this.targetChanged(); this.targetChanged();
} }
} }
oldTarget(oldTarget: any, target: any) {
throw new Error("Method not implemented.");
}
onVariableChange() { onVariableChange() {
if (this.isContainsVariables()) { if (this.isContainsVariables()) {
@@ -354,7 +383,7 @@ export class ZabbixQueryController extends QueryCtrl {
} }
addFunction(funcDef) { addFunction(funcDef) {
var newFunc = metricFunctions.createFuncInstance(funcDef); const newFunc = metricFunctions.createFuncInstance(funcDef);
newFunc.added = true; newFunc.added = true;
this.target.functions.push(newFunc); this.target.functions.push(newFunc);
@@ -373,12 +402,12 @@ export class ZabbixQueryController extends QueryCtrl {
moveFunction(func, offset) { moveFunction(func, offset) {
const index = this.target.functions.indexOf(func); const index = this.target.functions.indexOf(func);
_.move(this.target.functions, index, index + offset); (_ as any).move(this.target.functions, index, index + offset);
this.targetChanged(); this.targetChanged();
} }
moveAliasFuncLast() { moveAliasFuncLast() {
var aliasFunc = _.find(this.target.functions, func => { const aliasFunc = _.find(this.target.functions, func => {
return func.def.category === 'Alias'; return func.def.category === 'Alias';
}); });

1426
yarn.lock

File diff suppressed because it is too large Load Diff