Added migrations module for target format converting.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import * as dateMath from 'app/core/utils/datemath';
|
import * as dateMath from 'app/core/utils/datemath';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
import * as migrations from './migrations';
|
||||||
import * as metricFunctions from './metricFunctions';
|
import * as metricFunctions from './metricFunctions';
|
||||||
import DataProcessor from './DataProcessor';
|
import DataProcessor from './DataProcessor';
|
||||||
import './zabbixAPI.service.js';
|
import './zabbixAPI.service.js';
|
||||||
@@ -110,6 +111,8 @@ export class ZabbixAPIDatasource {
|
|||||||
var promises = _.map(options.targets, function(target) {
|
var promises = _.map(options.targets, function(target) {
|
||||||
|
|
||||||
if (target.mode !== 1) {
|
if (target.mode !== 1) {
|
||||||
|
//console.log(migrations.isGrafana2target(target), target);
|
||||||
|
target = migrations.migrate(target);
|
||||||
|
|
||||||
// Don't request undefined and hidden targets
|
// Don't request undefined and hidden targets
|
||||||
if (target.hide || !target.group ||
|
if (target.hide || !target.group ||
|
||||||
|
|||||||
53
src/datasource-zabbix/migrations.js
Normal file
53
src/datasource-zabbix/migrations.js
Normal 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 + '/';
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import {QueryCtrl} from 'app/plugins/sdk';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
import * as metricFunctions from './metricFunctions';
|
import * as metricFunctions from './metricFunctions';
|
||||||
|
import * as migrations from './migrations';
|
||||||
|
|
||||||
import './add-metric-function.directive';
|
import './add-metric-function.directive';
|
||||||
import './metric-function-editor.directive';
|
import './metric-function-editor.directive';
|
||||||
@@ -32,6 +33,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
|
|
||||||
|
this.target = migrations.migrate(this.target);
|
||||||
|
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
var target = this.target;
|
var target = this.target;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user