Fixed annotations.

This commit is contained in:
Alexander Zobnin
2016-02-04 19:49:21 +03:00
parent 37ecf1bb14
commit 4bcf741d66
4 changed files with 129 additions and 92 deletions

View File

@@ -344,75 +344,76 @@ function (angular, _, dateMath, utils, metricFunctions) {
var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
var annotation = options.annotation;
var self = this;
var showEvents = annotation.showOkEvents ? [0, 1] : 1;
// Remove events below the chose severity
var severities = [];
for (var i = 5; i >= annotation.minseverity; i--) {
severities.push(i);
}
var params = {
output: ['triggerid', 'description', 'priority'],
preservekeys: 1,
filter: { 'priority': severities },
search: {
'description': annotation.trigger
},
searchWildcardsEnabled: true,
expandDescription: true
};
if (annotation.host) {
params.host = templateSrv.replace(annotation.host);
}
else if (annotation.group) {
params.group = templateSrv.replace(annotation.group);
}
var buildQuery = self.queryProcessor.buildTriggerQuery(templateSrv.replace(annotation.group),
templateSrv.replace(annotation.host),
templateSrv.replace(annotation.application));
return buildQuery.then(function(query) {
return self.zabbixAPI.getTriggers(query.groupids,
query.hostids,
query.applicationids,
showEvents)
.then(function(triggers) {
return this.zabbixAPI.performZabbixAPIRequest('trigger.get', params)
.then(function (result) {
if(result) {
var objects = result;
// Filter triggers by description
if (utils.isRegex(annotation.trigger)) {
triggers = _.filter(triggers, function(trigger) {
return utils.buildRegex(annotation.trigger).test(trigger.description);
});
} else {
triggers = _.filter(triggers, function(trigger) {
return trigger.description === annotation.trigger;
});
}
// Remove events below the chose severity
triggers = _.filter(triggers, function(trigger) {
return Number(trigger.priority) >= Number(annotation.minseverity);
});
var objectids = _.map(triggers, 'triggerid');
var params = {
output: 'extend',
time_from: from,
time_till: to,
objectids: _.keys(objects),
objectids: objectids,
select_acknowledges: 'extend',
selectHosts: 'extend'
selectHosts: 'extend',
value: showEvents
};
// Show problem events only
if (!annotation.showOkEvents) {
params.value = 1;
}
return self.zabbixAPI.request('event.get', params)
.then(function (events) {
var indexedTriggers = _.indexBy(triggers, 'triggerid');
return self.zabbixAPI.performZabbixAPIRequest('event.get', params)
.then(function (result) {
var events = [];
// Hide acknowledged events if option enabled
if (annotation.hideAcknowledged) {
events = _.filter(events, function(event) {
return !event.acknowledges.length;
});
}
_.each(result, function(e) {
return _.map(events, function(e) {
var title ='';
if (annotation.showHostname) {
title += e.hosts[0].name + ': ';
}
// Show event type (OK or Problem)
title += Number(e.value) ? 'Problem' : 'OK';
// Hide acknowledged events
if (e.acknowledges.length > 0 && annotation.showAcknowledged) { return; }
var formatted_acknowledges = zabbixHelperSrv.formatAcknowledges(e.acknowledges);
events.push({
var formatted_acknowledges = utils.formatAcknowledges(e.acknowledges);
return {
annotation: annotation,
time: e.clock * 1000,
title: title,
text: objects[e.objectid].description + formatted_acknowledges
});
text: indexedTriggers[e.objectid].description + formatted_acknowledges
};
});
return events;
});
} else {
return [];
}
});
});
});
};
}

View File

@@ -1,53 +1,61 @@
<div class="editor-row">
<div class="section">
<h5>Zabbix trigger
</h5>
</div>
</div>
<div class="editor-row">
<div class="editor-option">
<label class="small">Group</label>
<input type="text" class="input-medium" ng-model='currentAnnotation.group'></input>
</div>
<div class="editor-option">
<label class="small">Host</label>
<input type="text" class="input-medium" ng-model='currentAnnotation.host'></input>
</div>
<div class="editor-option">
<label class="small">Trigger
<tip>Trigger name for search. Wildcards are supports. Examples: Lack of free swap space, Lack of*.
</tip>
</label>
<input type="text" style="width: 25em" ng-model='currentAnnotation.trigger' placeholder="Trigger name"></input>
</div>
<div class="editor-option">
<label class="small">Minimum severity
</label>
<select class="small" style="width: 113px" ng-init='currentAnnotation.minseverity = currentAnnotation.minseverity || 0' ng-model='currentAnnotation.minseverity' ng-options="v as k for (k, v) in {'Not classified': 0, 'Information': 1, 'Warning': 2, 'Average': 3, 'High': 4, 'Disaster': 5}" ng-change="render()"></select>
<div class="section tight-form-container" style="margin-bottom: 20px">
<h5>Filter Triggers</h5>
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 80px">
Group
</li>
<li>
<input type="text"
ng-model="annotation.group"
class="input-large tight-form-input">
</li>
<li class="tight-form-item" style="width: 50px">
Host
</li>
<li>
<input type="text"
ng-model="annotation.host"
class="input-large tight-form-input last">
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 80px">
Application
</li>
<li>
<input type="text"
ng-model="annotation.application"
class="input-large tight-form-input">
</li>
<li class="tight-form-item" style="width: 50px">
Trigger
</li>
<li>
<input type="text"
ng-model="annotation.trigger"
class="input-large tight-form-input last">
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="editor-row">
<div class="section">
<h5>Options</h5>
<input type="checkbox" class="cr1" id="currentAnnotation.showOkEvents"
ng-model="currentAnnotation.showOkEvents"
ng-checked="currentAnnotation.showOkEvents">
<label for="currentAnnotation.showOkEvents" class="cr1">Show OK events
<tip>Show events, generated when trigger release to OK state</tip>
</label>
<input type="checkbox" class="cr1" id="currentAnnotation.showHostname"
ng-model="currentAnnotation.showHostname"
ng-checked="currentAnnotation.showHostname">
<label for="currentAnnotation.showHostname" class="cr1">Show hostname
<tip>Show the hostname the event belongs to</tip>
</label>
<input type="checkbox" class="cr1" id="currentAnnotation.showAcknowledged"
ng-model="currentAnnotation.showAcknowledged"
ng-checked="currentAnnotation.showAcknowledged">
<label for="currentAnnotation.showAcknowledged" class="cr1">Hide acknowledged events
<tip>Hide events, that have been acknowledged</tip>
</label>
<div class="editor-option">
<label class="small">Minimum severity
</label>
<select class="small" style="width: 113px" ng-init='annotation.minseverity = annotation.minseverity || 0' ng-model='annotation.minseverity' ng-options="v as k for (k, v) in {'Not classified': 0, 'Information': 1, 'Warning': 2, 'Average': 3, 'High': 4, 'Disaster': 5}" ng-change="render()"></select>
</div>
<editor-opt-bool text="Show OK events" model="annotation.showOkEvents"></editor-opt-bool>
<editor-opt-bool text="Hide acknowledged events" model="annotation.hideAcknowledged"></editor-opt-bool>
<editor-opt-bool text="Show hostname" model="annotation.showHostname"></editor-opt-bool>
</div>
</div>

View File

@@ -47,6 +47,30 @@ function (_, moment) {
return moment.duration(Number(momentInterval[1]), momentInterval[2]).valueOf();
};
/**
* Format acknowledges.
*
* @param {array} acknowledges array of Zabbix acknowledge objects
* @return {string} HTML-formatted table
*/
this.formatAcknowledges = function(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 timestamp = moment.unix(ack.clock);
return '<tr><td><i>' + timestamp.format("DD MMM YYYY HH:mm:ss") + '</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 '';
}
};
}
return new Utils();

View File

@@ -308,7 +308,7 @@ function (angular, _) {
skipDependent: true,
//only_true: true,
filter: {
value: showEvents
value: 1
},
selectGroups: ['name'],
selectHosts: ['name'],
@@ -316,6 +316,10 @@ function (angular, _) {
selectLastEvent: 'extend'
};
if (showEvents) {
params.filter.value = showEvents;
}
return this.request('trigger.get', params);
};