Fixed annotations.
This commit is contained in:
@@ -344,75 +344,76 @@ function (angular, _, dateMath, utils, metricFunctions) {
|
|||||||
var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
var to = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||||
var annotation = options.annotation;
|
var annotation = options.annotation;
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var showEvents = annotation.showOkEvents ? [0, 1] : 1;
|
||||||
|
|
||||||
// Remove events below the chose severity
|
var buildQuery = self.queryProcessor.buildTriggerQuery(templateSrv.replace(annotation.group),
|
||||||
var severities = [];
|
templateSrv.replace(annotation.host),
|
||||||
for (var i = 5; i >= annotation.minseverity; i--) {
|
templateSrv.replace(annotation.application));
|
||||||
severities.push(i);
|
return buildQuery.then(function(query) {
|
||||||
}
|
return self.zabbixAPI.getTriggers(query.groupids,
|
||||||
var params = {
|
query.hostids,
|
||||||
output: ['triggerid', 'description', 'priority'],
|
query.applicationids,
|
||||||
preservekeys: 1,
|
showEvents)
|
||||||
filter: { 'priority': severities },
|
.then(function(triggers) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.zabbixAPI.performZabbixAPIRequest('trigger.get', params)
|
// Filter triggers by description
|
||||||
.then(function (result) {
|
if (utils.isRegex(annotation.trigger)) {
|
||||||
if(result) {
|
triggers = _.filter(triggers, function(trigger) {
|
||||||
var objects = result;
|
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 = {
|
var params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
time_from: from,
|
time_from: from,
|
||||||
time_till: to,
|
time_till: to,
|
||||||
objectids: _.keys(objects),
|
objectids: objectids,
|
||||||
select_acknowledges: 'extend',
|
select_acknowledges: 'extend',
|
||||||
selectHosts: 'extend'
|
selectHosts: 'extend',
|
||||||
|
value: showEvents
|
||||||
};
|
};
|
||||||
|
|
||||||
// Show problem events only
|
return self.zabbixAPI.request('event.get', params)
|
||||||
if (!annotation.showOkEvents) {
|
.then(function (events) {
|
||||||
params.value = 1;
|
var indexedTriggers = _.indexBy(triggers, 'triggerid');
|
||||||
}
|
|
||||||
|
|
||||||
return self.zabbixAPI.performZabbixAPIRequest('event.get', params)
|
// Hide acknowledged events if option enabled
|
||||||
.then(function (result) {
|
if (annotation.hideAcknowledged) {
|
||||||
var events = [];
|
events = _.filter(events, function(event) {
|
||||||
|
return !event.acknowledges.length;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_.each(result, function(e) {
|
return _.map(events, function(e) {
|
||||||
var title ='';
|
var title ='';
|
||||||
if (annotation.showHostname) {
|
if (annotation.showHostname) {
|
||||||
title += e.hosts[0].name + ': ';
|
title += e.hosts[0].name + ': ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show event type (OK or Problem)
|
||||||
title += Number(e.value) ? 'Problem' : 'OK';
|
title += Number(e.value) ? 'Problem' : 'OK';
|
||||||
|
|
||||||
// Hide acknowledged events
|
var formatted_acknowledges = utils.formatAcknowledges(e.acknowledges);
|
||||||
if (e.acknowledges.length > 0 && annotation.showAcknowledged) { return; }
|
return {
|
||||||
|
|
||||||
var formatted_acknowledges = zabbixHelperSrv.formatAcknowledges(e.acknowledges);
|
|
||||||
events.push({
|
|
||||||
annotation: annotation,
|
annotation: annotation,
|
||||||
time: e.clock * 1000,
|
time: e.clock * 1000,
|
||||||
title: title,
|
title: title,
|
||||||
text: objects[e.objectid].description + formatted_acknowledges
|
text: indexedTriggers[e.objectid].description + formatted_acknowledges
|
||||||
});
|
};
|
||||||
});
|
});
|
||||||
return events;
|
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
return [];
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,61 @@
|
|||||||
<div class="editor-row">
|
<div class="editor-row">
|
||||||
<div class="section">
|
<div class="section tight-form-container" style="margin-bottom: 20px">
|
||||||
<h5>Zabbix trigger
|
<h5>Filter Triggers</h5>
|
||||||
</h5>
|
<div class="tight-form">
|
||||||
</div>
|
<ul class="tight-form-list">
|
||||||
</div>
|
<li class="tight-form-item" style="width: 80px">
|
||||||
|
Group
|
||||||
<div class="editor-row">
|
</li>
|
||||||
<div class="editor-option">
|
<li>
|
||||||
<label class="small">Group</label>
|
<input type="text"
|
||||||
<input type="text" class="input-medium" ng-model='currentAnnotation.group'></input>
|
ng-model="annotation.group"
|
||||||
</div>
|
class="input-large tight-form-input">
|
||||||
<div class="editor-option">
|
</li>
|
||||||
<label class="small">Host</label>
|
<li class="tight-form-item" style="width: 50px">
|
||||||
<input type="text" class="input-medium" ng-model='currentAnnotation.host'></input>
|
Host
|
||||||
</div>
|
</li>
|
||||||
<div class="editor-option">
|
<li>
|
||||||
<label class="small">Trigger
|
<input type="text"
|
||||||
<tip>Trigger name for search. Wildcards are supports. Examples: Lack of free swap space, Lack of*.
|
ng-model="annotation.host"
|
||||||
</tip>
|
class="input-large tight-form-input last">
|
||||||
</label>
|
</li>
|
||||||
<input type="text" style="width: 25em" ng-model='currentAnnotation.trigger' placeholder="Trigger name"></input>
|
</ul>
|
||||||
</div>
|
<div class="clearfix"></div>
|
||||||
<div class="editor-option">
|
</div>
|
||||||
<label class="small">Minimum severity
|
<div class="tight-form">
|
||||||
</label>
|
<ul class="tight-form-list">
|
||||||
<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>
|
<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>
|
</div>
|
||||||
|
|
||||||
<div class="editor-row">
|
<div class="editor-row">
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h5>Options</h5>
|
<h5>Options</h5>
|
||||||
<input type="checkbox" class="cr1" id="currentAnnotation.showOkEvents"
|
<div class="editor-option">
|
||||||
ng-model="currentAnnotation.showOkEvents"
|
<label class="small">Minimum severity
|
||||||
ng-checked="currentAnnotation.showOkEvents">
|
</label>
|
||||||
<label for="currentAnnotation.showOkEvents" class="cr1">Show OK events
|
<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>
|
||||||
<tip>Show events, generated when trigger release to OK state</tip>
|
</div>
|
||||||
</label>
|
<editor-opt-bool text="Show OK events" model="annotation.showOkEvents"></editor-opt-bool>
|
||||||
<input type="checkbox" class="cr1" id="currentAnnotation.showHostname"
|
<editor-opt-bool text="Hide acknowledged events" model="annotation.hideAcknowledged"></editor-opt-bool>
|
||||||
ng-model="currentAnnotation.showHostname"
|
<editor-opt-bool text="Show hostname" model="annotation.showHostname"></editor-opt-bool>
|
||||||
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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -47,6 +47,30 @@ function (_, moment) {
|
|||||||
return moment.duration(Number(momentInterval[1]), momentInterval[2]).valueOf();
|
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();
|
return new Utils();
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ function (angular, _) {
|
|||||||
skipDependent: true,
|
skipDependent: true,
|
||||||
//only_true: true,
|
//only_true: true,
|
||||||
filter: {
|
filter: {
|
||||||
value: showEvents
|
value: 1
|
||||||
},
|
},
|
||||||
selectGroups: ['name'],
|
selectGroups: ['name'],
|
||||||
selectHosts: ['name'],
|
selectHosts: ['name'],
|
||||||
@@ -316,6 +316,10 @@ function (angular, _) {
|
|||||||
selectLastEvent: 'extend'
|
selectLastEvent: 'extend'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (showEvents) {
|
||||||
|
params.filter.value = showEvents;
|
||||||
|
}
|
||||||
|
|
||||||
return this.request('trigger.get', params);
|
return this.request('trigger.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user