Added migrations module for target format converting.

This commit is contained in:
Alexander Zobnin
2016-03-29 12:12:49 +03:00
parent ce6991cd3e
commit 3f028c7e2d
3 changed files with 59 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
import _ from 'lodash';
import * as dateMath from 'app/core/utils/datemath';
import * as utils from './utils';
import * as migrations from './migrations';
import * as metricFunctions from './metricFunctions';
import DataProcessor from './DataProcessor';
import './zabbixAPI.service.js';
@@ -110,6 +111,8 @@ export class ZabbixAPIDatasource {
var promises = _.map(options.targets, function(target) {
if (target.mode !== 1) {
//console.log(migrations.isGrafana2target(target), target);
target = migrations.migrate(target);
// Don't request undefined and hidden targets
if (target.hide || !target.group ||

View File

@@ -0,0 +1,53 @@
/**
* Query format migration.
* 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;
} 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;
}
export function migrate(target) {
if (isGrafana2target(target)) {
return migrateFrom2To3version(target);
} else {
return target;
}
}
function convertToRegex(str) {
return '/' + str + '/';
}

View File

@@ -2,6 +2,7 @@ import {QueryCtrl} from 'app/plugins/sdk';
import _ from 'lodash';
import * as utils from './utils';
import * as metricFunctions from './metricFunctions';
import * as migrations from './migrations';
import './add-metric-function.directive';
import './metric-function-editor.directive';
@@ -32,6 +33,8 @@ export class ZabbixQueryController extends QueryCtrl {
this.init = function() {
this.target = migrations.migrate(this.target);
this.templateSrv = templateSrv;
var target = this.target;