Fixed #52 - Added Basic Auth support.
This commit is contained in:
@@ -23,6 +23,8 @@ function (angular, _, kbn) {
|
|||||||
function ZabbixAPIDatasource(datasource) {
|
function ZabbixAPIDatasource(datasource) {
|
||||||
this.name = datasource.name;
|
this.name = datasource.name;
|
||||||
this.url = datasource.url;
|
this.url = datasource.url;
|
||||||
|
this.basicAuth = datasource.basicAuth;
|
||||||
|
this.withCredentials = datasource.withCredentials;
|
||||||
|
|
||||||
// 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;
|
||||||
@@ -36,7 +38,7 @@ function (angular, _, kbn) {
|
|||||||
this.limitmetrics = datasource.meta.limitmetrics || 100;
|
this.limitmetrics = datasource.meta.limitmetrics || 100;
|
||||||
|
|
||||||
// Initialize Zabbix API
|
// Initialize Zabbix API
|
||||||
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password);
|
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ function (angular, _) {
|
|||||||
|
|
||||||
module.factory('ZabbixAPI', function($q, backendSrv) {
|
module.factory('ZabbixAPI', function($q, backendSrv) {
|
||||||
|
|
||||||
function ZabbixAPI(api_url, username, password) {
|
function ZabbixAPI(api_url, username, password, basicAuth, withCredentials) {
|
||||||
// Initialize API parameters.
|
// Initialize API parameters.
|
||||||
this.url = api_url;
|
this.url = api_url;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
this.basicAuth = basicAuth;
|
||||||
|
this.withCredentials = withCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
var p = ZabbixAPI.prototype;
|
var p = ZabbixAPI.prototype;
|
||||||
@@ -45,6 +47,13 @@ function (angular, _) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.basicAuth || this.withCredentials) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
}
|
||||||
|
if (this.basicAuth) {
|
||||||
|
options.headers.Authorization = this.basicAuth;
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return backendSrv.datasourceRequest(options).then(function (response) {
|
return backendSrv.datasourceRequest(options).then(function (response) {
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
@@ -88,6 +97,14 @@ function (angular, _) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (this.basicAuth || this.withCredentials) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
}
|
||||||
|
if (this.basicAuth) {
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
options.headers.Authorization = this.basicAuth;
|
||||||
|
}
|
||||||
|
|
||||||
return backendSrv.datasourceRequest(options).then(function (result) {
|
return backendSrv.datasourceRequest(options).then(function (result) {
|
||||||
if (!result.data) {
|
if (!result.data) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user