Skip to content

Commit

Permalink
Merge branch 'feature-annotations' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderzobnin committed Jun 11, 2015
2 parents 8eb9c58 + 33bf0c3 commit 17392c0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
62 changes: 54 additions & 8 deletions zabbix/datasource.js
Expand Up @@ -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;
Expand Down Expand Up @@ -691,4 +697,44 @@ function expandItemName(item) {
name = name.replace('$' + i, key_params[i - 1]);
};
return name;
};
}


/**
* 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 = '<br><br>Acknowledges:<br><table><tr><td><b>Time</b></td><td><b>User</b></td><td><b>Comments</b></td></tr>';
_.each(_.map(acknowledges, function (ack) {
var time = new Date(ack.clock * 1000);
return '<tr><td><i>' + getShortTime(time) + '</i></td><td>' + ack.alias + ' (' + ack.name+ ' ' + ack.surname + ')' + '</td><td>' + ack.message + '</td></tr>';
}), function (ack) {
formatted_acknowledges = formatted_acknowledges.concat(ack)
});
formatted_acknowledges = formatted_acknowledges.concat('</table>')
return formatted_acknowledges;
} else {
return '';
}
}
10 changes: 9 additions & 1 deletion zabbix/partials/annotations.editor.html
Expand Up @@ -2,7 +2,15 @@
<div class="section">
<h5>Zabbix trigger <tip>Example: Lack of free swap space</tip></h5>
<div class="editor-option">
<input type="text" class="span10" ng-model='currentAnnotation.query' placeholder="Lack of free swap space"></input>
<input type="text" class="span10" ng-model="currentAnnotation.query" placeholder="Lack of free swap space"></input>
</div>
</div>
</div>

<div class="editor-row">
<div class="section">
<h5>Options</h5>
<input type="checkbox" class="cr1" id="currentAnnotation.okEvents" ng-model="currentAnnotation.okEvents" ng-checked="currentAnnotation.okEvents">
<label for="currentAnnotation.okEvents" class="cr1">Show OK events <tip>Show events, generated when trigger release to OK state</tip></label>
</div>
</div>

0 comments on commit 17392c0

Please sign in to comment.