diff --git a/dist/datasource-zabbix/partials/query.editor.html b/dist/datasource-zabbix/partials/query.editor.html
index 886ee0551..de976ae9c 100644
--- a/dist/datasource-zabbix/partials/query.editor.html
+++ b/dist/datasource-zabbix/partials/query.editor.html
@@ -163,12 +163,19 @@
diff --git a/dist/datasource-zabbix/query.controller.js b/dist/datasource-zabbix/query.controller.js
index 6023a4e35..6f1880c14 100644
--- a/dist/datasource-zabbix/query.controller.js
+++ b/dist/datasource-zabbix/query.controller.js
@@ -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) {
diff --git a/dist/datasource-zabbix/query.controller.js.map b/dist/datasource-zabbix/query.controller.js.map
index e39b3167c..2b80eb0fa 100644
--- a/dist/datasource-zabbix/query.controller.js.map
+++ b/dist/datasource-zabbix/query.controller.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../../src/datasource-zabbix/query.controller.js"],"names":["QueryCtrl","_","c","utils","metricFunctions","migrations","ZabbixQueryController","$scope","$injector","$rootScope","$sce","templateSrv","zabbix","datasource","replaceTemplateVars","editorModes","value","text","mode","MODE_METRICS","MODE_TEXT","MODE_ITSERVICE","MODE_ITEMID","MODE_TRIGGERS","editorMode","METRICS","TEXT","ITSERVICE","ITEMID","TRIGGERS","slaPropertyList","name","property","ackFilters","resultFormats","triggerSeverity","TRIGGER_SEVERITY","getGroupNames","bind","getMetricNames","getHostNames","getApplicationNames","getItemNames","getITServices","getVariables","getTemplateVariables","$on","onVariableChange","onTargetBlur","init","target","migrate","scopeDefaults","metric","oldTarget","cloneDeep","queryOptionsText","renderQueryOptionsText","defaults","targetDefaults","functions","map","func","createFuncInstance","def","params","initFilters","slaProperty","suggestITServices","itemtype","find","Promise","all","suggestGroups","suggestHosts","suggestApps","suggestItems","metricList","addAllValue","metrics","uniq","forEach","variables","unshift","variable","getAllGroups","then","groupList","groups","groupFilter","group","filter","getAllHosts","hostList","hosts","hostFilter","host","getAllApps","appList","apps","appFilter","application","options","showDisabledItems","getAllItems","itemList","items","getITService","itServiceList","itservices","str","isRegex","isTemplateVariable","newTarget","isEqual","targetChanged","isContainsVariables","some","field","parseTarget","panelCtrl","refresh","funcDef","newFunc","added","push","moveAliasFuncLast","length","without","aliasFunc","showQueryOptions","optionsMap","forOwn","key","join","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAQA,e,kBAAAA,S;;AACDC,O;;AACKC,O;;AACAC,W;;AACAC,qB;;AACAC,gB;;;;;;;;;;;;;;;;;;;;;uCAKCC,qB;;;AAEX;AACA,uCAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,UAA/B,EAA2CC,IAA3C,EAAiDC,WAAjD,EAA8D;AAAA;;AAAA,oJACtDJ,MADsD,EAC9CC,SAD8C;;AAE5D,gBAAKI,MAAL,GAAc,MAAKC,UAAL,CAAgBD,MAA9B;;AAEA;AACA,gBAAKE,mBAAL,GAA2B,MAAKD,UAAL,CAAgBC,mBAA3C;AACA,gBAAKH,WAAL,GAAmBA,WAAnB;;AAEA,gBAAKI,WAAL,GAAmB,CACjB,EAACC,OAAO,KAAR,EAAqBC,MAAM,SAA3B,EAA0CC,MAAMhB,EAAEiB,YAAlD,EADiB,EAEjB,EAACH,OAAO,MAAR,EAAqBC,MAAM,MAA3B,EAA0CC,MAAMhB,EAAEkB,SAAlD,EAFiB,EAGjB,EAACJ,OAAO,WAAR,EAAqBC,MAAM,aAA3B,EAA0CC,M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AAL,CAAYhC,IAAZ,GAAmBA,IAAnB;AACA,iBAAK+B,IAAL;AACA,iBAAKkE,aAAL;AACD;;;;QA9TwCnH,S;;;;AAiU3C;AACAM,4BAAsBiI,WAAtB,GAAoC,8CAApC","file":"query.controller.js","sourcesContent":["import {QueryCtrl} from 'app/plugins/sdk';\nimport _ from 'lodash';\nimport * as c from './constants';\nimport * as utils from './utils';\nimport * as metricFunctions from './metricFunctions';\nimport * as migrations from './migrations';\n\nimport './add-metric-function.directive';\nimport './metric-function-editor.directive';\n\nexport class ZabbixQueryController extends QueryCtrl {\n\n // ZabbixQueryCtrl constructor\n constructor($scope, $injector, $rootScope, $sce, templateSrv) {\n super($scope, $injector);\n this.zabbix = this.datasource.zabbix;\n\n // Use custom format for template variables\n this.replaceTemplateVars = this.datasource.replaceTemplateVars;\n this.templateSrv = templateSrv;\n\n this.editorModes = [\n {value: 'num', text: 'Metrics', mode: c.MODE_METRICS},\n {value: 'text', text: 'Text', mode: c.MODE_TEXT},\n {value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE},\n {value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID},\n {value: 'triggers', text: 'Triggers', mode: c.MODE_TRIGGERS}\n ];\n\n this.$scope.editorMode = {\n METRICS: c.MODE_METRICS,\n TEXT: c.MODE_TEXT,\n ITSERVICE: c.MODE_ITSERVICE,\n ITEMID: c.MODE_ITEMID,\n TRIGGERS: c.MODE_TRIGGERS\n };\n\n this.slaPropertyList = [\n {name: \"Status\", property: \"status\"},\n {name: \"SLA\", property: \"sla\"},\n {name: \"OK time\", property: \"okTime\"},\n {name: \"Problem time\", property: \"problemTime\"},\n {name: \"Down time\", property: \"downtimeTime\"}\n ];\n\n this.ackFilters = [\n {text: 'all triggers', value: 2},\n {text: 'unacknowledged', value: 0},\n {text: 'acknowledged', value: 1},\n ];\n\n this.resultFormats = [{ text: 'Time series', value: 'time_series' }, { text: 'Table', value: 'table' }];\n\n this.triggerSeverity = c.TRIGGER_SEVERITY;\n\n // Map functions for bs-typeahead\n this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');\n this.getHostNames = _.bind(this.getMetricNames, this, 'hostList', true);\n this.getApplicationNames = _.bind(this.getMetricNames, this, 'appList');\n this.getItemNames = _.bind(this.getMetricNames, this, 'itemList');\n this.getITServices = _.bind(this.getMetricNames, this, 'itServiceList');\n this.getVariables = _.bind(this.getTemplateVariables, this);\n\n // Update metric suggestion when template variable was changed\n $rootScope.$on('template-variable-value-updated', () => this.onVariableChange());\n\n // Update metrics when item selected from dropdown\n $scope.$on('typeahead-updated', () => {\n this.onTargetBlur();\n });\n\n this.init = function() {\n var target = this.target;\n\n // Migrate old targets\n target = migrations.migrate(target);\n\n var scopeDefaults = {\n metric: {},\n oldTarget: _.cloneDeep(this.target),\n queryOptionsText: this.renderQueryOptionsText()\n };\n _.defaults(this, scopeDefaults);\n\n // Load default values\n var targetDefaults = {\n 'mode': c.MODE_METRICS,\n 'group': { 'filter': \"\" },\n 'host': { 'filter': \"\" },\n 'application': { 'filter': \"\" },\n 'item': { 'filter': \"\" },\n 'functions': [],\n 'triggers': {\n 'count': true,\n 'minSeverity': 3,\n 'acknowledged': 2\n },\n 'options': {\n 'showDisabledItems': false\n }\n };\n _.defaults(target, targetDefaults);\n\n // Create function instances from saved JSON\n target.functions = _.map(target.functions, function(func) {\n return metricFunctions.createFuncInstance(func.def, func.params);\n });\n\n if (target.mode === c.MODE_METRICS ||\n target.mode === c.MODE_TEXT ||\n target.mode === c.MODE_TRIGGERS) {\n this.initFilters();\n }\n else if (target.mode === c.MODE_ITSERVICE) {\n _.defaults(target, {slaProperty: {name: \"SLA\", property: \"sla\"}});\n this.suggestITServices();\n }\n };\n\n this.init();\n this.queryOptionsText = this.renderQueryOptionsText();\n }\n\n initFilters() {\n let itemtype = _.find(this.editorModes, {'mode': this.target.mode});\n itemtype = itemtype ? itemtype.value : null;\n return Promise.all([\n this.suggestGroups(),\n this.suggestHosts(),\n this.suggestApps(),\n this.suggestItems(itemtype)\n ]);\n }\n\n // Get list of metric names for bs-typeahead directive\n getMetricNames(metricList, addAllValue) {\n let metrics = _.uniq(_.map(this.metric[metricList], 'name'));\n\n // Add template variables\n _.forEach(this.templateSrv.variables, variable => {\n metrics.unshift('$' + variable.name);\n });\n\n if (addAllValue) {\n metrics.unshift('/.*/');\n }\n\n return metrics;\n }\n\n getTemplateVariables() {\n return _.map(this.templateSrv.variables, variable => {\n return '$' + variable.name;\n });\n }\n\n suggestGroups() {\n return this.zabbix.getAllGroups()\n .then(groups => {\n this.metric.groupList = groups;\n return groups;\n });\n }\n\n suggestHosts() {\n let groupFilter = this.replaceTemplateVars(this.target.group.filter);\n return this.zabbix.getAllHosts(groupFilter)\n .then(hosts => {\n this.metric.hostList = hosts;\n return hosts;\n });\n }\n\n suggestApps() {\n let groupFilter = this.replaceTemplateVars(this.target.group.filter);\n let hostFilter = this.replaceTemplateVars(this.target.host.filter);\n return this.zabbix.getAllApps(groupFilter, hostFilter)\n .then(apps => {\n this.metric.appList = apps;\n return apps;\n });\n }\n\n suggestItems(itemtype = 'num') {\n let groupFilter = this.replaceTemplateVars(this.target.group.filter);\n let hostFilter = this.replaceTemplateVars(this.target.host.filter);\n let appFilter = this.replaceTemplateVars(this.target.application.filter);\n let options = {\n itemtype: itemtype,\n showDisabledItems: this.target.options.showDisabledItems\n };\n\n return this.zabbix\n .getAllItems(groupFilter, hostFilter, appFilter, options)\n .then(items => {\n this.metric.itemList = items;\n return items;\n });\n }\n\n suggestITServices() {\n return this.zabbix.getITService()\n .then(itservices => {\n this.metric.itServiceList = itservices;\n return itservices;\n });\n }\n\n isRegex(str) {\n return utils.isRegex(str);\n }\n\n isVariable(str) {\n return utils.isTemplateVariable(str, this.templateSrv.variables);\n }\n\n onTargetBlur() {\n var newTarget = _.cloneDeep(this.target);\n if (!_.isEqual(this.oldTarget, this.target)) {\n this.oldTarget = newTarget;\n this.targetChanged();\n }\n }\n\n onVariableChange() {\n if (this.isContainsVariables()) {\n this.targetChanged();\n }\n }\n\n /**\n * Check query for template variables\n */\n isContainsVariables() {\n return _.some(['group', 'host', 'application'], field => {\n if (this.target[field] && this.target[field].filter) {\n return utils.isTemplateVariable(this.target[field].filter, this.templateSrv.variables);\n } else {\n return false;\n }\n });\n }\n\n parseTarget() {\n // Parse target\n }\n\n // Validate target and set validation info\n validateTarget() {\n // validate\n }\n\n targetChanged() {\n this.initFilters();\n this.parseTarget();\n this.panelCtrl.refresh();\n }\n\n addFunction(funcDef) {\n var newFunc = metricFunctions.createFuncInstance(funcDef);\n newFunc.added = true;\n this.target.functions.push(newFunc);\n\n this.moveAliasFuncLast();\n\n if (newFunc.params.length && newFunc.added ||\n newFunc.def.params.length === 0) {\n this.targetChanged();\n }\n }\n\n removeFunction(func) {\n this.target.functions = _.without(this.target.functions, func);\n this.targetChanged();\n }\n\n moveAliasFuncLast() {\n var aliasFunc = _.find(this.target.functions, function(func) {\n return func.def.name === 'alias' ||\n func.def.name === 'aliasByNode' ||\n func.def.name === 'aliasByMetric';\n });\n\n if (aliasFunc) {\n this.target.functions = _.without(this.target.functions, aliasFunc);\n this.target.functions.push(aliasFunc);\n }\n }\n\n toggleQueryOptions() {\n this.showQueryOptions = !this.showQueryOptions;\n }\n\n onQueryOptionChange() {\n this.queryOptionsText = this.renderQueryOptionsText();\n this.onTargetBlur();\n }\n\n renderQueryOptionsText() {\n var optionsMap = {\n showDisabledItems: \"Show disabled items\"\n };\n var options = [];\n _.forOwn(this.target.options, (value, key) => {\n if (value) {\n if (value === true) {\n // Show only option name (if enabled) for boolean options\n options.push(optionsMap[key]);\n } else {\n // Show \"option = value\" for another options\n options.push(optionsMap[key] + \" = \" + value);\n }\n }\n });\n return \"Options: \" + options.join(', ');\n }\n\n /**\n * Switch query editor to specified mode.\n * Modes:\n * 0 - items\n * 1 - IT services\n * 2 - Text metrics\n */\n switchEditorMode(mode) {\n this.target.mode = mode;\n this.init();\n this.targetChanged();\n }\n}\n\n// Set templateUrl as static property\nZabbixQueryController.templateUrl = 'datasource-zabbix/partials/query.editor.html';\n"]}
\ No newline at end of file
+{"version":3,"sources":["../../src/datasource-zabbix/query.controller.js"],"names":["QueryCtrl","_","c","utils","metricFunctions","migrations","ZabbixQueryController","$scope","$injector","$rootScope","$sce","templateSrv","zabbix","datasource","replaceTemplateVars","editorModes","value","text","mode","MODE_METRICS","MODE_TEXT","MODE_ITSERVICE","MODE_ITEMID","MODE_TRIGGERS","editorMode","METRICS","TEXT","ITSERVICE","ITEMID","TRIGGERS","slaPropertyList","name","property","ackFilters","resultFormats","triggerSeverity","TRIGGER_SEVERITY","getGroupNames","bind","getMetricNames","getHostNames","getApplicationNames","getItemNames","getITServices","getVariables","getTemplateVariables","$on","onVariableChange","onTargetBlur","init","target","migrate","scopeDefaults","metric","oldTarget","cloneDeep","queryOptionsText","renderQueryOptionsText","defaults","targetDefaults","functions","map","func","createFuncInstance","def","params","initFilters","slaProperty","suggestITServices","itemtype","find","Promise","all","suggestGroups","suggestHosts","suggestApps","suggestItems","metricList","addAllValue","metrics","uniq","forEach","variables","unshift","variable","getAllGroups","then","groupList","groups","groupFilter","group","filter","getAllHosts","hostList","hosts","hostFilter","host","getAllApps","appList","apps","appFilter","application","options","showDisabledItems","getAllItems","itemList","items","getITService","itServiceList","itservices","str","isRegex","isTemplateVariable","newTarget","isEqual","targetChanged","isContainsVariables","some","field","parseTarget","panelCtrl","refresh","funcDef","newFunc","added","push","moveAliasFuncLast","length","without","aliasFunc","showQueryOptions","optionsMap","skipEmptyValues","forOwn","key","join","templateUrl"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAQA,e,kBAAAA,S;;AACDC,O;;AACKC,O;;AACAC,W;;AACAC,qB;;AACAC,gB;;;;;;;;;;;;;;;;;;;;;uCAKCC,qB;;;AAEX;AACA,uCAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,UAA/B,EAA2CC,IAA3C,EAAiDC,WAAjD,EAA8D;AAAA;;AAAA,oJACtDJ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B,gBAAImF,aAAa;AACf5B,iCAAmB,qBADJ;AAEf6B,+BAAiB;AAFF,aAAjB;AAIA,gBAAI9B,UAAU,EAAd;AACArG,cAAEoI,MAAF,CAAS,KAAKnF,MAAL,CAAYoD,OAArB,EAA8B,UAACtF,KAAD,EAAQsH,GAAR,EAAgB;AAC5C,kBAAItH,KAAJ,EAAW;AACT,oBAAIA,UAAU,IAAd,EAAoB;AAClB;AACAsF,0BAAQuB,IAAR,CAAaM,WAAWG,GAAX,CAAb;AACD,iBAHD,MAGO;AACL;AACAhC,0BAAQuB,IAAR,CAAaM,WAAWG,GAAX,IAAkB,KAAlB,GAA0BtH,KAAvC;AACD;AACF;AACF,aAVD;AAWA,mBAAO,cAAcsF,QAAQiC,IAAR,CAAa,IAAb,CAArB;AACD;;;2CASgBrH,I,EAAM;AACrB,iBAAKgC,MAAL,CAAYhC,IAAZ,GAAmBA,IAAnB;AACA,iBAAK+B,IAAL;AACA,iBAAKkE,aAAL;AACD;;;;QAnUwCnH,S;;;;AAsU3C;AACAM,4BAAsBkI,WAAtB,GAAoC,8CAApC","file":"query.controller.js","sourcesContent":["import {QueryCtrl} from 'app/plugins/sdk';\nimport _ from 'lodash';\nimport * as c from './constants';\nimport * as utils from './utils';\nimport * as metricFunctions from './metricFunctions';\nimport * as migrations from './migrations';\n\nimport './add-metric-function.directive';\nimport './metric-function-editor.directive';\n\nexport class ZabbixQueryController extends QueryCtrl {\n\n // ZabbixQueryCtrl constructor\n constructor($scope, $injector, $rootScope, $sce, templateSrv) {\n super($scope, $injector);\n this.zabbix = this.datasource.zabbix;\n\n // Use custom format for template variables\n this.replaceTemplateVars = this.datasource.replaceTemplateVars;\n this.templateSrv = templateSrv;\n\n this.editorModes = [\n {value: 'num', text: 'Metrics', mode: c.MODE_METRICS},\n {value: 'text', text: 'Text', mode: c.MODE_TEXT},\n {value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE},\n {value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID},\n {value: 'triggers', text: 'Triggers', mode: c.MODE_TRIGGERS}\n ];\n\n this.$scope.editorMode = {\n METRICS: c.MODE_METRICS,\n TEXT: c.MODE_TEXT,\n ITSERVICE: c.MODE_ITSERVICE,\n ITEMID: c.MODE_ITEMID,\n TRIGGERS: c.MODE_TRIGGERS\n };\n\n this.slaPropertyList = [\n {name: \"Status\", property: \"status\"},\n {name: \"SLA\", property: \"sla\"},\n {name: \"OK time\", property: \"okTime\"},\n {name: \"Problem time\", property: \"problemTime\"},\n {name: \"Down time\", property: \"downtimeTime\"}\n ];\n\n this.ackFilters = [\n {text: 'all triggers', value: 2},\n {text: 'unacknowledged', value: 0},\n {text: 'acknowledged', value: 1},\n ];\n\n this.resultFormats = [{ text: 'Time series', value: 'time_series' }, { text: 'Table', value: 'table' }];\n\n this.triggerSeverity = c.TRIGGER_SEVERITY;\n\n // Map functions for bs-typeahead\n this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');\n this.getHostNames = _.bind(this.getMetricNames, this, 'hostList', true);\n this.getApplicationNames = _.bind(this.getMetricNames, this, 'appList');\n this.getItemNames = _.bind(this.getMetricNames, this, 'itemList');\n this.getITServices = _.bind(this.getMetricNames, this, 'itServiceList');\n this.getVariables = _.bind(this.getTemplateVariables, this);\n\n // Update metric suggestion when template variable was changed\n $rootScope.$on('template-variable-value-updated', () => this.onVariableChange());\n\n // Update metrics when item selected from dropdown\n $scope.$on('typeahead-updated', () => {\n this.onTargetBlur();\n });\n\n this.init = function() {\n var target = this.target;\n\n // Migrate old targets\n target = migrations.migrate(target);\n\n var scopeDefaults = {\n metric: {},\n oldTarget: _.cloneDeep(this.target),\n queryOptionsText: this.renderQueryOptionsText()\n };\n _.defaults(this, scopeDefaults);\n\n // Load default values\n var targetDefaults = {\n 'mode': c.MODE_METRICS,\n 'group': { 'filter': \"\" },\n 'host': { 'filter': \"\" },\n 'application': { 'filter': \"\" },\n 'item': { 'filter': \"\" },\n 'functions': [],\n 'triggers': {\n 'count': true,\n 'minSeverity': 3,\n 'acknowledged': 2\n },\n 'options': {\n 'showDisabledItems': false,\n 'skipEmptyValues': false\n },\n 'table': {\n 'skipEmptyValues': false\n }\n };\n _.defaults(target, targetDefaults);\n\n // Create function instances from saved JSON\n target.functions = _.map(target.functions, function(func) {\n return metricFunctions.createFuncInstance(func.def, func.params);\n });\n\n if (target.mode === c.MODE_METRICS ||\n target.mode === c.MODE_TEXT ||\n target.mode === c.MODE_TRIGGERS) {\n this.initFilters();\n }\n else if (target.mode === c.MODE_ITSERVICE) {\n _.defaults(target, {slaProperty: {name: \"SLA\", property: \"sla\"}});\n this.suggestITServices();\n }\n };\n\n this.init();\n this.queryOptionsText = this.renderQueryOptionsText();\n }\n\n initFilters() {\n let itemtype = _.find(this.editorModes, {'mode': this.target.mode});\n itemtype = itemtype ? itemtype.value : null;\n return Promise.all([\n this.suggestGroups(),\n this.suggestHosts(),\n this.suggestApps(),\n this.suggestItems(itemtype)\n ]);\n }\n\n // Get list of metric names for bs-typeahead directive\n getMetricNames(metricList, addAllValue) {\n let metrics = _.uniq(_.map(this.metric[metricList], 'name'));\n\n // Add template variables\n _.forEach(this.templateSrv.variables, variable => {\n metrics.unshift('$' + variable.name);\n });\n\n if (addAllValue) {\n metrics.unshift('/.*/');\n }\n\n return metrics;\n }\n\n getTemplateVariables() {\n return _.map(this.templateSrv.variables, variable => {\n return '$' + variable.name;\n });\n }\n\n suggestGroups() {\n return this.zabbix.getAllGroups()\n .then(groups => {\n this.metric.groupList = groups;\n return groups;\n });\n }\n\n suggestHosts() {\n let groupFilter = this.replaceTemplateVars(this.target.group.filter);\n return this.zabbix.getAllHosts(groupFilter)\n .then(hosts => {\n this.metric.hostList = hosts;\n return hosts;\n });\n }\n\n suggestApps() {\n let groupFilter = this.replaceTemplateVars(this.target.group.filter);\n let hostFilter = this.replaceTemplateVars(this.target.host.filter);\n return this.zabbix.getAllApps(groupFilter, hostFilter)\n .then(apps => {\n this.metric.appList = apps;\n return apps;\n });\n }\n\n suggestItems(itemtype = 'num') {\n let groupFilter = this.replaceTemplateVars(this.target.group.filter);\n let hostFilter = this.replaceTemplateVars(this.target.host.filter);\n let appFilter = this.replaceTemplateVars(this.target.application.filter);\n let options = {\n itemtype: itemtype,\n showDisabledItems: this.target.options.showDisabledItems\n };\n\n return this.zabbix\n .getAllItems(groupFilter, hostFilter, appFilter, options)\n .then(items => {\n this.metric.itemList = items;\n return items;\n });\n }\n\n suggestITServices() {\n return this.zabbix.getITService()\n .then(itservices => {\n this.metric.itServiceList = itservices;\n return itservices;\n });\n }\n\n isRegex(str) {\n return utils.isRegex(str);\n }\n\n isVariable(str) {\n return utils.isTemplateVariable(str, this.templateSrv.variables);\n }\n\n onTargetBlur() {\n var newTarget = _.cloneDeep(this.target);\n if (!_.isEqual(this.oldTarget, this.target)) {\n this.oldTarget = newTarget;\n this.targetChanged();\n }\n }\n\n onVariableChange() {\n if (this.isContainsVariables()) {\n this.targetChanged();\n }\n }\n\n /**\n * Check query for template variables\n */\n isContainsVariables() {\n return _.some(['group', 'host', 'application'], field => {\n if (this.target[field] && this.target[field].filter) {\n return utils.isTemplateVariable(this.target[field].filter, this.templateSrv.variables);\n } else {\n return false;\n }\n });\n }\n\n parseTarget() {\n // Parse target\n }\n\n // Validate target and set validation info\n validateTarget() {\n // validate\n }\n\n targetChanged() {\n this.initFilters();\n this.parseTarget();\n this.panelCtrl.refresh();\n }\n\n addFunction(funcDef) {\n var newFunc = metricFunctions.createFuncInstance(funcDef);\n newFunc.added = true;\n this.target.functions.push(newFunc);\n\n this.moveAliasFuncLast();\n\n if (newFunc.params.length && newFunc.added ||\n newFunc.def.params.length === 0) {\n this.targetChanged();\n }\n }\n\n removeFunction(func) {\n this.target.functions = _.without(this.target.functions, func);\n this.targetChanged();\n }\n\n moveAliasFuncLast() {\n var aliasFunc = _.find(this.target.functions, function(func) {\n return func.def.name === 'alias' ||\n func.def.name === 'aliasByNode' ||\n func.def.name === 'aliasByMetric';\n });\n\n if (aliasFunc) {\n this.target.functions = _.without(this.target.functions, aliasFunc);\n this.target.functions.push(aliasFunc);\n }\n }\n\n toggleQueryOptions() {\n this.showQueryOptions = !this.showQueryOptions;\n }\n\n onQueryOptionChange() {\n this.queryOptionsText = this.renderQueryOptionsText();\n this.onTargetBlur();\n }\n\n renderQueryOptionsText() {\n var optionsMap = {\n showDisabledItems: \"Show disabled items\",\n skipEmptyValues: \"Skip empty values\"\n };\n var options = [];\n _.forOwn(this.target.options, (value, key) => {\n if (value) {\n if (value === true) {\n // Show only option name (if enabled) for boolean options\n options.push(optionsMap[key]);\n } else {\n // Show \"option = value\" for another options\n options.push(optionsMap[key] + \" = \" + value);\n }\n }\n });\n return \"Options: \" + options.join(', ');\n }\n\n /**\n * Switch query editor to specified mode.\n * Modes:\n * 0 - items\n * 1 - IT services\n * 2 - Text metrics\n */\n switchEditorMode(mode) {\n this.target.mode = mode;\n this.init();\n this.targetChanged();\n }\n}\n\n// Set templateUrl as static property\nZabbixQueryController.templateUrl = 'datasource-zabbix/partials/query.editor.html';\n"]}
\ No newline at end of file
diff --git a/dist/datasource-zabbix/responseHandler.js b/dist/datasource-zabbix/responseHandler.js
index d80bae1da..fad1d09d7 100644
--- a/dist/datasource-zabbix/responseHandler.js
+++ b/dist/datasource-zabbix/responseHandler.js
@@ -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);
diff --git a/dist/datasource-zabbix/responseHandler.js.map b/dist/datasource-zabbix/responseHandler.js.map
index 0475c4750..aad8c3e89 100644
--- a/dist/datasource-zabbix/responseHandler.js.map
+++ b/dist/datasource-zabbix/responseHandler.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../../src/datasource-zabbix/responseHandler.js"],"names":["convertHistory","history","items","addHostName","convertPointCallback","grouped_history","_","groupBy","hosts","uniqBy","flatten","map","hist","itemid","item","find","alias","name","keys","length","host","hostid","target","datapoints","handleHistory","convertHistoryPoint","handleTrends","valueType","partial","convertTrendPoint","handleText","convertTextCallback","convertText","handleHistoryAsTable","table","TableModel","addColumn","text","each","itemHistory","lastPoint","last","lastValue","value","textFilter","extractText","useCaptureGroups","first","rows","push","key_","point","clock","Math","round","ns","str","pattern","extractPattern","RegExp","extractedValue","exec","handleSLAResponse","itservice","slaProperty","slaObject","targetSLA","serviceid","sla","property","targetStatus","parseInt","status","to","from","handleTriggersResponse","triggers","timeRange","isNumber","stats","getTriggerStats","orderBy","c","TRIGGER_SEVERITY","severity","severity_stats","group","row","toPairs","s","concat","groups","uniq","flattenDeep","trigger","priority","Number","value_min","value_max","value_avg","value_sum","value_count"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;AASA,WAASA,cAAT,CAAwBC,OAAxB,EAAiCC,KAAjC,EAAwCC,WAAxC,EAAqDC,oBAArD,EAA2E;AACzE;;;;;;;;;;AAUA;AACA,QAAIC,kBAAkBC,EAAEC,OAAF,CAAUN,OAAV,EAAmB,QAAnB,CAAtB;AACA,QAAIO,QAAQF,EAAEG,MAAF,CAASH,EAAEI,OAAF,CAAUJ,EAAEK,GAAF,CAAMT,KAAN,EAAa,OAAb,CAAV,CAAT,EAA2C,QAA3C,CAAZ,CAbyE,CAaN;;AAEnE,WAAOI,EAAEK,GAAF,CAAMN,eAAN,EAAuB,UAASO,IAAT,EAAeC,MAAf,EAAuB;AACnD,UAAIC,OAAOR,EAAES,IAAF,CAAOb,KAAP,EAAc,EAAC,UAAUW,MAAX,EAAd,CAAX;AACA,UAAIG,QAAQF,KAAKG,IAAjB;AACA,UAAIX,EAAEY,IAAF,CAAOV,KAAP,EAAcW,MAAd,GAAuB,CAAvB,IAA4BhB,WAAhC,EAA6C;AAAI;AAC/C,YAAIiB,OAAOd,EAAES,IAAF,CAAOP,KAAP,E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AMb6B,2BAAmBA,iBANN;AAOba,gCAAwBA;AAPX,O;;AAUf;AACA,UAAI,CAACrE,EAAEG,MAAP,EAAe;AAACH,UAAEG,MAAF,GAAWH,EAAEsF,IAAb;AAAmB","file":"responseHandler.js","sourcesContent":["import _ from 'lodash';\nimport TableModel from 'app/core/table_model';\nimport * as c from './constants';\n\n/**\n * Convert Zabbix API history.get response to Grafana format\n *\n * @return {Array} Array of timeseries in Grafana format\n * {\n * target: \"Metric name\",\n * datapoints: [[, ], ...]\n * }\n */\nfunction convertHistory(history, items, addHostName, convertPointCallback) {\n /**\n * Response should be in the format:\n * data: [\n * {\n * target: \"Metric name\",\n * datapoints: [[, ], ...]\n * }, ...\n * ]\n */\n\n // Group history by itemid\n var grouped_history = _.groupBy(history, 'itemid');\n var hosts = _.uniqBy(_.flatten(_.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate\n\n return _.map(grouped_history, function(hist, itemid) {\n var item = _.find(items, {'itemid': itemid});\n var alias = item.name;\n if (_.keys(hosts).length > 1 && addHostName) { //only when actual multi hosts selected\n var host = _.find(hosts, {'hostid': item.hostid});\n alias = host.name + \": \" + alias;\n }\n return {\n target: alias,\n datapoints: _.map(hist, convertPointCallback)\n };\n });\n}\n\nfunction handleHistory(history, items, addHostName = true) {\n return convertHistory(history, items, addHostName, convertHistoryPoint);\n}\n\nfunction handleTrends(history, items, valueType, addHostName = true) {\n var convertPointCallback = _.partial(convertTrendPoint, valueType);\n return convertHistory(history, items, addHostName, convertPointCallback);\n}\n\nfunction handleText(history, items, target, addHostName = true) {\n let convertTextCallback = _.partial(convertText, target);\n return convertHistory(history, items, addHostName, convertTextCallback);\n}\n\nfunction handleHistoryAsTable(history, items, target) {\n let table = new TableModel();\n table.addColumn({text: 'Host'});\n table.addColumn({text: 'Item'});\n table.addColumn({text: 'Key'});\n table.addColumn({text: 'Last value'});\n\n let grouped_history = _.groupBy(history, 'itemid');\n _.each(items, (item) => {\n let itemHistory = grouped_history[item.itemid] || [];\n let lastPoint = _.last(itemHistory);\n let lastValue = lastPoint ? lastPoint.value : null;\n\n // Regex-based extractor\n if (target.textFilter) {\n lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);\n }\n\n let host = _.first(item.hosts);\n host = host ? host.name : \"\";\n\n table.rows.push([\n host, item.name, item.key_, lastValue\n ]);\n });\n\n return table;\n}\n\nfunction convertText(target, point) {\n let value = point.value;\n\n // Regex-based extractor\n if (target.textFilter) {\n value = extractText(point.value, target.textFilter, target.useCaptureGroups);\n }\n\n return [\n value,\n point.clock * 1000 + Math.round(point.ns / 1000000)\n ];\n}\n\nfunction extractText(str, pattern, useCaptureGroups) {\n let extractPattern = new RegExp(pattern);\n let extractedValue = extractPattern.exec(str);\n if (extractedValue) {\n if (useCaptureGroups) {\n extractedValue = extractedValue[1];\n } else {\n extractedValue = extractedValue[0];\n }\n }\n return extractedValue;\n}\n\nfunction handleSLAResponse(itservice, slaProperty, slaObject) {\n var targetSLA = slaObject[itservice.serviceid].sla[0];\n if (slaProperty.property === 'status') {\n var targetStatus = parseInt(slaObject[itservice.serviceid].status);\n return {\n target: itservice.name + ' ' + slaProperty.name,\n datapoints: [\n [targetStatus, targetSLA.to * 1000]\n ]\n };\n } else {\n return {\n target: itservice.name + ' ' + slaProperty.name,\n datapoints: [\n [targetSLA[slaProperty.property], targetSLA.from * 1000],\n [targetSLA[slaProperty.property], targetSLA.to * 1000]\n ]\n };\n }\n}\n\nfunction handleTriggersResponse(triggers, timeRange) {\n if (_.isNumber(triggers)) {\n return {\n target: \"triggers count\",\n datapoints: [\n [triggers, timeRange[1] * 1000]\n ]\n };\n } else {\n let stats = getTriggerStats(triggers);\n let table = new TableModel();\n table.addColumn({text: 'Host group'});\n _.each(_.orderBy(c.TRIGGER_SEVERITY, ['val'], ['desc']), (severity) => {\n table.addColumn({text: severity.text});\n });\n _.each(stats, (severity_stats, group) => {\n let row = _.map(_.orderBy(_.toPairs(severity_stats), (s) => s[0], ['desc']), (s) => s[1]);\n row = _.concat([group], ...row);\n table.rows.push(row);\n });\n return table;\n }\n}\n\nfunction getTriggerStats(triggers) {\n let groups = _.uniq(_.flattenDeep(_.map(triggers, (trigger) => _.map(trigger.groups, 'name'))));\n // let severity = _.map(c.TRIGGER_SEVERITY, 'text');\n let stats = {};\n _.each(groups, (group) => {\n stats[group] = {0:0, 1:0, 2:0, 3:0, 4:0, 5:0}; // severity:count\n });\n _.each(triggers, (trigger) => {\n _.each(trigger.groups, (group) => {\n stats[group.name][trigger.priority]++;\n });\n });\n return stats;\n}\n\nfunction convertHistoryPoint(point) {\n // Value must be a number for properly work\n return [\n Number(point.value),\n point.clock * 1000 + Math.round(point.ns / 1000000)\n ];\n}\n\nfunction convertTrendPoint(valueType, point) {\n var value;\n switch (valueType) {\n case \"min\":\n value = point.value_min;\n break;\n case \"max\":\n value = point.value_max;\n break;\n case \"avg\":\n value = point.value_avg;\n break;\n case \"sum\":\n value = point.value_sum;\n break;\n case \"count\":\n value = point.value_count;\n break;\n default:\n value = point.value_avg;\n }\n\n return [\n Number(value),\n point.clock * 1000\n ];\n}\n\nexport default {\n handleHistory: handleHistory,\n convertHistory: convertHistory,\n handleTrends: handleTrends,\n handleText: handleText,\n handleHistoryAsTable: handleHistoryAsTable,\n handleSLAResponse: handleSLAResponse,\n handleTriggersResponse: handleTriggersResponse\n};\n\n// Fix for backward compatibility with lodash 2.4\nif (!_.uniqBy) {_.uniqBy = _.uniq;}\n"]}
\ No newline at end of file
+{"version":3,"sources":["../../src/datasource-zabbix/responseHandler.js"],"names":["convertHistory","history","items","addHostName","convertPointCallback","grouped_history","_","groupBy","hosts","uniqBy","flatten","map","hist","itemid","item","find","alias","name","keys","length","host","hostid","target","datapoints","handleHistory","convertHistoryPoint","handleTrends","valueType","partial","convertTrendPoint","handleText","convertTextCallback","convertText","handleHistoryAsTable","table","TableModel","addColumn","text","each","itemHistory","lastPoint","last","lastValue","value","options","skipEmptyValues","textFilter","extractText","useCaptureGroups","first","rows","push","key_","point","clock","Math","round","ns","str","pattern","extractPattern","RegExp","extractedValue","exec","handleSLAResponse","itservice","slaProperty","slaObject","targetSLA","serviceid","sla","property","targetStatus","parseInt","status","to","from","handleTriggersResponse","triggers","timeRange","isNumber","stats","getTriggerStats","orderBy","c","TRIGGER_SEVERITY","severity","severity_stats","group","row","toPairs","s","concat","groups","uniq","flattenDeep","trigger","priority","Number","value_min","value_max","value_avg","value_sum","value_count"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;AASA,WAASA,cAAT,CAAwBC,OAAxB,EAAiCC,KAAjC,EAAwCC,WAAxC,EAAqDC,oBAArD,EAA2E;AACzE;;;;;;;;;;AAUA;AACA,QAAIC,kBAAkBC,EAAEC,OAAF,CAAUN,OAAV,EAAmB,QAAnB,CAAtB;AACA,QAAIO,QAAQF,EAAEG,MAAF,CAASH,EAAEI,OAAF,CAAUJ,EAAEK,GAAF,CAAMT,KAAN,EAAa,OAAb,CAAV,CAAT,EAA2C,QAA3C,CAAZ,CAbyE,CAaN;;AAEnE,WAAOI,EAAEK,GAAF,CAAMN,eAAN,EAAuB,UAASO,IAAT,EAAeC,MAAf,EAAuB;AACnD,UAAIC,OAAOR,EAAES,IAAF,CAAOb,KAAP,EAAc,EAAC,UAAUW,MAAX,EAAd,CAAX;AACA,UAAIG,QAAQF,KAAKG,IAAjB;AACA,UAAIX,EAAEY,IAAF,CAAOV,KAAP,EAAcW,MAAd,GAAuB,CAAvB,IAA4BhB,WAAhC,EAA6C;AAAI;AAC/C,YAAIiB,OAAOd,EAAES,IAAF,CAAOP,KAAP,EAAc,EAAC,UAAUM,KAAKO,MAAhB,EAAd,CAAX;AACAL,gBAAQI,KAAKH,IAAL,GAAY,IAAZ,GAAmBD,KAA3B;AACD;AACD,aAAO;AACLM,gBAAQN,KADH;AAELO,oBAAYjB,EAAEK,GAAF,CAAMC,IAAN,EAAYR,oBAAZ;AAFP,OAAP;AAID,KAXM,CAAP;AAYD;;AAED,WAASoB,aAAT,CAAuBvB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":["import _ from 'lodash';\nimport TableModel from 'app/core/table_model';\nimport * as c from './constants';\n\n/**\n * Convert Zabbix API history.get response to Grafana format\n *\n * @return {Array} Array of timeseries in Grafana format\n * {\n * target: \"Metric name\",\n * datapoints: [[, ], ...]\n * }\n */\nfunction convertHistory(history, items, addHostName, convertPointCallback) {\n /**\n * Response should be in the format:\n * data: [\n * {\n * target: \"Metric name\",\n * datapoints: [[, ], ...]\n * }, ...\n * ]\n */\n\n // Group history by itemid\n var grouped_history = _.groupBy(history, 'itemid');\n var hosts = _.uniqBy(_.flatten(_.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate\n\n return _.map(grouped_history, function(hist, itemid) {\n var item = _.find(items, {'itemid': itemid});\n var alias = item.name;\n if (_.keys(hosts).length > 1 && addHostName) { //only when actual multi hosts selected\n var host = _.find(hosts, {'hostid': item.hostid});\n alias = host.name + \": \" + alias;\n }\n return {\n target: alias,\n datapoints: _.map(hist, convertPointCallback)\n };\n });\n}\n\nfunction handleHistory(history, items, addHostName = true) {\n return convertHistory(history, items, addHostName, convertHistoryPoint);\n}\n\nfunction handleTrends(history, items, valueType, addHostName = true) {\n var convertPointCallback = _.partial(convertTrendPoint, valueType);\n return convertHistory(history, items, addHostName, convertPointCallback);\n}\n\nfunction handleText(history, items, target, addHostName = true) {\n let convertTextCallback = _.partial(convertText, target);\n return convertHistory(history, items, addHostName, convertTextCallback);\n}\n\nfunction handleHistoryAsTable(history, items, target) {\n let table = new TableModel();\n table.addColumn({text: 'Host'});\n table.addColumn({text: 'Item'});\n table.addColumn({text: 'Key'});\n table.addColumn({text: 'Last value'});\n\n let grouped_history = _.groupBy(history, 'itemid');\n _.each(items, (item) => {\n let itemHistory = grouped_history[item.itemid] || [];\n let lastPoint = _.last(itemHistory);\n let lastValue = lastPoint ? lastPoint.value : null;\n\n if(target.options.skipEmptyValues && (!lastValue || lastValue === '')) {\n return;\n }\n\n // Regex-based extractor\n if (target.textFilter) {\n lastValue = extractText(lastValue, target.textFilter, target.useCaptureGroups);\n }\n\n let host = _.first(item.hosts);\n host = host ? host.name : \"\";\n\n table.rows.push([\n host, item.name, item.key_, lastValue\n ]);\n });\n\n return table;\n}\n\nfunction convertText(target, point) {\n let value = point.value;\n\n // Regex-based extractor\n if (target.textFilter) {\n value = extractText(point.value, target.textFilter, target.useCaptureGroups);\n }\n\n return [\n value,\n point.clock * 1000 + Math.round(point.ns / 1000000)\n ];\n}\n\nfunction extractText(str, pattern, useCaptureGroups) {\n let extractPattern = new RegExp(pattern);\n let extractedValue = extractPattern.exec(str);\n if (extractedValue) {\n if (useCaptureGroups) {\n extractedValue = extractedValue[1];\n } else {\n extractedValue = extractedValue[0];\n }\n }\n return extractedValue;\n}\n\nfunction handleSLAResponse(itservice, slaProperty, slaObject) {\n var targetSLA = slaObject[itservice.serviceid].sla[0];\n if (slaProperty.property === 'status') {\n var targetStatus = parseInt(slaObject[itservice.serviceid].status);\n return {\n target: itservice.name + ' ' + slaProperty.name,\n datapoints: [\n [targetStatus, targetSLA.to * 1000]\n ]\n };\n } else {\n return {\n target: itservice.name + ' ' + slaProperty.name,\n datapoints: [\n [targetSLA[slaProperty.property], targetSLA.from * 1000],\n [targetSLA[slaProperty.property], targetSLA.to * 1000]\n ]\n };\n }\n}\n\nfunction handleTriggersResponse(triggers, timeRange) {\n if (_.isNumber(triggers)) {\n return {\n target: \"triggers count\",\n datapoints: [\n [triggers, timeRange[1] * 1000]\n ]\n };\n } else {\n let stats = getTriggerStats(triggers);\n let table = new TableModel();\n table.addColumn({text: 'Host group'});\n _.each(_.orderBy(c.TRIGGER_SEVERITY, ['val'], ['desc']), (severity) => {\n table.addColumn({text: severity.text});\n });\n _.each(stats, (severity_stats, group) => {\n let row = _.map(_.orderBy(_.toPairs(severity_stats), (s) => s[0], ['desc']), (s) => s[1]);\n row = _.concat([group], ...row);\n table.rows.push(row);\n });\n return table;\n }\n}\n\nfunction getTriggerStats(triggers) {\n let groups = _.uniq(_.flattenDeep(_.map(triggers, (trigger) => _.map(trigger.groups, 'name'))));\n // let severity = _.map(c.TRIGGER_SEVERITY, 'text');\n let stats = {};\n _.each(groups, (group) => {\n stats[group] = {0:0, 1:0, 2:0, 3:0, 4:0, 5:0}; // severity:count\n });\n _.each(triggers, (trigger) => {\n _.each(trigger.groups, (group) => {\n stats[group.name][trigger.priority]++;\n });\n });\n return stats;\n}\n\nfunction convertHistoryPoint(point) {\n // Value must be a number for properly work\n return [\n Number(point.value),\n point.clock * 1000 + Math.round(point.ns / 1000000)\n ];\n}\n\nfunction convertTrendPoint(valueType, point) {\n var value;\n switch (valueType) {\n case \"min\":\n value = point.value_min;\n break;\n case \"max\":\n value = point.value_max;\n break;\n case \"avg\":\n value = point.value_avg;\n break;\n case \"sum\":\n value = point.value_sum;\n break;\n case \"count\":\n value = point.value_count;\n break;\n default:\n value = point.value_avg;\n }\n\n return [\n Number(value),\n point.clock * 1000\n ];\n}\n\nexport default {\n handleHistory: handleHistory,\n convertHistory: convertHistory,\n handleTrends: handleTrends,\n handleText: handleText,\n handleHistoryAsTable: handleHistoryAsTable,\n handleSLAResponse: handleSLAResponse,\n handleTriggersResponse: handleTriggersResponse\n};\n\n// Fix for backward compatibility with lodash 2.4\nif (!_.uniqBy) {_.uniqBy = _.uniq;}\n"]}
\ No newline at end of file
diff --git a/dist/datasource-zabbix/specs/datasource.spec.js b/dist/datasource-zabbix/specs/datasource.spec.js
index 652b747e4..697c982b4 100644
--- a/dist/datasource-zabbix/specs/datasource.spec.js
+++ b/dist/datasource-zabbix/specs/datasource.spec.js
@@ -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', () => {
diff --git a/src/datasource-zabbix/partials/query.editor.html b/src/datasource-zabbix/partials/query.editor.html
index 886ee0551..de976ae9c 100644
--- a/src/datasource-zabbix/partials/query.editor.html
+++ b/src/datasource-zabbix/partials/query.editor.html
@@ -163,12 +163,19 @@
diff --git a/src/datasource-zabbix/query.controller.js b/src/datasource-zabbix/query.controller.js
index 0eb6a39d3..733fdd8a1 100644
--- a/src/datasource-zabbix/query.controller.js
+++ b/src/datasource-zabbix/query.controller.js
@@ -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) => {
diff --git a/src/datasource-zabbix/responseHandler.js b/src/datasource-zabbix/responseHandler.js
index 22e81fc3f..b46f6c90b 100644
--- a/src/datasource-zabbix/responseHandler.js
+++ b/src/datasource-zabbix/responseHandler.js
@@ -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);
diff --git a/src/datasource-zabbix/specs/datasource.spec.js b/src/datasource-zabbix/specs/datasource.spec.js
index 652b747e4..697c982b4 100644
--- a/src/datasource-zabbix/specs/datasource.spec.js
+++ b/src/datasource-zabbix/specs/datasource.spec.js
@@ -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', () => {