Replace $http to backendSrv for grafana-2-like request style.

This commit is contained in:
Alexander Zobnin
2015-05-12 22:58:34 +03:00
parent 4a9885946b
commit 69d781e698
2 changed files with 16 additions and 12 deletions

View File

@@ -9,12 +9,12 @@ function (angular, _, kbn) {
var module = angular.module('grafana.services'); var module = angular.module('grafana.services');
module.factory('ZabbixAPIDatasource', function($q, $http, templateSrv) { module.factory('ZabbixAPIDatasource', function($q, backendSrv, templateSrv) {
function ZabbixAPIDatasource(datasource) { function ZabbixAPIDatasource(datasource) {
this.name = datasource.name; this.name = datasource.name;
this.type = 'ZabbixAPIDatasource'; this.type = 'zabbix';
this.supportMetrics = true;
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
@@ -23,6 +23,11 @@ function (angular, _, kbn) {
// No datapoints limit by default // No datapoints limit by default
this.limitMetrics = datasource.limitMetrics || 0; this.limitMetrics = datasource.limitMetrics || 0;
this.supportMetrics = true;
this.supportAnnotations = true;
// For testing
this.ds = datasource;
} }
@@ -133,10 +138,10 @@ function (angular, _, kbn) {
performedQuery = this.performZabbixAPILogin().then(function (response) { performedQuery = this.performZabbixAPILogin().then(function (response) {
self.auth = response; self.auth = response;
options.data.auth = response; options.data.auth = response;
return $http(options); return backendSrv.datasourceRequest(options);
}); });
} else { } else {
performedQuery = $http(options); performedQuery = backendSrv.datasourceRequest(options);
} }
// Handle response // Handle response
@@ -237,7 +242,7 @@ function (angular, _, kbn) {
}, },
}; };
return $http(options).then(function (result) { return backendSrv.datasourceRequest(options).then(function (result) {
if (!result.data) { if (!result.data) {
return null; return null;
} }
@@ -351,7 +356,7 @@ function (angular, _, kbn) {
}, },
}; };
return $http(tid_options).then(function(result) { return backendSrv.datasourceRequest(tid_options).then(function(result) {
var obs = {}; var obs = {};
obs = _.indexBy(result.data.result, 'triggerid'); obs = _.indexBy(result.data.result, 'triggerid');
@@ -374,7 +379,7 @@ function (angular, _, kbn) {
}, },
}; };
return $http(options).then(function(result2) { return backendSrv.datasourceRequest(options).then(function(result2) {
var list = []; var list = [];
_.each(result2.data.result, function(e) { _.each(result2.data.result, function(e) {
list.push({ list.push({

View File

@@ -1,22 +1,21 @@
<div ng-include="httpConfigPartialSrc"></div> <div ng-include="httpConfigPartialSrc"></div>
<br> <br>
<h5>Zabbix API details</h5> <h5>Zabbix API details</h5>
<div class="tight-form"> <div class="tight-form last">
<ul class="tight-form-list"> <ul class="tight-form-list">
<li class="tight-form-item" style="width: 80px"> <li class="tight-form-item" style="width: 80px">
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.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.zabbixPassword' placeholder=""></input>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>