diff --git a/app/app.js b/app/app.js index faceeea..f0dd5a9 100644 --- a/app/app.js +++ b/app/app.js @@ -14,6 +14,7 @@ angular.module('bansho', [ 'bansho.service', 'bansho.drupal', 'bansho.drupal.tile', + 'bansho.drupal.info', 'bansho.view', 'bansho.view.dashboard', 'bansho.view.singleTable', @@ -29,11 +30,12 @@ angular.module('bansho', [ }]) // Reinitialise objects on url change - .run(['$rootScope', 'promisesManager', 'reinitTables', 'reinitDrupalTiles', - function ($rootScope, promisesManager, reinitTables, reinitDrupalTiles) { + .run(['$rootScope', 'promisesManager', 'reinitTables', 'reinitDrupalTiles', 'reinitDrupalInfo', + function ($rootScope, promisesManager, reinitTables, reinitDrupalTiles, reinitDrupalInfo) { $rootScope.$on('$locationChangeStart', function () { reinitTables(); reinitDrupalTiles(); + reinitDrupalInfo(); promisesManager.clearAllPromises(); }); }]); diff --git a/app/components/drupal/drupal.html b/app/components/drupal/drupal.html index 4fbb7bc..8908d00 100644 --- a/app/components/drupal/drupal.html +++ b/app/components/drupal/drupal.html @@ -1,43 +1,9 @@

{{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
-
+ + +

{{title}}

+ + + + + + + +
{{datum[0]}}{{datum[1]}}
+ diff --git a/app/components/drupal/drupal_info/drupal_info.js b/app/components/drupal/drupal_info/drupal_info.js new file mode 100644 index 0000000..82f3ac9 --- /dev/null +++ b/app/components/drupal/drupal_info/drupal_info.js @@ -0,0 +1,86 @@ +'use strict'; + +angular.module('bansho.drupal.info', []) + + .value('DrupalInfoConfig', {'nextIndex': 0, 'conf': []}) + + .controller('DrupalInfoCtrl', ['$scope', 'surveilStatus', 'DrupalInfoConfig', + function ($scope, surveilStatus, DrupalInfoConfig) { + var fields = [], + apiName = 'services', + filters = {}, + currentIndex = DrupalInfoConfig.nextIndex, + conf = DrupalInfoConfig.conf[currentIndex]; + + $scope.plugin = conf.plugin; + $scope.title = conf.title; + $scope.hostName = conf.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('\n').slice(0, -1); + + // Split data into (key, value, score_class) tuples + for (var i = 0; i < data.length; i++) { + var tuple = data[i].split(';'), + score = parseInt(tuple[2], 10); + + if (score === 1) { + tuple[2] = 'btn-warning'; + } else if (score === 0) { + tuple[2] = 'btn-danger'; + } else { + tuple[2] = ''; + } + + out.push(tuple); + } + + $scope.data = out; + }); + + DrupalInfoConfig.nextIndex++; + }]) + + .directive('banshoDrupalInfo', ['$http', '$compile', 'DrupalInfoConfig', + function ($http, $compile, DrupalInfoConfig) { + return { + restrict: 'E', + compile: function () { + return function (scope, element, attrs) { + var template = 'components/drupal/drupal_info/drupal_info.html', + currentIndex = DrupalInfoConfig.nextIndex, + conf = {}; + + if (!attrs.hostName || !attrs.plugin) { + throw new Error(' "host-name" and "plugin"' + + 'attributes must be defined'); + } + + conf.hostName = attrs.hostName; + conf.plugin = attrs.plugin; + conf.title = attrs.title; + DrupalInfoConfig.conf.push(conf); + + $http.get(template, { cache: true }) + .success(function (data) { + var elem = $compile(data)(scope); + element.append(elem); + }); + }; + } + }; + }]) + + .service('reinitDrupalInfo', ['DrupalInfoConfig', + function (DrupalInfoConfig) { + return function () { + // Reinitialise tile index + DrupalInfoConfig.nextIndex = 0; + }; + }]); diff --git a/app/index.html b/app/index.html index e88ffda..9c98cc8 100644 --- a/app/index.html +++ b/app/index.html @@ -88,6 +88,7 @@ +