Improve annotations - filter trigger expression.
This commit is contained in:
@@ -12,20 +12,13 @@ function (angular, _, kbn) {
|
|||||||
module.factory('ZabbixAPIDatasource', function($q, backendSrv, templateSrv) {
|
module.factory('ZabbixAPIDatasource', function($q, backendSrv, templateSrv) {
|
||||||
|
|
||||||
function ZabbixAPIDatasource(datasource) {
|
function ZabbixAPIDatasource(datasource) {
|
||||||
this.type = 'zabbix';
|
|
||||||
this.name = datasource.name;
|
this.name = datasource.name;
|
||||||
|
|
||||||
this.url = datasource.url;
|
this.url = datasource.url;
|
||||||
|
|
||||||
// TODO: fix passing username and password from config.html
|
// TODO: fix passing username and password from config.html
|
||||||
this.username = datasource.meta.username;
|
this.username = datasource.meta.username;
|
||||||
this.password = datasource.meta.password;
|
this.password = datasource.meta.password;
|
||||||
|
|
||||||
// No datapoints limit by default
|
|
||||||
this.limitMetrics = datasource.limitMetrics || 0;
|
|
||||||
this.supportMetrics = true;
|
|
||||||
this.supportAnnotations = true;
|
|
||||||
|
|
||||||
// For testing
|
// For testing
|
||||||
this.ds = datasource;
|
this.ds = datasource;
|
||||||
}
|
}
|
||||||
@@ -137,8 +130,7 @@ function (angular, _, kbn) {
|
|||||||
itemids: items.itemid,
|
itemids: items.itemid,
|
||||||
sortfield: 'clock',
|
sortfield: 'clock',
|
||||||
sortorder: 'ASC',
|
sortorder: 'ASC',
|
||||||
limit: this.limitmetrics,
|
time_from: start
|
||||||
time_from: start,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Relative queries (e.g. last hour) don't include an end time
|
// Relative queries (e.g. last hour) don't include an end time
|
||||||
@@ -238,63 +230,45 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
|
|
||||||
ZabbixAPIDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
|
ZabbixAPIDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
|
||||||
var from = kbn.parseDate(rangeUnparsed.from).getTime();
|
var from = Math.ceil(kbn.parseDate(rangeUnparsed.from).getTime() / 1000);
|
||||||
var to = kbn.parseDate(rangeUnparsed.to).getTime();
|
var to = Math.ceil(kbn.parseDate(rangeUnparsed.to).getTime() / 1000);
|
||||||
var self = this;
|
var self = this;
|
||||||
from = Math.ceil(from/1000);
|
|
||||||
to = Math.ceil(to/1000);
|
|
||||||
|
|
||||||
var tid_options = {
|
var params = {
|
||||||
method: 'POST',
|
|
||||||
url: self.url + '',
|
|
||||||
data: {
|
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'trigger.get',
|
|
||||||
params: {
|
|
||||||
output: ['triggerid', 'description'],
|
output: ['triggerid', 'description'],
|
||||||
itemids: annotation.aids.split(','), // TODO: validate / pull automatically from dashboard.
|
search: {
|
||||||
limit: self.limitmetrics,
|
'description': annotation.query
|
||||||
},
|
|
||||||
auth: self.auth,
|
|
||||||
id: 1
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return backendSrv.datasourceRequest(tid_options).then(function(result) {
|
return this.performZabbixAPIRequest('trigger.get', params).then(function (result) {
|
||||||
|
if(result) {
|
||||||
var obs = {};
|
var obs = {};
|
||||||
obs = _.indexBy(result.data.result, 'triggerid');
|
obs = _.indexBy(result, 'triggerid');
|
||||||
|
|
||||||
var options = {
|
var params = {
|
||||||
method: 'POST',
|
|
||||||
url: self.url + '',
|
|
||||||
data: {
|
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'event.get',
|
|
||||||
params: {
|
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
sortorder: 'DESC',
|
sortorder: 'DESC',
|
||||||
time_from: from,
|
time_from: from,
|
||||||
time_till: to,
|
time_till: to,
|
||||||
objectids: _.keys(obs),
|
objectids: _.keys(obs)
|
||||||
limit: self.limitmetrics,
|
|
||||||
},
|
|
||||||
auth: self.auth,
|
|
||||||
id: 1
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return backendSrv.datasourceRequest(options).then(function(result2) {
|
return self.performZabbixAPIRequest('event.get', params).then(function (result) {
|
||||||
var list = [];
|
var events = [];
|
||||||
_.each(result2.data.result, function(e) {
|
_.each(result, function(e) {
|
||||||
list.push({
|
events.push({
|
||||||
annotation: annotation,
|
annotation: annotation,
|
||||||
time: e.clock * 1000,
|
time: e.clock * 1000,
|
||||||
title: obs[e.objectid].description,
|
title: obs[e.objectid].description,
|
||||||
text: e.eventid,
|
text: e.eventid,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return list;
|
return events;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<div class="editor-row">
|
<div class="editor-row">
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h5>Item ids <tip>Example: 123, 45, 678</tip></h5>
|
<h5>Zabbix trigger <tip>Example: Lack of free swap space</tip></h5>
|
||||||
<div class="editor-option">
|
<div class="editor-option">
|
||||||
<input type="text" class="span10" ng-model='currentAnnotation.aids' placeholder="###, ###, ##"></input>
|
<input type="text" class="span10" ng-model='currentAnnotation.query' placeholder="Lack of free swap space"></input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,13 +10,13 @@
|
|||||||
User
|
User
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="text" class="tight-form-input input-large" ng-model='current.user' placeholder=""></input>
|
<input type="text" class="tight-form-input input-large" ng-model='current.jsonData.zabbixUser' placeholder=""></input>
|
||||||
</li>
|
</li>
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
Password
|
Password
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="password" class="tight-form-input input-large" ng-model='current.password' placeholder=""></input>
|
<input type="password" class="tight-form-input input-large" ng-model='current.jsonData.zabbixPassword' placeholder=""></input>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user