|
|
@@ -7,13 +7,12 @@ function(angular, config) {
|
|
|
|
|
|
var module = angular.module('kibana.services');
|
|
|
|
|
|
- module.service('elasticClient', function($http) {
|
|
|
-
|
|
|
- this.post = function(url, data) {
|
|
|
+ module.service('elastic', function($http) {
|
|
|
|
|
|
+ this._request = function(method, url, data) {
|
|
|
var options = {
|
|
|
url: config.elasticsearch + "/" + config.grafana_index + "/" + url,
|
|
|
- method: 'POST',
|
|
|
+ method: method,
|
|
|
data: data
|
|
|
};
|
|
|
|
|
|
@@ -23,11 +22,35 @@ function(angular, config) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- return $http(options)
|
|
|
+ return $http(options);
|
|
|
+ };
|
|
|
+
|
|
|
+ this.post = function(url, data) {
|
|
|
+ return this._request('POST', url, data)
|
|
|
.then(function(results) {
|
|
|
return results.data;
|
|
|
- }, function(results) {
|
|
|
- return results.data;
|
|
|
+ }, function(err) {
|
|
|
+ return err.data;
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ this.saveDashboard = function(dashboard, title, ttl) {
|
|
|
+ var dashboardClone = angular.copy(dashboard);
|
|
|
+ title = dashboardClone.title = title ? title : dashboard.title;
|
|
|
+
|
|
|
+ var data = {
|
|
|
+ user: 'guest',
|
|
|
+ group: 'guest',
|
|
|
+ title: title,
|
|
|
+ tags: dashboardClone.tags,
|
|
|
+ dashboard: angular.toJson(dashboardClone)
|
|
|
+ };
|
|
|
+
|
|
|
+ return this._request('PUT', '/dashboard/' + encodeURIComponent(title), data)
|
|
|
+ .then(function() {
|
|
|
+ return { title: title, url: '/dashboard/elasticsearch/' + title };
|
|
|
+ }, function(err) {
|
|
|
+ throw 'Failed to save to elasticsearch ' + err.data;
|
|
|
});
|
|
|
};
|
|
|
|