fix regex-based text filter
This commit is contained in:
2
dist/datasource-zabbix/datasource.js
vendored
2
dist/datasource-zabbix/datasource.js
vendored
@@ -503,7 +503,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
if (items.length) {
|
if (items.length) {
|
||||||
return _this4.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
return _this4.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||||
if (target.resultFormat === 'table') {
|
if (target.resultFormat === 'table') {
|
||||||
return responseHandler.handleHistoryAsTable(history, items);
|
return responseHandler.handleHistoryAsTable(history, items, target);
|
||||||
} else {
|
} else {
|
||||||
return responseHandler.handleText(history, items, target);
|
return responseHandler.handleText(history, items, target);
|
||||||
}
|
}
|
||||||
|
|||||||
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
8
dist/datasource-zabbix/responseHandler.js
vendored
8
dist/datasource-zabbix/responseHandler.js
vendored
@@ -72,7 +72,7 @@ System.register(['lodash', 'app/core/table_model', './constants'], function (_ex
|
|||||||
|
|
||||||
var convertTextCallback = _.partial(convertText, target);
|
var convertTextCallback = _.partial(convertText, target);
|
||||||
return convertHistory(history, items, addHostName, convertTextCallback);
|
return convertHistory(history, items, addHostName, convertTextCallback);
|
||||||
}function handleHistoryAsTable(history, items) {
|
}function handleHistoryAsTable(history, items, target) {
|
||||||
var table = new TableModel();
|
var table = new TableModel();
|
||||||
table.addColumn({ text: 'Host' });
|
table.addColumn({ text: 'Host' });
|
||||||
table.addColumn({ text: 'Item' });
|
table.addColumn({ text: 'Item' });
|
||||||
@@ -84,6 +84,12 @@ System.register(['lodash', 'app/core/table_model', './constants'], function (_ex
|
|||||||
var itemHistory = grouped_history[item.itemid] || [];
|
var itemHistory = grouped_history[item.itemid] || [];
|
||||||
var lastPoint = _.last(itemHistory);
|
var lastPoint = _.last(itemHistory);
|
||||||
var lastValue = lastPoint ? lastPoint.value : null;
|
var lastValue = lastPoint ? lastPoint.value : null;
|
||||||
|
|
||||||
|
// Regex-based extractor
|
||||||
|
if (target.textFilter) {
|
||||||
|
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||||
|
}
|
||||||
|
|
||||||
var host = _.first(item.hosts);
|
var host = _.first(item.hosts);
|
||||||
host = host ? host.name : "";
|
host = host ? host.name : "";
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -123,6 +123,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
host: {filter: "Zabbix server"},
|
host: {filter: "Zabbix server"},
|
||||||
application: {filter: ""},
|
application: {filter: ""},
|
||||||
item: {filter: "System information"},
|
item: {filter: "System information"},
|
||||||
|
textFilter: "",
|
||||||
|
useCaptureGroups: true,
|
||||||
mode: 2,
|
mode: 2,
|
||||||
resultFormat: "table"
|
resultFormat: "table"
|
||||||
}
|
}
|
||||||
@@ -145,13 +147,11 @@ describe('ZabbixDatasource', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should extract value if regex is specified', (done) => {
|
it('should extract value if regex with capture group is used', (done) => {
|
||||||
ctx.options.targets[0].textFilter = "Linux (.*)";
|
ctx.options.targets[0].textFilter = "Linux (.*)";
|
||||||
ctx.ds.query(ctx.options).then(result => {
|
ctx.ds.query(ctx.options).then(result => {
|
||||||
let tableData = result.data[0];
|
let tableData = result.data[0];
|
||||||
expect(tableData.rows).toEqual([
|
expect(tableData.rows[0][3]).toEqual('last');
|
||||||
['Zabbix server', 'System information', 'system.uname', 'last']
|
|
||||||
]);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ class ZabbixAPIDatasource {
|
|||||||
return this.zabbix.getHistory(items, timeFrom, timeTo)
|
return this.zabbix.getHistory(items, timeFrom, timeTo)
|
||||||
.then(history => {
|
.then(history => {
|
||||||
if (target.resultFormat === 'table') {
|
if (target.resultFormat === 'table') {
|
||||||
return responseHandler.handleHistoryAsTable(history, items);
|
return responseHandler.handleHistoryAsTable(history, items, target);
|
||||||
} else {
|
} else {
|
||||||
return responseHandler.handleText(history, items, target);
|
return responseHandler.handleText(history, items, target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ function handleText(history, items, target, addHostName = true) {
|
|||||||
return convertHistory(history, items, addHostName, convertTextCallback);
|
return convertHistory(history, items, addHostName, convertTextCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleHistoryAsTable(history, items) {
|
function handleHistoryAsTable(history, items, target) {
|
||||||
let table = new TableModel();
|
let table = new TableModel();
|
||||||
table.addColumn({text: 'Host'});
|
table.addColumn({text: 'Host'});
|
||||||
table.addColumn({text: 'Item'});
|
table.addColumn({text: 'Item'});
|
||||||
@@ -66,6 +66,12 @@ function handleHistoryAsTable(history, items) {
|
|||||||
let itemHistory = grouped_history[item.itemid] || [];
|
let itemHistory = grouped_history[item.itemid] || [];
|
||||||
let lastPoint = _.last(itemHistory);
|
let lastPoint = _.last(itemHistory);
|
||||||
let lastValue = lastPoint ? lastPoint.value : null;
|
let lastValue = lastPoint ? lastPoint.value : null;
|
||||||
|
|
||||||
|
// Regex-based extractor
|
||||||
|
if (target.textFilter) {
|
||||||
|
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||||
|
}
|
||||||
|
|
||||||
let host = _.first(item.hosts);
|
let host = _.first(item.hosts);
|
||||||
host = host ? host.name : "";
|
host = host ? host.name : "";
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
host: {filter: "Zabbix server"},
|
host: {filter: "Zabbix server"},
|
||||||
application: {filter: ""},
|
application: {filter: ""},
|
||||||
item: {filter: "System information"},
|
item: {filter: "System information"},
|
||||||
|
textFilter: "",
|
||||||
|
useCaptureGroups: true,
|
||||||
mode: 2,
|
mode: 2,
|
||||||
resultFormat: "table"
|
resultFormat: "table"
|
||||||
}
|
}
|
||||||
@@ -145,13 +147,11 @@ describe('ZabbixDatasource', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should extract value if regex is specified', (done) => {
|
it('should extract value if regex with capture group is used', (done) => {
|
||||||
ctx.options.targets[0].textFilter = "Linux (.*)";
|
ctx.options.targets[0].textFilter = "Linux (.*)";
|
||||||
ctx.ds.query(ctx.options).then(result => {
|
ctx.ds.query(ctx.options).then(result => {
|
||||||
let tableData = result.data[0];
|
let tableData = result.data[0];
|
||||||
expect(tableData.rows).toEqual([
|
expect(tableData.rows[0][3]).toEqual('last');
|
||||||
['Zabbix server', 'System information', 'system.uname', 'last']
|
|
||||||
]);
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user