diff --git a/zabbix/datasource.js b/zabbix/datasource.js index d5f601f..ff249c4 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -617,31 +617,37 @@ function (angular, _, kbn) { search: { 'description': annotation.query }, + searchWildcardsEnabled: true, + expandDescription: true }; return this.performZabbixAPIRequest('trigger.get', params) .then(function (result) { if(result) { - var obs = {}; - obs = _.indexBy(result, 'triggerid'); - + var objects = _.indexBy(result, 'triggerid'); var params = { output: 'extend', - sortorder: 'DESC', time_from: from, time_till: to, - objectids: _.keys(obs) + objectids: _.keys(objects), + select_acknowledges: 'extend' }; + // Show problem events only + if (!annotation.showOkEvents) { + params.value = 1; + } + return self.performZabbixAPIRequest('event.get', params) .then(function (result) { var events = []; _.each(result, function(e) { + var formatted_acknowledges = formatAcknowledges(e.acknowledges);; events.push({ annotation: annotation, time: e.clock * 1000, - title: obs[e.objectid].description, - text: e.eventid, + title: Number(e.value) ? 'Problem' : 'OK', + text: objects[e.objectid].description + formatted_acknowledges, }); }); return events; @@ -691,4 +697,44 @@ function expandItemName(item) { name = name.replace('$' + i, key_params[i - 1]); }; return name; -}; \ No newline at end of file +} + + +/** + * Convert Date object to local time in format + * YYYY-MM-DD HH:mm:ss + * + * @param {Date} date Date object + * @return {string} formatted local time YYYY-MM-DD HH:mm:ss + */ +function getShortTime(date) { + var MM = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth(); + var DD = date.getDate() < 10 ? '0' + date.getDate() : date.getDate(); + var HH = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(); + var mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(); + var ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(); + return date.getFullYear() + '-' + MM + '-' + DD + ' ' + HH + ':' + mm + ':' + ss; +} + + +/** + * Format acknowledges. + * + * @param {array} acknowledges array of Zabbix acknowledge objects + * @return {string} HTML-formatted table + */ +function formatAcknowledges(acknowledges) { + if (acknowledges.length) { + var formatted_acknowledges = '

Acknowledges:
'; + _.each(_.map(acknowledges, function (ack) { + var time = new Date(ack.clock * 1000); + return ''; + }), function (ack) { + formatted_acknowledges = formatted_acknowledges.concat(ack) + }); + formatted_acknowledges = formatted_acknowledges.concat('
TimeUserComments
' + getShortTime(time) + '' + ack.alias + ' (' + ack.name+ ' ' + ack.surname + ')' + '' + ack.message + '
') + return formatted_acknowledges; + } else { + return ''; + } +} \ No newline at end of file diff --git a/zabbix/partials/annotations.editor.html b/zabbix/partials/annotations.editor.html index eb65f53..1ca3d78 100644 --- a/zabbix/partials/annotations.editor.html +++ b/zabbix/partials/annotations.editor.html @@ -2,7 +2,15 @@
Zabbix trigger Example: Lack of free swap space
- +
+ +
+
+
Options
+ + +
+