Merge PR #526
This commit is contained in:
@@ -163,12 +163,19 @@
|
||||
<!-- Query options -->
|
||||
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
|
||||
<div class="gf-form offset-width-7" ng-hide="ctrl.target.mode == editorMode.TRIGGERS">
|
||||
<gf-form-switch class="gf-form"
|
||||
<gf-form-switch class="gf-form" label-class="width-10"
|
||||
label="Show disabled items"
|
||||
checked="ctrl.target.options.showDisabledItems"
|
||||
on-change="ctrl.onQueryOptionChange()">
|
||||
</gf-form-switch>
|
||||
</div>
|
||||
<div class="gf-form offset-width-7" ng-show="ctrl.target.mode === editorMode.TEXT && ctrl.target.resultFormat === 'table'">
|
||||
<gf-form-switch class="gf-form" label-class="width-10"
|
||||
label="Skip empty values"
|
||||
checked="ctrl.target.options.skipEmptyValues"
|
||||
on-change="ctrl.onQueryOptionChange()">
|
||||
</gf-form-switch>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Item IDs editor mode -->
|
||||
|
||||
9
dist/datasource-zabbix/query.controller.js
vendored
9
dist/datasource-zabbix/query.controller.js
vendored
@@ -146,7 +146,11 @@ System.register(['app/plugins/sdk', 'lodash', './constants', './utils', './metri
|
||||
'acknowledged': 2
|
||||
},
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
'showDisabledItems': false,
|
||||
'skipEmptyValues': false
|
||||
},
|
||||
'table': {
|
||||
'skipEmptyValues': false
|
||||
}
|
||||
};
|
||||
_.defaults(target, targetDefaults);
|
||||
@@ -367,7 +371,8 @@ System.register(['app/plugins/sdk', 'lodash', './constants', './utils', './metri
|
||||
key: 'renderQueryOptionsText',
|
||||
value: function renderQueryOptionsText() {
|
||||
var optionsMap = {
|
||||
showDisabledItems: "Show disabled items"
|
||||
showDisabledItems: "Show disabled items",
|
||||
skipEmptyValues: "Skip empty values"
|
||||
};
|
||||
var options = [];
|
||||
_.forOwn(this.target.options, function (value, key) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
4
dist/datasource-zabbix/responseHandler.js
vendored
4
dist/datasource-zabbix/responseHandler.js
vendored
@@ -85,6 +85,10 @@ System.register(['lodash', 'app/core/table_model', './constants'], function (_ex
|
||||
var lastPoint = _.last(itemHistory);
|
||||
var lastValue = lastPoint ? lastPoint.value : null;
|
||||
|
||||
if (target.options.skipEmptyValues && (!lastValue || lastValue === '')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||
|
||||
File diff suppressed because one or more lines are too long
32
dist/datasource-zabbix/specs/datasource.spec.js
vendored
32
dist/datasource-zabbix/specs/datasource.spec.js
vendored
@@ -126,7 +126,10 @@ describe('ZabbixDatasource', () => {
|
||||
textFilter: "",
|
||||
useCaptureGroups: true,
|
||||
mode: 2,
|
||||
resultFormat: "table"
|
||||
resultFormat: "table",
|
||||
options: {
|
||||
skipEmptyValues: false
|
||||
}
|
||||
}
|
||||
],
|
||||
};
|
||||
@@ -155,6 +158,33 @@ describe('ZabbixDatasource', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip item when last value is empty', () => {
|
||||
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve([
|
||||
{
|
||||
hosts: [{hostid: "10001", name: "Zabbix server"}],
|
||||
itemid: "10100", name: "System information", key_: "system.uname"
|
||||
},
|
||||
{
|
||||
hosts: [{hostid: "10002", name: "Server02"}],
|
||||
itemid: "90109", name: "System information", key_: "system.uname"
|
||||
}
|
||||
]));
|
||||
|
||||
ctx.options.targets[0].options.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', () => {
|
||||
|
||||
@@ -163,12 +163,19 @@
|
||||
<!-- Query options -->
|
||||
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
|
||||
<div class="gf-form offset-width-7" ng-hide="ctrl.target.mode == editorMode.TRIGGERS">
|
||||
<gf-form-switch class="gf-form"
|
||||
<gf-form-switch class="gf-form" label-class="width-10"
|
||||
label="Show disabled items"
|
||||
checked="ctrl.target.options.showDisabledItems"
|
||||
on-change="ctrl.onQueryOptionChange()">
|
||||
</gf-form-switch>
|
||||
</div>
|
||||
<div class="gf-form offset-width-7" ng-show="ctrl.target.mode === editorMode.TEXT && ctrl.target.resultFormat === 'table'">
|
||||
<gf-form-switch class="gf-form" label-class="width-10"
|
||||
label="Skip empty values"
|
||||
checked="ctrl.target.options.skipEmptyValues"
|
||||
on-change="ctrl.onQueryOptionChange()">
|
||||
</gf-form-switch>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Item IDs editor mode -->
|
||||
|
||||
@@ -96,7 +96,11 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
'acknowledged': 2
|
||||
},
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
'showDisabledItems': false,
|
||||
'skipEmptyValues': false
|
||||
},
|
||||
'table': {
|
||||
'skipEmptyValues': false
|
||||
}
|
||||
};
|
||||
_.defaults(target, targetDefaults);
|
||||
@@ -298,7 +302,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
|
||||
renderQueryOptionsText() {
|
||||
var optionsMap = {
|
||||
showDisabledItems: "Show disabled items"
|
||||
showDisabledItems: "Show disabled items",
|
||||
skipEmptyValues: "Skip empty values"
|
||||
};
|
||||
var options = [];
|
||||
_.forOwn(this.target.options, (value, key) => {
|
||||
|
||||
@@ -67,6 +67,10 @@ function handleHistoryAsTable(history, items, target) {
|
||||
let lastPoint = _.last(itemHistory);
|
||||
let lastValue = lastPoint ? lastPoint.value : null;
|
||||
|
||||
if(target.options.skipEmptyValues && (!lastValue || lastValue === '')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Regex-based extractor
|
||||
if (target.textFilter) {
|
||||
lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);
|
||||
|
||||
@@ -126,7 +126,10 @@ describe('ZabbixDatasource', () => {
|
||||
textFilter: "",
|
||||
useCaptureGroups: true,
|
||||
mode: 2,
|
||||
resultFormat: "table"
|
||||
resultFormat: "table",
|
||||
options: {
|
||||
skipEmptyValues: false
|
||||
}
|
||||
}
|
||||
],
|
||||
};
|
||||
@@ -155,6 +158,33 @@ describe('ZabbixDatasource', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should skip item when last value is empty', () => {
|
||||
ctx.ds.zabbix.getItemsFromTarget = jest.fn().mockReturnValue(Promise.resolve([
|
||||
{
|
||||
hosts: [{hostid: "10001", name: "Zabbix server"}],
|
||||
itemid: "10100", name: "System information", key_: "system.uname"
|
||||
},
|
||||
{
|
||||
hosts: [{hostid: "10002", name: "Server02"}],
|
||||
itemid: "90109", name: "System information", key_: "system.uname"
|
||||
}
|
||||
]));
|
||||
|
||||
ctx.options.targets[0].options.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', () => {
|
||||
|
||||
Reference in New Issue
Block a user