From e0f1606a5a3b5b0dc9010b5aa9dc3b07ba768bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Vachon?= Date: Fri, 29 May 2015 16:26:53 -0400 Subject: [PATCH] Drupal detailed view Change-Id: I5a5d93247dc5b9210f4ca7e4eafeb41f1239fac2 --- app/app.js | 18 +-- app/assets/sass/temporary/temporary.scss | 17 ++- app/components/drupal/drupal.html | 97 +++++++++++++++ app/components/drupal/drupal.js | 35 ++++++ .../drupal/drupal_tile/drupal_tile.html | 10 ++ .../drupal/drupal_tile/drupal_tile.js | 99 +++++++++++++++ app/index.html | 2 + app/templates/drupal/drupal.html | 117 +----------------- 8 files changed, 270 insertions(+), 125 deletions(-) create mode 100644 app/components/drupal/drupal.html create mode 100644 app/components/drupal/drupal.js create mode 100644 app/components/drupal/drupal_tile/drupal_tile.html create mode 100644 app/components/drupal/drupal_tile/drupal_tile.js diff --git a/app/app.js b/app/app.js index 6870369..faceeea 100644 --- a/app/app.js +++ b/app/app.js @@ -12,6 +12,8 @@ angular.module('bansho', [ 'bansho.surveil', 'bansho.host', 'bansho.service', + 'bansho.drupal', + 'bansho.drupal.tile', 'bansho.view', 'bansho.view.dashboard', 'bansho.view.singleTable', @@ -27,11 +29,11 @@ angular.module('bansho', [ }]) // Reinitialise objects on url change - .run(['$rootScope', 'promisesManager', 'reinitTables', 'themeManager', - function ($rootScope, promisesManager, reinitTables, themeManager) { - themeManager.setTheme(); - $rootScope.$on('$locationChangeStart', function () { - reinitTables(); - promisesManager.clearAllPromises(); - }); - }]); + .run(['$rootScope', 'promisesManager', 'reinitTables', 'reinitDrupalTiles', + function ($rootScope, promisesManager, reinitTables, reinitDrupalTiles) { + $rootScope.$on('$locationChangeStart', function () { + reinitTables(); + reinitDrupalTiles(); + promisesManager.clearAllPromises(); + }); + }]); diff --git a/app/assets/sass/temporary/temporary.scss b/app/assets/sass/temporary/temporary.scss index 3a98ab1..2762131 100644 --- a/app/assets/sass/temporary/temporary.scss +++ b/app/assets/sass/temporary/temporary.scss @@ -13,6 +13,22 @@ width: 100%; } +.tile__score-critical { + background-color: #d9534f; + border-color: #d43f3a; + border-radius: 5px; + color: #fff; + padding: 5px; +} + +.tile__score-warning { + background-color: #f0ad4e; + border-color: #eea236; + color: #fff; + border-radius: 5px; + padding: 5px; +} + .btn-success { background-color: #5cb85c; border-color: #4cae4c; @@ -45,7 +61,6 @@ margin: 2px; text-align: center; vertical-align: middle; - white-space: nowrap; } .drupal-warn { diff --git a/app/components/drupal/drupal.html b/app/components/drupal/drupal.html new file mode 100644 index 0000000..4fbb7bc --- /dev/null +++ b/app/components/drupal/drupal.html @@ -0,0 +1,97 @@ +
+

{{drupal_id}}

+
+

General informations

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Core version :7.37
Core up-to-date :YES
Vulnerable core :NO
JQuery version:2.1.4
Database :MySQL
Database version :5.6.23
Database state : OK
Cache activated :YES
+
+ + + + + + + + + + + + + + + + +
diff --git a/app/components/drupal/drupal.js b/app/components/drupal/drupal.js new file mode 100644 index 0000000..8aa444e --- /dev/null +++ b/app/components/drupal/drupal.js @@ -0,0 +1,35 @@ +'use strict'; + +angular.module('bansho.drupal', ['bansho.surveil']) + + .value('drupalConfig', {}) + + .controller('DrupalCtrl', ['$scope', 'drupalConfig', 'surveilStatus', + function ($scope, drupalConfig, surveilStatus) { + $scope.hostName = drupalConfig.hostName; + }]) + + .directive('banshoDrupal', ['$http', '$compile', 'surveilStatus', 'drupalConfig', + function ($http, $compile, surveilStatus, drupalConfig) { + return { + restrict: 'E', + compile: function () { + return function (scope, element, attrs) { + var template = 'components/drupal/drupal.html'; + + if (!attrs.hostName) { + throw new Error(' "host-name" attribute must be defined'); + } + + drupalConfig.hostName = {}; + drupalConfig.hostName = attrs.hostName; + + $http.get(template, { cache: true }) + .success(function (data) { + var elem = $compile(data)(scope); + element.append(elem); + }); + }; + } + }; + }]); diff --git a/app/components/drupal/drupal_tile/drupal_tile.html b/app/components/drupal/drupal_tile/drupal_tile.html new file mode 100644 index 0000000..4a7d0b4 --- /dev/null +++ b/app/components/drupal/drupal_tile/drupal_tile.html @@ -0,0 +1,10 @@ +
+

{{title}} {{finalScore}}

+ + + + + + +
{{datum[0]}}
+
diff --git a/app/components/drupal/drupal_tile/drupal_tile.js b/app/components/drupal/drupal_tile/drupal_tile.js new file mode 100644 index 0000000..07bec7a --- /dev/null +++ b/app/components/drupal/drupal_tile/drupal_tile.js @@ -0,0 +1,99 @@ +'use strict'; + +angular.module('bansho.drupal.tile', []) + + .value('DrupalTileConfig', {'nextIndex': 0, 'tileConf': []}) + + .controller('DrupalTileCtrl', ['$scope', 'surveilStatus', 'DrupalTileConfig', + function ($scope, surveilStatus, DrupalTileConfig) { + var fields = [], + apiName = 'services', + filters = {}, + currentIndex = DrupalTileConfig.nextIndex, + tileConfig = DrupalTileConfig.tileConf[currentIndex]; + + $scope.plugin = tileConfig.plugin; + $scope.title = tileConfig.title; + $scope.hostName = tileConfig.hostName; + + filters = {'is': {'host_name': [$scope.hostName], + 'service_description': [$scope.plugin]}}; + + surveilStatus.getObjects(fields, filters, apiName) + .success(function (response) { + var finalScore = response[0].plugin_output.split(' ')[1], + out = [], + data = response[0].long_output.split(';').slice(0, -1); + + finalScore = parseInt(finalScore.substring(0, finalScore.length - 4)); + $scope.finalScore = isNaN(finalScore) ? '': finalScore + '%'; + + if (finalScore <= tileConfig.critical) { + $scope.finalScoreClass = 'tile__score-critical'; + } else if (finalScore <= tileConfig.warning) { + $scope.finalScoreClass = 'tile__score-warning'; + } + + // Split data into (metric, score_class, action) tuples + for (var i = 0; i < data.length; i+=3) { + var tuple = []; + + tuple.push(data[i]); + var score = parseInt(data[i+1].trim(), 10); + if (score === 1) { + tuple.push('btn-warning'); + } else if (score === 0) { + tuple.push('btn-danger'); + } else { + tuple.push(''); + } + tuple.push(data[i+2]); + out.push(tuple); + } + $scope.data = out; + + }); + + DrupalTileConfig.nextIndex++; + }]) + + .directive('banshoDrupalTile', ['$http', '$compile', 'DrupalTileConfig', + function ($http, $compile, DrupalTileConfig) { + return { + restrict: 'E', + compile: function () { + return function (scope, element, attrs) { + var template = 'components/drupal/drupal_tile/drupal_tile.html', + currentIndex = DrupalTileConfig.nextIndex, + tileConfig = {}; + + if (!attrs.hostName || !attrs.plugin || !attrs.warning || !attrs.critical) { + throw new Error(' "host-name", ' + + '"plugin", "warning" and "critical" ' + + 'attributes must be defined'); + } + + tileConfig.hostName = attrs.hostName; + tileConfig.plugin = attrs.plugin; + tileConfig.title = attrs.title; + tileConfig.warning = parseInt(attrs.warning, 10); + tileConfig.critical = parseInt(attrs.critical, 10); + DrupalTileConfig.tileConf.push(tileConfig); + + $http.get(template, { cache: true }) + .success(function (data) { + var elem = $compile(data)(scope); + element.append(elem); + }); + }; + } + }; + }]) + + .service('reinitDrupalTiles', ['DrupalTileConfig', + function (DrupalTileConfig) { + return function () { + // Reinitialise tile index + DrupalTileConfig.nextIndex = 0; + }; + }]); diff --git a/app/index.html b/app/index.html index cf74644..4d150de 100644 --- a/app/index.html +++ b/app/index.html @@ -83,6 +83,8 @@ + + diff --git a/app/templates/drupal/drupal.html b/app/templates/drupal/drupal.html index 5bf32a0..89c8dec 100644 --- a/app/templates/drupal/drupal.html +++ b/app/templates/drupal/drupal.html @@ -1,116 +1 @@ -
-

{{drupal_id}}

-
-
-

General informations

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core version :7.37
Core up-to-date :YES
Vulnerable core :NO
JQuery version:2.1.4
Database :MySQL
Database version :5.6.23
Database state :OK
Cache activated :YES
-
- -
-

Database 100%

- - - - - - - - - - - - - - - - - - - -
Total size35.54 Mb
CollationsEvery tables are using UTF-8
Storage EnginesAll tables are using innoDB
Tables over 1000 rows20
-
- -
-

Cache 17%

- - - - - - - - - - - - - - - - - - - - - - - -
Anonymous cachingNot enabled
Minimum cache lifetimeNone
Expiration of cached pagesNot set
Aggregate and compress CSSNot enabled
Aggregate JavascriptNot enabled
-
- -
-

Cron jobs 100%

- - - - - - - - - - - - - - - -
Crontab statusEnabled
RunningNo
Last run24 min 51 sec ago
-
-
-
+