implement replaceAlias() function, #287
This commit is contained in:
14
dist/datasource-zabbix/dataProcessor.js
vendored
14
dist/datasource-zabbix/dataProcessor.js
vendored
@@ -150,6 +150,17 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
||||
}function setAlias(alias, timeseries) {
|
||||
timeseries.target = alias;
|
||||
return timeseries;
|
||||
}function replaceAlias(regexp, newAlias, timeseries) {
|
||||
var pattern = void 0;
|
||||
if (utils.isRegex(regexp)) {
|
||||
pattern = utils.buildRegex(regexp);
|
||||
} else {
|
||||
pattern = regexp;
|
||||
}
|
||||
|
||||
var alias = timeseries.target.replace(pattern, newAlias);
|
||||
timeseries.target = alias;
|
||||
return timeseries;
|
||||
}function setAliasByRegex(alias, timeseries) {
|
||||
timeseries.target = extractText(timeseries.target, alias);
|
||||
return timeseries;
|
||||
@@ -265,7 +276,8 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
||||
bottom: _.partial(limit, 'bottom'),
|
||||
timeShift: timeShift,
|
||||
setAlias: setAlias,
|
||||
setAliasByRegex: setAliasByRegex
|
||||
setAliasByRegex: setAliasByRegex,
|
||||
replaceAlias: replaceAlias
|
||||
};
|
||||
aggregationFunctions = {
|
||||
avg: AVERAGE,
|
||||
|
||||
2
dist/datasource-zabbix/dataProcessor.js.map
vendored
2
dist/datasource-zabbix/dataProcessor.js.map
vendored
File diff suppressed because one or more lines are too long
42
dist/datasource-zabbix/datasource.js
vendored
42
dist/datasource-zabbix/datasource.js
vendored
@@ -334,12 +334,10 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
var getHistoryPromise = void 0;
|
||||
|
||||
if (useTrends) {
|
||||
(function () {
|
||||
var valueType = _this2.getTrendValueType(target);
|
||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
return responseHandler.handleTrends(history, items, valueType);
|
||||
});
|
||||
})();
|
||||
var valueType = _this2.getTrendValueType(target);
|
||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
return responseHandler.handleTrends(history, items, valueType);
|
||||
});
|
||||
} else {
|
||||
// Use history
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
@@ -386,20 +384,18 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
|
||||
// Apply aggregations
|
||||
if (aggregationFunctions.length) {
|
||||
(function () {
|
||||
var dp = _.map(timeseries_data, 'datapoints');
|
||||
dp = sequence(aggregationFunctions)(dp);
|
||||
var dp = _.map(timeseries_data, 'datapoints');
|
||||
dp = sequence(aggregationFunctions)(dp);
|
||||
|
||||
var aggFuncNames = _.map(metricFunctions.getCategories()['Aggregate'], 'name');
|
||||
var lastAgg = _.findLast(target.functions, function (func) {
|
||||
return _.includes(aggFuncNames, func.def.name);
|
||||
});
|
||||
var aggFuncNames = _.map(metricFunctions.getCategories()['Aggregate'], 'name');
|
||||
var lastAgg = _.findLast(target.functions, function (func) {
|
||||
return _.includes(aggFuncNames, func.def.name);
|
||||
});
|
||||
|
||||
timeseries_data = [{
|
||||
target: lastAgg.text,
|
||||
datapoints: dp
|
||||
}];
|
||||
})();
|
||||
timeseries_data = [{
|
||||
target: lastAgg.text,
|
||||
datapoints: dp
|
||||
}];
|
||||
}
|
||||
|
||||
// Apply alias functions
|
||||
@@ -419,12 +415,10 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return func.def.name === 'timeShift';
|
||||
});
|
||||
if (timeShiftFunc) {
|
||||
(function () {
|
||||
var shift = timeShiftFunc.params[0];
|
||||
_.forEach(timeseries_data, function (series) {
|
||||
series.datapoints = dataProcessor.unShiftTimeSeries(shift, series.datapoints);
|
||||
});
|
||||
})();
|
||||
var shift = timeShiftFunc.params[0];
|
||||
_.forEach(timeseries_data, function (series) {
|
||||
series.datapoints = dataProcessor.unShiftTimeSeries(shift, series.datapoints);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
7
dist/datasource-zabbix/metricFunctions.js
vendored
7
dist/datasource-zabbix/metricFunctions.js
vendored
@@ -211,6 +211,13 @@ System.register(['lodash', 'jquery'], function (_export, _context) {
|
||||
defaultParams: []
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'replaceAlias',
|
||||
category: 'Alias',
|
||||
params: [{ name: 'regexp', type: 'string' }, { name: 'newAlias', type: 'string' }],
|
||||
defaultParams: ['/(.*)/', '$1']
|
||||
});
|
||||
|
||||
_.each(categories, function (funcList, catName) {
|
||||
categories[catName] = _.sortBy(funcList, 'name');
|
||||
});
|
||||
|
||||
File diff suppressed because one or more lines are too long
16
dist/test/datasource-zabbix/dataProcessor.js
vendored
16
dist/test/datasource-zabbix/dataProcessor.js
vendored
@@ -181,6 +181,19 @@ function setAlias(alias, timeseries) {
|
||||
return timeseries;
|
||||
}
|
||||
|
||||
function replaceAlias(regexp, newAlias, timeseries) {
|
||||
var pattern = void 0;
|
||||
if (utils.isRegex(regexp)) {
|
||||
pattern = utils.buildRegex(regexp);
|
||||
} else {
|
||||
pattern = regexp;
|
||||
}
|
||||
|
||||
var alias = timeseries.target.replace(pattern, newAlias);
|
||||
timeseries.target = alias;
|
||||
return timeseries;
|
||||
}
|
||||
|
||||
function setAliasByRegex(alias, timeseries) {
|
||||
timeseries.target = extractText(timeseries.target, alias);
|
||||
return timeseries;
|
||||
@@ -315,7 +328,8 @@ var metricFunctions = {
|
||||
bottom: _lodash2.default.partial(limit, 'bottom'),
|
||||
timeShift: timeShift,
|
||||
setAlias: setAlias,
|
||||
setAliasByRegex: setAliasByRegex
|
||||
setAliasByRegex: setAliasByRegex,
|
||||
replaceAlias: replaceAlias
|
||||
};
|
||||
|
||||
var aggregationFunctions = {
|
||||
|
||||
42
dist/test/datasource-zabbix/datasource.js
vendored
42
dist/test/datasource-zabbix/datasource.js
vendored
@@ -192,12 +192,10 @@ var ZabbixAPIDatasource = function () {
|
||||
var getHistoryPromise = void 0;
|
||||
|
||||
if (useTrends) {
|
||||
(function () {
|
||||
var valueType = _this2.getTrendValueType(target);
|
||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
return _responseHandler2.default.handleTrends(history, items, valueType);
|
||||
});
|
||||
})();
|
||||
var valueType = _this2.getTrendValueType(target);
|
||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
return _responseHandler2.default.handleTrends(history, items, valueType);
|
||||
});
|
||||
} else {
|
||||
// Use history
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
@@ -244,20 +242,18 @@ var ZabbixAPIDatasource = function () {
|
||||
|
||||
// Apply aggregations
|
||||
if (aggregationFunctions.length) {
|
||||
(function () {
|
||||
var dp = _lodash2.default.map(timeseries_data, 'datapoints');
|
||||
dp = sequence(aggregationFunctions)(dp);
|
||||
var dp = _lodash2.default.map(timeseries_data, 'datapoints');
|
||||
dp = sequence(aggregationFunctions)(dp);
|
||||
|
||||
var aggFuncNames = _lodash2.default.map(metricFunctions.getCategories()['Aggregate'], 'name');
|
||||
var lastAgg = _lodash2.default.findLast(target.functions, function (func) {
|
||||
return _lodash2.default.includes(aggFuncNames, func.def.name);
|
||||
});
|
||||
var aggFuncNames = _lodash2.default.map(metricFunctions.getCategories()['Aggregate'], 'name');
|
||||
var lastAgg = _lodash2.default.findLast(target.functions, function (func) {
|
||||
return _lodash2.default.includes(aggFuncNames, func.def.name);
|
||||
});
|
||||
|
||||
timeseries_data = [{
|
||||
target: lastAgg.text,
|
||||
datapoints: dp
|
||||
}];
|
||||
})();
|
||||
timeseries_data = [{
|
||||
target: lastAgg.text,
|
||||
datapoints: dp
|
||||
}];
|
||||
}
|
||||
|
||||
// Apply alias functions
|
||||
@@ -277,12 +273,10 @@ var ZabbixAPIDatasource = function () {
|
||||
return func.def.name === 'timeShift';
|
||||
});
|
||||
if (timeShiftFunc) {
|
||||
(function () {
|
||||
var shift = timeShiftFunc.params[0];
|
||||
_lodash2.default.forEach(timeseries_data, function (series) {
|
||||
series.datapoints = _dataProcessor2.default.unShiftTimeSeries(shift, series.datapoints);
|
||||
});
|
||||
})();
|
||||
var shift = timeShiftFunc.params[0];
|
||||
_lodash2.default.forEach(timeseries_data, function (series) {
|
||||
series.datapoints = _dataProcessor2.default.unShiftTimeSeries(shift, series.datapoints);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
||||
@@ -174,6 +174,13 @@ addFuncDef({
|
||||
defaultParams: []
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'replaceAlias',
|
||||
category: 'Alias',
|
||||
params: [{ name: 'regexp', type: 'string' }, { name: 'newAlias', type: 'string' }],
|
||||
defaultParams: ['/(.*)/', '$1']
|
||||
});
|
||||
|
||||
_lodash2.default.each(categories, function (funcList, catName) {
|
||||
categories[catName] = _lodash2.default.sortBy(funcList, 'name');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user