mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #55 from oroce/elasticsearch-basicauth
basic authentication added for elasticsearch
This commit is contained in:
commit
2c5bfec089
@ -28,16 +28,19 @@ function (_, crypto) {
|
|||||||
settings[key] = typeof options[key] !== 'undefined' ? options[key] : defaults[key];
|
settings[key] = typeof options[key] !== 'undefined' ? options[key] : defaults[key];
|
||||||
});
|
});
|
||||||
|
|
||||||
var url = settings.graphiteUrl;
|
var basicAuth = function(url) {
|
||||||
var passwordAt = url.indexOf('@');
|
var passwordAt = url.indexOf('@');
|
||||||
if (passwordAt > 0) {
|
if (passwordAt > 0) {
|
||||||
var userStart = url.indexOf('//') + 2;
|
var userStart = url.indexOf('//') + 2;
|
||||||
var userAndPassword = url.substring(userStart, passwordAt);
|
var userAndPassword = url.substring(userStart, passwordAt);
|
||||||
var bytes = crypto.charenc.Binary.stringToBytes(userAndPassword);
|
var bytes = crypto.charenc.Binary.stringToBytes(userAndPassword);
|
||||||
var base64 = crypto.util.bytesToBase64(bytes);
|
var base64 = crypto.util.bytesToBase64(bytes);
|
||||||
settings.graphiteBasicAuth = base64;
|
return base64;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
settings.graphiteBasicAuth = basicAuth(settings.graphiteUrl);
|
||||||
|
settings.elasticsearchBasicAuth = basicAuth(settings.elasticsearch);
|
||||||
return settings;
|
return settings;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -58,7 +58,7 @@ function (angular, $, config, _) {
|
|||||||
|
|
||||||
$scope.reset_row();
|
$scope.reset_row();
|
||||||
|
|
||||||
$scope.ejs = ejsResource(config.elasticsearch);
|
$scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
|
||||||
|
|
||||||
$scope.bindKeyboardShortcuts();
|
$scope.bindKeyboardShortcuts();
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,13 @@ function (angular, _, config) {
|
|||||||
|
|
||||||
module.controller('MetricKeysCtrl', function($scope, $http, $q) {
|
module.controller('MetricKeysCtrl', function($scope, $http, $q) {
|
||||||
var elasticSearchUrlForMetricIndex = config.elasticsearch + '/' + config.grafana_metrics_index + '/';
|
var elasticSearchUrlForMetricIndex = config.elasticsearch + '/' + config.grafana_metrics_index + '/';
|
||||||
|
var httpOptions = {};
|
||||||
|
if (config.elasticsearchBasicAuth) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
options.headers = {
|
||||||
|
"Authorization": "Basic " + config.elasticsearchBasicAuth
|
||||||
|
};
|
||||||
|
}
|
||||||
$scope.init = function () {
|
$scope.init = function () {
|
||||||
$scope.metricPath = "prod.apps.api.boobarella.*";
|
$scope.metricPath = "prod.apps.api.boobarella.*";
|
||||||
$scope.metricCounter = 0;
|
$scope.metricCounter = 0;
|
||||||
@ -77,7 +83,7 @@ function (angular, _, config) {
|
|||||||
function deleteIndex()
|
function deleteIndex()
|
||||||
{
|
{
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
$http.delete(elasticSearchUrlForMetricIndex)
|
$http.delete(elasticSearchUrlForMetricIndex, httpOptions)
|
||||||
.success(function() {
|
.success(function() {
|
||||||
deferred.resolve('ok');
|
deferred.resolve('ok');
|
||||||
})
|
})
|
||||||
@ -124,7 +130,7 @@ function (angular, _, config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}, httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function receiveMetric(result) {
|
function receiveMetric(result) {
|
||||||
|
@ -47,7 +47,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// An elasticJS client to use
|
// An elasticJS client to use
|
||||||
var ejs = ejsResource(config.elasticsearch);
|
var ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
|
||||||
var gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
|
var gist_pattern = /(^\d{5,}$)|(^[a-z0-9]{10,}$)|(gist.github.com(\/*.*)\/[a-z0-9]{5,}\/*$)/;
|
||||||
|
|
||||||
// Store a reference to this
|
// Store a reference to this
|
||||||
@ -286,13 +286,21 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.elasticsearch_load = function(type,id) {
|
this.elasticsearch_load = function(type,id) {
|
||||||
return $http({
|
var options = {
|
||||||
url: config.elasticsearch + "/" + config.grafana_index + "/"+type+"/"+id+'?' + new Date().getTime(),
|
url: config.elasticsearch + "/" + config.grafana_index + "/"+type+"/"+id+'?' + new Date().getTime(),
|
||||||
method: "GET",
|
method: "GET",
|
||||||
transformResponse: function(response) {
|
transformResponse: function(response) {
|
||||||
return renderTemplate(angular.fromJson(response)._source.dashboard, $routeParams);
|
return renderTemplate(angular.fromJson(response)._source.dashboard, $routeParams);
|
||||||
}
|
}
|
||||||
}).error(function(data, status) {
|
};
|
||||||
|
if (config.elasticsearchBasicAuth) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
options.headers = {
|
||||||
|
"Authorization": "Basic " + config.elasticsearchBasicAuth
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return $http(options)
|
||||||
|
.error(function(data, status) {
|
||||||
if(status === 0) {
|
if(status === 0) {
|
||||||
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
|
alertSrv.set('Error',"Could not contact Elasticsearch at "+config.elasticsearch+
|
||||||
". Please ensure that Elasticsearch is reachable from your system." ,'error');
|
". Please ensure that Elasticsearch is reachable from your system." ,'error');
|
||||||
|
@ -13,7 +13,7 @@ be injected into your angular controllers.
|
|||||||
angular.module('elasticjs.service', [])
|
angular.module('elasticjs.service', [])
|
||||||
.factory('ejsResource', ['$http', function ($http) {
|
.factory('ejsResource', ['$http', function ($http) {
|
||||||
|
|
||||||
return function (config) {
|
return function (config, basicAuth) {
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
||||||
@ -43,6 +43,12 @@ angular.module('elasticjs.service', [])
|
|||||||
config.server = '';
|
config.server = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set authentication header
|
||||||
|
if (basicAuth || config.basicAuth) {
|
||||||
|
config.headers = angular.extend( config.headers||{}, {
|
||||||
|
"Authorization": "Basic " + (basicAuth||config.basicAuth)
|
||||||
|
});
|
||||||
|
}
|
||||||
/* implement the elastic.js client interface for angular */
|
/* implement the elastic.js client interface for angular */
|
||||||
ejs.client = {
|
ejs.client = {
|
||||||
server: function (s) {
|
server: function (s) {
|
||||||
|
Loading…
Reference in New Issue
Block a user