From 8ea43517979e5afd3f08d72da5705e0015944095 Mon Sep 17 00:00:00 2001 From: Nikolay Bryskin Date: Thu, 3 Apr 2014 01:35:49 +0400 Subject: [PATCH 1/3] import from non-default dashboard support --- src/app/controllers/graphiteImport.js | 17 +++++++++++++++-- src/app/partials/import.html | 11 ++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/controllers/graphiteImport.js b/src/app/controllers/graphiteImport.js index 10f6e4d0593..2f7d1a39a17 100644 --- a/src/app/controllers/graphiteImport.js +++ b/src/app/controllers/graphiteImport.js @@ -12,12 +12,25 @@ function (angular, app, _) { $scope.init = function() { console.log('hej!'); + $scope.datasources = datasourceSrv.listOptions(); + $scope.setDatasource(datasourceSrv.default.value); }; + + $scope.setDatasource = function(datasource) { + $scope.datasource = datasourceSrv.get(datasource); + + if (!$scope.datasource) { + $scope.error = "Cannot find datasource " + datasource; + return; + } + }; + + $scope.listAll = function(query) { delete $scope.error; - datasourceSrv.default.listDashboards(query) + $scope.datasource.listDashboards(query) .then(function(results) { $scope.dashboards = results; }) @@ -29,7 +42,7 @@ function (angular, app, _) { $scope.import = function(dashName) { delete $scope.error; - datasourceSrv.default.loadDashboard(dashName) + $scope.datasource.loadDashboard(dashName) .then(function(results) { if (!results.data || !results.data.state) { throw { message: 'no dashboard state received from graphite' }; diff --git a/src/app/partials/import.html b/src/app/partials/import.html index 9331d2b8b63..eeb481e9bdf 100644 --- a/src/app/partials/import.html +++ b/src/app/partials/import.html @@ -1,8 +1,17 @@ -
+
Import dashboards from graphite web
+
+ + + +
From ae9d9ea284bb919c1ff8c180e9c1d1b9201a4d1b Mon Sep 17 00:00:00 2001 From: Nikolay Bryskin Date: Thu, 3 Apr 2014 02:11:58 +0400 Subject: [PATCH 2/3] import from graphite: set correct datasource for panel --- src/app/controllers/graphiteImport.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/controllers/graphiteImport.js b/src/app/controllers/graphiteImport.js index 2f7d1a39a17..71c4ef2cb13 100644 --- a/src/app/controllers/graphiteImport.js +++ b/src/app/controllers/graphiteImport.js @@ -13,7 +13,7 @@ function (angular, app, _) { $scope.init = function() { console.log('hej!'); $scope.datasources = datasourceSrv.listOptions(); - $scope.setDatasource(datasourceSrv.default.value); + $scope.setDatasource(null); }; @@ -48,14 +48,14 @@ function (angular, app, _) { throw { message: 'no dashboard state received from graphite' }; } - graphiteToGrafanaTranslator(results.data.state); + graphiteToGrafanaTranslator(results.data.state, $scope.datasource.name); }) .then(null, function(err) { $scope.error = err.message || 'Failed to import dashboard'; }); }; - function graphiteToGrafanaTranslator(state) { + function graphiteToGrafanaTranslator(state, datasource) { var graphsPerRow = 2; var rowHeight = 300; var rowTemplate; @@ -85,7 +85,8 @@ function (angular, app, _) { type: 'graphite', span: 12 / graphsPerRow, title: graph[1].title, - targets: [] + targets: [], + datasource: datasource }; _.each(graph[1].target, function(target) { From a1632e48742bbdc1c7f9dcfa0b390951809c2ef9 Mon Sep 17 00:00:00 2001 From: Nikolay Bryskin Date: Thu, 3 Apr 2014 02:38:01 +0400 Subject: [PATCH 3/3] identation fixed --- src/app/controllers/graphiteImport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/controllers/graphiteImport.js b/src/app/controllers/graphiteImport.js index 71c4ef2cb13..9c63c977277 100644 --- a/src/app/controllers/graphiteImport.js +++ b/src/app/controllers/graphiteImport.js @@ -21,7 +21,7 @@ function (angular, app, _) { $scope.datasource = datasourceSrv.get(datasource); if (!$scope.datasource) { - $scope.error = "Cannot find datasource " + datasource; + $scope.error = "Cannot find datasource " + datasource; return; } };