Add options for table
This commit is contained in:
@@ -17,6 +17,17 @@
|
|||||||
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.resultFormat" ng-options="f.value as f.text for f in ctrl.resultFormats" ng-change="ctrl.refresh()"></select>
|
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.resultFormat" ng-options="f.value as f.text for f in ctrl.resultFormats" ng-change="ctrl.refresh()"></select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="gf-form" ng-show="ctrl.target.mode == editorMode.TEXT && ctrl.target.resultFormat === 'table'">
|
||||||
|
<label class="gf-form-label query-keyword width-8">Options</label>
|
||||||
|
<gf-form-switch class="gf-form" label="Host" checked="ctrl.target.table.host" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label="Item" checked="ctrl.target.table.item" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label="Key" checked="ctrl.target.table.key" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label="Skip empty values" checked="ctrl.target.table.skipEmptyValues" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
</div>
|
||||||
<div class="gf-form gf-form--grow">
|
<div class="gf-form gf-form--grow">
|
||||||
<div class="gf-form-label gf-form-label--grow"></div>
|
<div class="gf-form-label gf-form-label--grow"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
6
dist/datasource-zabbix/query.controller.js
vendored
6
dist/datasource-zabbix/query.controller.js
vendored
@@ -147,6 +147,12 @@ System.register(['app/plugins/sdk', 'lodash', './constants', './utils', './metri
|
|||||||
},
|
},
|
||||||
'options': {
|
'options': {
|
||||||
'showDisabledItems': false
|
'showDisabledItems': false
|
||||||
|
},
|
||||||
|
'table': {
|
||||||
|
'host': true,
|
||||||
|
'item': true,
|
||||||
|
'key': true,
|
||||||
|
'skipEmptyValues': false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_.defaults(target, targetDefaults);
|
_.defaults(target, targetDefaults);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
30
dist/datasource-zabbix/responseHandler.js
vendored
30
dist/datasource-zabbix/responseHandler.js
vendored
@@ -74,9 +74,15 @@ System.register(['lodash', 'app/core/table_model', './constants'], function (_ex
|
|||||||
return convertHistory(history, items, addHostName, convertTextCallback);
|
return convertHistory(history, items, addHostName, convertTextCallback);
|
||||||
}function handleHistoryAsTable(history, items, target) {
|
}function handleHistoryAsTable(history, items, target) {
|
||||||
var table = new TableModel();
|
var table = new TableModel();
|
||||||
table.addColumn({ text: 'Host' });
|
if (target.table.host) {
|
||||||
table.addColumn({ text: 'Item' });
|
table.addColumn({ text: 'Host' });
|
||||||
table.addColumn({ text: 'Key' });
|
}
|
||||||
|
if (target.table.item) {
|
||||||
|
table.addColumn({ text: 'Item' });
|
||||||
|
}
|
||||||
|
if (target.table.key) {
|
||||||
|
table.addColumn({ text: 'Key' });
|
||||||
|
}
|
||||||
table.addColumn({ text: 'Last value' });
|
table.addColumn({ text: 'Last value' });
|
||||||
|
|
||||||
var grouped_history = _.groupBy(history, 'itemid');
|
var grouped_history = _.groupBy(history, 'itemid');
|
||||||
@@ -85,6 +91,10 @@ System.register(['lodash', 'app/core/table_model', './constants'], function (_ex
|
|||||||
var lastPoint = _.last(itemHistory);
|
var lastPoint = _.last(itemHistory);
|
||||||
var lastValue = lastPoint ? lastPoint.value : null;
|
var lastValue = lastPoint ? lastPoint.value : null;
|
||||||
|
|
||||||
|
if (target.table.skipEmptyValues && (!lastValue || lastValue === '')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Regex-based extractor
|
// Regex-based extractor
|
||||||
if (target.textFilter) {
|
if (target.textFilter) {
|
||||||
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||||
@@ -93,7 +103,19 @@ System.register(['lodash', 'app/core/table_model', './constants'], function (_ex
|
|||||||
var host = _.first(item.hosts);
|
var host = _.first(item.hosts);
|
||||||
host = host ? host.name : "";
|
host = host ? host.name : "";
|
||||||
|
|
||||||
table.rows.push([host, item.name, item.key_, lastValue]);
|
var row = [];
|
||||||
|
if (target.table.host) {
|
||||||
|
row.push(host);
|
||||||
|
}
|
||||||
|
if (target.table.item) {
|
||||||
|
row.push(item.name);
|
||||||
|
}
|
||||||
|
if (target.table.key) {
|
||||||
|
row.push(item.key_);
|
||||||
|
}
|
||||||
|
row.push(lastValue);
|
||||||
|
|
||||||
|
table.rows.push(row);
|
||||||
});
|
});
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
40
dist/datasource-zabbix/specs/datasource.spec.js
vendored
40
dist/datasource-zabbix/specs/datasource.spec.js
vendored
@@ -126,7 +126,13 @@ describe('ZabbixDatasource', () => {
|
|||||||
textFilter: "",
|
textFilter: "",
|
||||||
useCaptureGroups: true,
|
useCaptureGroups: true,
|
||||||
mode: 2,
|
mode: 2,
|
||||||
resultFormat: "table"
|
resultFormat: "table",
|
||||||
|
table: {
|
||||||
|
host: true,
|
||||||
|
item: true,
|
||||||
|
key: true,
|
||||||
|
skipEmptyValues: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -155,6 +161,38 @@ describe('ZabbixDatasource', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return table only with `Last value` column when other columns are not selected', () => {
|
||||||
|
ctx.options.targets[0].table = {
|
||||||
|
host: false,
|
||||||
|
item: false,
|
||||||
|
key: false,
|
||||||
|
skipEmptyValues: false
|
||||||
|
};
|
||||||
|
return ctx.ds.query(ctx.options).then(result => {
|
||||||
|
let tableData = result.data[0];
|
||||||
|
expect(tableData.columns.length).toBe(1);
|
||||||
|
expect(tableData.columns[0].text).toEqual('Last value');
|
||||||
|
expect(tableData.rows[0].length).toBe(1);
|
||||||
|
expect(tableData.rows[0][0]).toEqual('Linux last');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should skip item when last value is empty', () => {
|
||||||
|
ctx.options.targets[0].skipEmptyValues = true;
|
||||||
|
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([
|
||||||
|
{clock: "1500010200", itemid:"10100", ns:"900111000", value:"Linux first"},
|
||||||
|
{clock: "1500010300", itemid:"10100", ns:"900111000", value:"Linux 2nd"},
|
||||||
|
{clock: "1500010400", itemid:"10100", ns:"900111000", value:"Linux last"},
|
||||||
|
{clock: "1500010200", itemid:"90109", ns:"900111000", value:"Non empty value"},
|
||||||
|
{clock: "1500010500", itemid:"90109", ns:"900111000", value:""}
|
||||||
|
]));
|
||||||
|
return ctx.ds.query(ctx.options).then(result => {
|
||||||
|
let tableData = result.data[0];
|
||||||
|
expect(tableData.rows.length).toBe(1);
|
||||||
|
expect(tableData.rows[0][3]).toEqual('Linux last');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When replacing template variables', () => {
|
describe('When replacing template variables', () => {
|
||||||
|
|||||||
@@ -17,6 +17,17 @@
|
|||||||
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.resultFormat" ng-options="f.value as f.text for f in ctrl.resultFormats" ng-change="ctrl.refresh()"></select>
|
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.resultFormat" ng-options="f.value as f.text for f in ctrl.resultFormats" ng-change="ctrl.refresh()"></select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="gf-form" ng-show="ctrl.target.mode == editorMode.TEXT && ctrl.target.resultFormat === 'table'">
|
||||||
|
<label class="gf-form-label query-keyword width-8">Options</label>
|
||||||
|
<gf-form-switch class="gf-form" label="Host" checked="ctrl.target.table.host" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label="Item" checked="ctrl.target.table.item" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label="Key" checked="ctrl.target.table.key" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
<gf-form-switch class="gf-form" label="Skip empty values" checked="ctrl.target.table.skipEmptyValues" on-change="ctrl.onTargetBlur()">
|
||||||
|
</gf-form-switch>
|
||||||
|
</div>
|
||||||
<div class="gf-form gf-form--grow">
|
<div class="gf-form gf-form--grow">
|
||||||
<div class="gf-form-label gf-form-label--grow"></div>
|
<div class="gf-form-label gf-form-label--grow"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -97,6 +97,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
},
|
},
|
||||||
'options': {
|
'options': {
|
||||||
'showDisabledItems': false
|
'showDisabledItems': false
|
||||||
|
},
|
||||||
|
'table': {
|
||||||
|
'host': true,
|
||||||
|
'item': true,
|
||||||
|
'key': true,
|
||||||
|
'skipEmptyValues': false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_.defaults(target, targetDefaults);
|
_.defaults(target, targetDefaults);
|
||||||
|
|||||||
@@ -56,9 +56,15 @@ function handleText(history, items, target, addHostName = true) {
|
|||||||
|
|
||||||
function handleHistoryAsTable(history, items, target) {
|
function handleHistoryAsTable(history, items, target) {
|
||||||
let table = new TableModel();
|
let table = new TableModel();
|
||||||
table.addColumn({text: 'Host'});
|
if(target.table.host) {
|
||||||
table.addColumn({text: 'Item'});
|
table.addColumn({text: 'Host'});
|
||||||
table.addColumn({text: 'Key'});
|
}
|
||||||
|
if(target.table.item) {
|
||||||
|
table.addColumn({text: 'Item'});
|
||||||
|
}
|
||||||
|
if(target.table.key) {
|
||||||
|
table.addColumn({text: 'Key'});
|
||||||
|
}
|
||||||
table.addColumn({text: 'Last value'});
|
table.addColumn({text: 'Last value'});
|
||||||
|
|
||||||
let grouped_history = _.groupBy(history, 'itemid');
|
let grouped_history = _.groupBy(history, 'itemid');
|
||||||
@@ -67,6 +73,10 @@ function handleHistoryAsTable(history, items, target) {
|
|||||||
let lastPoint = _.last(itemHistory);
|
let lastPoint = _.last(itemHistory);
|
||||||
let lastValue = lastPoint ? lastPoint.value : null;
|
let lastValue = lastPoint ? lastPoint.value : null;
|
||||||
|
|
||||||
|
if(target.table.skipEmptyValues && (!lastValue || lastValue === '')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Regex-based extractor
|
// Regex-based extractor
|
||||||
if (target.textFilter) {
|
if (target.textFilter) {
|
||||||
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||||
@@ -75,9 +85,19 @@ function handleHistoryAsTable(history, items, target) {
|
|||||||
let host = _.first(item.hosts);
|
let host = _.first(item.hosts);
|
||||||
host = host ? host.name : "";
|
host = host ? host.name : "";
|
||||||
|
|
||||||
table.rows.push([
|
let row = [];
|
||||||
host, item.name, item.key_, lastValue
|
if(target.table.host) {
|
||||||
]);
|
row.push(host);
|
||||||
|
}
|
||||||
|
if(target.table.item) {
|
||||||
|
row.push(item.name);
|
||||||
|
}
|
||||||
|
if(target.table.key) {
|
||||||
|
row.push(item.key_);
|
||||||
|
}
|
||||||
|
row.push(lastValue);
|
||||||
|
|
||||||
|
table.rows.push(row);
|
||||||
});
|
});
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
|
|||||||
@@ -126,7 +126,13 @@ describe('ZabbixDatasource', () => {
|
|||||||
textFilter: "",
|
textFilter: "",
|
||||||
useCaptureGroups: true,
|
useCaptureGroups: true,
|
||||||
mode: 2,
|
mode: 2,
|
||||||
resultFormat: "table"
|
resultFormat: "table",
|
||||||
|
table: {
|
||||||
|
host: true,
|
||||||
|
item: true,
|
||||||
|
key: true,
|
||||||
|
skipEmptyValues: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -155,6 +161,38 @@ describe('ZabbixDatasource', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return table only with `Last value` column when other columns are not selected', () => {
|
||||||
|
ctx.options.targets[0].table = {
|
||||||
|
host: false,
|
||||||
|
item: false,
|
||||||
|
key: false,
|
||||||
|
skipEmptyValues: false
|
||||||
|
};
|
||||||
|
return ctx.ds.query(ctx.options).then(result => {
|
||||||
|
let tableData = result.data[0];
|
||||||
|
expect(tableData.columns.length).toBe(1);
|
||||||
|
expect(tableData.columns[0].text).toEqual('Last value');
|
||||||
|
expect(tableData.rows[0].length).toBe(1);
|
||||||
|
expect(tableData.rows[0][0]).toEqual('Linux last');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should skip item when last value is empty', () => {
|
||||||
|
ctx.options.targets[0].skipEmptyValues = true;
|
||||||
|
ctx.ds.zabbix.getHistory = jest.fn().mockReturnValue(Promise.resolve([
|
||||||
|
{clock: "1500010200", itemid:"10100", ns:"900111000", value:"Linux first"},
|
||||||
|
{clock: "1500010300", itemid:"10100", ns:"900111000", value:"Linux 2nd"},
|
||||||
|
{clock: "1500010400", itemid:"10100", ns:"900111000", value:"Linux last"},
|
||||||
|
{clock: "1500010200", itemid:"90109", ns:"900111000", value:"Non empty value"},
|
||||||
|
{clock: "1500010500", itemid:"90109", ns:"900111000", value:""}
|
||||||
|
]));
|
||||||
|
return ctx.ds.query(ctx.options).then(result => {
|
||||||
|
let tableData = result.data[0];
|
||||||
|
expect(tableData.rows.length).toBe(1);
|
||||||
|
expect(tableData.rows[0][3]).toEqual('Linux last');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When replacing template variables', () => {
|
describe('When replacing template variables', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user