Merge branch 'develop'

This commit is contained in:
Alexander Zobnin
2015-05-19 23:54:47 +03:00
3 changed files with 35 additions and 61 deletions

View File

@@ -12,20 +12,13 @@ function (angular, _, kbn) {
module.factory('ZabbixAPIDatasource', function($q, backendSrv, templateSrv) {
function ZabbixAPIDatasource(datasource) {
this.type = 'zabbix';
this.name = datasource.name;
this.url = datasource.url;
// TODO: fix passing username and password from config.html
this.username = datasource.meta.username;
this.password = datasource.meta.password;
// No datapoints limit by default
this.limitMetrics = datasource.limitMetrics || 0;
this.supportMetrics = true;
this.supportAnnotations = true;
// For testing
this.ds = datasource;
}
@@ -137,8 +130,7 @@ function (angular, _, kbn) {
itemids: items.itemid,
sortfield: 'clock',
sortorder: 'ASC',
limit: this.limitmetrics,
time_from: start,
time_from: start
};
// 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) {
var from = kbn.parseDate(rangeUnparsed.from).getTime();
var to = kbn.parseDate(rangeUnparsed.to).getTime();
var from = Math.ceil(kbn.parseDate(rangeUnparsed.from).getTime() / 1000);
var to = Math.ceil(kbn.parseDate(rangeUnparsed.to).getTime() / 1000);
var self = this;
from = Math.ceil(from/1000);
to = Math.ceil(to/1000);
var tid_options = {
method: 'POST',
url: self.url + '',
data: {
jsonrpc: '2.0',
method: 'trigger.get',
params: {
output: ['triggerid', 'description'],
itemids: annotation.aids.split(','), // TODO: validate / pull automatically from dashboard.
limit: self.limitmetrics,
},
auth: self.auth,
id: 1
var params = {
output: ['triggerid', 'description'],
search: {
'description': annotation.query
},
};
return backendSrv.datasourceRequest(tid_options).then(function(result) {
var obs = {};
obs = _.indexBy(result.data.result, 'triggerid');
return this.performZabbixAPIRequest('trigger.get', params).then(function (result) {
if(result) {
var obs = {};
obs = _.indexBy(result, 'triggerid');
var options = {
method: 'POST',
url: self.url + '',
data: {
jsonrpc: '2.0',
method: 'event.get',
params: {
output: 'extend',
sortorder: 'DESC',
time_from: from,
time_till: to,
objectids: _.keys(obs),
limit: self.limitmetrics,
},
auth: self.auth,
id: 1
},
};
var params = {
output: 'extend',
sortorder: 'DESC',
time_from: from,
time_till: to,
objectids: _.keys(obs)
};
return backendSrv.datasourceRequest(options).then(function(result2) {
var list = [];
_.each(result2.data.result, function(e) {
list.push({
annotation: annotation,
time: e.clock * 1000,
title: obs[e.objectid].description,
text: e.eventid,
return self.performZabbixAPIRequest('event.get', params).then(function (result) {
var events = [];
_.each(result, function(e) {
events.push({
annotation: annotation,
time: e.clock * 1000,
title: obs[e.objectid].description,
text: e.eventid,
});
});
return events;
});
return list;
});
} else {
return [];
}
});
};

View File

@@ -1,8 +1,8 @@
<div class="editor-row">
<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">
<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>

View File

@@ -10,13 +10,13 @@
User
</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 class="tight-form-item">
Password
</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>
</ul>
<div class="clearfix"></div>