From 4fca46ef6a91539463be0650ed3253e840db2ce9 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 11 Jun 2015 01:35:59 +0300 Subject: [PATCH 1/5] Add acknowledges to annotations. Add wildcards to triggers search. --- zabbix/datasource.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index d5f601f3c..577368bd9 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' }; return self.performZabbixAPIRequest('event.get', params) .then(function (result) { var events = []; _.each(result, function(e) { + var formatted_acknowledges = '\n'; + var acknowledges = _.each(_.map(e.acknowledges, function (ack) { + return ack.name + ' ' + ack.surname + '(' + ack.alias + '): ' + ack.message; + }), function (ack) { + formatted_acknowledges = formatted_acknowledges.concat(ack, '\n') + }); 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 + (acknowledges.length ? formatted_acknowledges : ''), }); }); return events; From c3bf7d038dd1ac8936fac314bfb6188a08847fed Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 11 Jun 2015 11:01:01 +0300 Subject: [PATCH 2/5] Add zabbix acknowledges to annotations. --- zabbix/datasource.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 577368bd9..23004fb24 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -637,12 +637,13 @@ function (angular, _, kbn) { .then(function (result) { var events = []; _.each(result, function(e) { - var formatted_acknowledges = '\n'; + var formatted_acknowledges = '
'; var acknowledges = _.each(_.map(e.acknowledges, function (ack) { - return ack.name + ' ' + ack.surname + '(' + ack.alias + '): ' + ack.message; + return '' + ack.name + ' ' + ack.surname + ' (' + ack.alias + '): ' + ack.message; }), function (ack) { - formatted_acknowledges = formatted_acknowledges.concat(ack, '\n') + formatted_acknowledges = formatted_acknowledges.concat(ack, '
') }); + events.push({ annotation: annotation, time: e.clock * 1000, From 015cb875fae3d81f1202c4abba5f7a35073e3a55 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 11 Jun 2015 13:19:04 +0300 Subject: [PATCH 3/5] Format acknowledges as table. --- zabbix/datasource.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 23004fb24..cb047532a 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -637,12 +637,13 @@ function (angular, _, kbn) { .then(function (result) { var events = []; _.each(result, function(e) { - var formatted_acknowledges = '
'; + var formatted_acknowledges = "

Acknowledges:
"; var acknowledges = _.each(_.map(e.acknowledges, function (ack) { - return '' + ack.name + ' ' + ack.surname + ' (' + ack.alias + '): ' + ack.message; + return ''; }), function (ack) { - formatted_acknowledges = formatted_acknowledges.concat(ack, '
') + formatted_acknowledges = formatted_acknowledges.concat(ack) }); + formatted_acknowledges = formatted_acknowledges.concat('
TimeUserMessage
' + ack.clock + '' + ack.name + ' ' + ack.surname + ' (' + ack.alias + ')' + '' + ack.message + '
') events.push({ annotation: annotation, From ad32942b8a1af898523807f1ae253b9fd35a1f3c Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 11 Jun 2015 14:22:10 +0300 Subject: [PATCH 4/5] Add time to acknowledges. --- zabbix/datasource.js | 47 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index cb047532a..283295e42 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -637,19 +637,12 @@ function (angular, _, kbn) { .then(function (result) { var events = []; _.each(result, function(e) { - var formatted_acknowledges = "

Acknowledges:
"; - var acknowledges = _.each(_.map(e.acknowledges, function (ack) { - return ''; - }), function (ack) { - formatted_acknowledges = formatted_acknowledges.concat(ack) - }); - formatted_acknowledges = formatted_acknowledges.concat('
TimeUserMessage
' + ack.clock + '' + ack.name + ' ' + ack.surname + ' (' + ack.alias + ')' + '' + ack.message + '
') - + var formatted_acknowledges = formatAcknowledges(e.acknowledges);; events.push({ annotation: annotation, time: e.clock * 1000, title: Number(e.value) ? 'Problem' : 'OK', - text: objects[e.objectid].description + (acknowledges.length ? formatted_acknowledges : ''), + text: objects[e.objectid].description + formatted_acknowledges, }); }); return events; @@ -699,4 +692,38 @@ 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; +} + + +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 From 33bf0c38e737b9196131cf23efaedf3040d6ad62 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Thu, 11 Jun 2015 18:21:56 +0300 Subject: [PATCH 5/5] Add Show OK events option. --- zabbix/datasource.js | 13 ++++++++++++- zabbix/partials/annotations.editor.html | 10 +++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 283295e42..ff249c490 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -633,6 +633,11 @@ function (angular, _, kbn) { select_acknowledges: 'extend' }; + // Show problem events only + if (!annotation.showOkEvents) { + params.value = 1; + } + return self.performZabbixAPIRequest('event.get', params) .then(function (result) { var events = []; @@ -712,9 +717,15 @@ function getShortTime(date) { } +/** + * 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:
'; + var formatted_acknowledges = '

Acknowledges:
TimeUserComments
'; _.each(_.map(acknowledges, function (ack) { var time = new Date(ack.clock * 1000); return ''; diff --git a/zabbix/partials/annotations.editor.html b/zabbix/partials/annotations.editor.html index eb65f53a8..1ca3d78a8 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
+ + +
+
TimeUserComments
' + getShortTime(time) + '' + ack.alias + ' (' + ack.name+ ' ' + ack.surname + ')' + '' + ack.message + '