implement replaceAlias() function, #287
This commit is contained in:
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