diff --git a/src/app/controllers/all.js b/src/app/controllers/all.js index 9f6a70552ca..1968daab360 100644 --- a/src/app/controllers/all.js +++ b/src/app/controllers/all.js @@ -5,5 +5,6 @@ define([ './pulldown', './search', './metricKeys', - './graphiteTarget' + './graphiteTarget', + './graphiteImport', ], function () {}); \ No newline at end of file diff --git a/src/app/controllers/graphiteImport.js b/src/app/controllers/graphiteImport.js new file mode 100644 index 00000000000..664eafa4f45 --- /dev/null +++ b/src/app/controllers/graphiteImport.js @@ -0,0 +1,90 @@ +define([ + 'angular', + 'app', + 'underscore' +], +function (angular, app, _) { + 'use strict'; + + var module = angular.module('kibana.controllers'); + + module.controller('GraphiteImportCtrl', function($scope, $rootScope, $timeout, graphiteSrv, dashboard) { + + $scope.init = function() { + console.log('hej!'); + }; + + $scope.listAll = function(query) { + delete $scope.error; + + graphiteSrv.listDashboards(query) + .then(function(results) { + $scope.dashboards = results; + }) + .then(null, function(err) { + $scope.error = err.message || 'Error while fetching list of dashboards'; + }); + }; + + $scope.import = function(dashName) { + delete $scope.error; + + graphiteSrv.loadDashboard(dashName) + .then(function(results) { + if (!results.data || !results.data.state) { + throw { message: 'no dashboard state received from graphite' }; + } + + graphiteToGrafanaTranslator(results.data.state); + }) + .then(null, function(err) { + $scope.error = err.message || 'Failed to import dashboard'; + }); + }; + + function graphiteToGrafanaTranslator(state) { + var graphsPerRow = 2; + var rowHeight = 300; + var rowTemplate; + var currentRow; + var panel; + + rowTemplate = { + title: '', + panels: [], + height: rowHeight + }; + + currentRow = angular.copy(rowTemplate); + + var newDashboard = angular.copy(dashboard.current); + newDashboard.rows = []; + newDashboard.title = state.name; + newDashboard.rows.push(currentRow); + + _.each(state.graphs, function(graph) { + if (currentRow.panels.length === graphsPerRow) { + currentRow = angular.copy(rowTemplate); + } + + panel = { + type: 'graphite', + span: 12 / graphsPerRow, + targets: [] + }; + + _.each(graph[1].target, function(target) { + panel.targets.push({ + target: target + }); + }); + + currentRow.panels.push(panel); + }); + + dashboard.dash_load(newDashboard); + } + + }); + +}); \ No newline at end of file diff --git a/src/app/partials/dashboard.html b/src/app/partials/dashboard.html index 9cc00019b53..c17456c19d9 100644 --- a/src/app/partials/dashboard.html +++ b/src/app/partials/dashboard.html @@ -77,7 +77,7 @@
- ADD A ROW + ADD A ROW
diff --git a/src/app/partials/dasheditor.html b/src/app/partials/dasheditor.html index f94e6fefc37..4bccbc2e41c 100644 --- a/src/app/partials/dasheditor.html +++ b/src/app/partials/dasheditor.html @@ -2,7 +2,7 @@
Dashboard settings
-
+
@@ -124,11 +124,15 @@
-
+
-
+
+ +
+ +
diff --git a/src/app/partials/import.html b/src/app/partials/import.html new file mode 100644 index 00000000000..cdfc637fb58 --- /dev/null +++ b/src/app/partials/import.html @@ -0,0 +1,22 @@ +
+
Import dashboards from graphite webb
+ +
+
+ +
+
+ +
+ + + + +
+ {{dash.name}}
+
+ +
+ {{error}} +
+
diff --git a/src/app/services/graphite/graphiteSrv.js b/src/app/services/graphite/graphiteSrv.js index 4f276be3c2c..a7f7ed763f0 100644 --- a/src/app/services/graphite/graphiteSrv.js +++ b/src/app/services/graphite/graphiteSrv.js @@ -71,6 +71,18 @@ function (angular, _, $, config) { }); }; + this.listDashboards = function(query) { + var url = config.graphiteUrl + '/dashboard/find/'; + return $http.get(url, {params: {query: query || ''}}) + .then(function(results) { + return results.data.dashboards; + }); + }; + + this.loadDashboard = function(dashName) { + var url = config.graphiteUrl + '/dashboard/load/' + encodeURIComponent(dashName); + return $http.get(url); + }; function buildGraphitePostParams(options) { var clean_options = [];