diff --git a/README.md b/README.md index f901771..5fe60de 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [](https://gitter.im/alexanderzobnin/grafana-zabbix?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +##### [Donate](https://www.paypal.me/alexanderzobnin) + ##### See features overview and dashboards examples at Grafana-Zabbix [Live demo](http://play.grafana-zabbix.org) site. ##### Download [latest release](https://github.com/alexanderzobnin/grafana-zabbix/releases/latest) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 447d827..93e81ca 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -336,52 +336,70 @@ function (angular, _, dateMath) { // Annotations // ///////////////// - ZabbixAPIDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) { - var from = Math.ceil(dateMath.parse(rangeUnparsed.from) / 1000); - var to = Math.ceil(dateMath.parse(rangeUnparsed.to) / 1000); + ZabbixAPIDatasource.prototype.annotationQuery = function(options) { + var from = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000); + var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000); var self = this; + // Remove events below the chose severity + var severities = []; + for (var i = 5; i >= options.annotation.minseverity; i--) { + severities.push(i); + } var params = { - output: ['triggerid', 'description'], + output: ['triggerid', 'description', 'priority'], + preservekeys: 1, + filter: { 'priority': severities }, search: { - 'description': annotation.trigger + 'description': options.annotation.trigger }, searchWildcardsEnabled: true, expandDescription: true }; - if (annotation.host) { - params.host = templateSrv.replace(annotation.host); + if (options.annotation.host) { + params.host = templateSrv.replace(options.annotation.host); } - else if (annotation.group) { - params.group = templateSrv.replace(annotation.group); + else if (options.annotation.group) { + params.group = templateSrv.replace(options.annotation.group); } return this.zabbixAPI.performZabbixAPIRequest('trigger.get', params) .then(function (result) { if(result) { - var objects = _.indexBy(result, 'triggerid'); + var objects = result; var params = { output: 'extend', time_from: from, time_till: to, objectids: _.keys(objects), - select_acknowledges: 'extend' + select_acknowledges: 'extend', + selectHosts: 'extend' }; // Show problem events only - if (!annotation.showOkEvents) { + if (!options.annotation.showOkEvents) { params.value = 1; } return self.zabbixAPI.performZabbixAPIRequest('event.get', params) .then(function (result) { var events = []; + + var title =''; + if (options.annotation.showHostname) { + title += e.hosts[0]['name'] + ': '; + } + title += Number(e.value) ? 'Problem' : 'OK'; + _.each(result, function(e) { + // Hide acknowledged events + if (e.acknowledges.length > 0 && options.annotation.showAcknowledged) { return; } + var formatted_acknowledges = zabbixHelperSrv.formatAcknowledges(e.acknowledges); events.push({ - annotation: annotation, + annotation: options.annotation, time: e.clock * 1000, - title: Number(e.value) ? 'Problem' : 'OK', + title: title, text: objects[e.objectid].description + formatted_acknowledges }); }); diff --git a/zabbix/partials/annotations.editor.html b/zabbix/partials/annotations.editor.html index 1a95b36..7dc8fb8 100644 --- a/zabbix/partials/annotations.editor.html +++ b/zabbix/partials/annotations.editor.html @@ -21,6 +21,11 @@ +