From 7f75abb2d3beb152d6701453f0adb2bbb269bedf Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 29 Mar 2016 13:50:05 +0300 Subject: [PATCH] Fixed migration issues. --- src/datasource-zabbix/datasource.js | 3 +- src/datasource-zabbix/migrations.js | 46 +++++++++-------------- src/datasource-zabbix/query.controller.js | 10 ++--- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/datasource-zabbix/datasource.js b/src/datasource-zabbix/datasource.js index 6e8805d..a259c73 100644 --- a/src/datasource-zabbix/datasource.js +++ b/src/datasource-zabbix/datasource.js @@ -111,7 +111,8 @@ export class ZabbixAPIDatasource { var promises = _.map(options.targets, function(target) { if (target.mode !== 1) { - //console.log(migrations.isGrafana2target(target), target); + + // Migrate old targets target = migrations.migrate(target); // Don't request undefined and hidden targets diff --git a/src/datasource-zabbix/migrations.js b/src/datasource-zabbix/migrations.js index 3871782..4343149 100644 --- a/src/datasource-zabbix/migrations.js +++ b/src/datasource-zabbix/migrations.js @@ -3,41 +3,31 @@ * This module can detect query format version and make migration. */ -import * as utils from './utils'; - export function isGrafana2target(target) { - if ((target.hostFilter || target.itemFilter || target.downsampleFunction || target.host.host) && - (!target.functions && !target.host.filter)) { - return true; + if (!target.mode || target.mode === 0) { + if ((target.hostFilter || target.itemFilter || target.downsampleFunction || target.host.host) && + (target.item.filter === undefined && target.host.filter === undefined)) { + return true; + } else { + return false; + } } else { return false; } } export function migrateFrom2To3version(target) { - utils.isRegex(target.host.name); - var newTarget = { - group: { - filter: target.group.name === "*" ? "/.*/" : target.group.name, - isRegex: target.group.name === "*" - }, - host: { - filter: target.host.name === "*" ? convertToRegex(target.hostFilter) : target.host.name, - isRegex: target.host.name === "*" - }, - application: { - filter: target.application.name === "*" ? "" : target.application.name, - isRegex: target.application.name === "*" - }, - item: { - filter: target.item.name === "All" ? convertToRegex(target.itemFilter) : target.item.name, - isRegex: target.item.name === "All" - }, - functions: [], - mode: target.mode, - hide: target.hide, - }; - return newTarget; + target.group.filter = target.group.name === "*" ? "/.*/" : target.group.name; + target.group.isRegex = target.group.name === "*"; + target.host.filter = target.host.name === "*" ? convertToRegex(target.hostFilter) : target.host.name; + target.host.isRegex = target.host.name === "*"; + target.application.filter = target.application.name === "*" ? "" : target.application.name; + target.application.isRegex = target.application.name === "*"; + target.item.filter = target.item.name === "All" ? convertToRegex(target.itemFilter) : target.item.name; + target.item.isRegex = target.item.name === "All"; + target.functions = []; + target.refId = target.refId ? target.refId : "A"; + return target; } export function migrate(target) { diff --git a/src/datasource-zabbix/query.controller.js b/src/datasource-zabbix/query.controller.js index 1a8a64b..daeda87 100644 --- a/src/datasource-zabbix/query.controller.js +++ b/src/datasource-zabbix/query.controller.js @@ -33,11 +33,12 @@ export class ZabbixQueryController extends QueryCtrl { this.init = function() { - this.target = migrations.migrate(this.target); - this.templateSrv = templateSrv; var target = this.target; + // Migrate old targets + target = migrations.migrate(target); + var scopeDefaults = { metric: {}, oldTarget: _.cloneDeep(this.target) @@ -69,11 +70,6 @@ export class ZabbixQueryController extends QueryCtrl { {name: "max", value: "max"} ]; - // Set avg by default - if (!target.downsampleFunction) { - target.downsampleFunction = this.downsampleFunctionList[0]; - } - this.initFilters(); } else if (target.mode === 1) {