Drupal dashboard

Change-Id: Ib33878960646aae789062980c8b6fdebeaafb98c
This commit is contained in:
Frédéric Vachon 2015-06-25 12:37:52 -04:00
parent 2f7b56e588
commit 07bb737512
3 changed files with 64 additions and 93 deletions

View File

@ -270,20 +270,8 @@
"title": "Drupal dashboard", "title": "Drupal dashboard",
"refreshInterval": 0, "refreshInterval": 0,
"template": "drupal_dashboard", "template": "drupal_dashboard",
"servicesMap": {
"drupal_cache": "Drupal cache",
"drupal_codebase": "Drupal codebase",
"drupal_cron": "Drupal cron",
"drupal_database": "Drupal Database",
"drupal_extensions": "Drupal Extensions",
"drupal_logging": "Drupal logging",
"drupal_security": "Drupal security",
"drupal_status": "Drupal status",
"drupal_views": "Drupal views"
},
"hostsMap": { "hostsMap": {
"drupal": "Wonderful Drupal Website" "drupal": "Wonderful Drupal Website"
}, }
"hideStatusOk": false
} }
} }

View File

@ -1,40 +1,29 @@
<article ng-controller="DrupalDashboardViewCtrl"> <article ng-controller="DrupalDashboardViewCtrl">
<h1 class="drupal__dashboard__title">Drupal dashboard</h1> <h1 class="drupal__dashboard__title">{{title}}</h1>
<span ng-repeat="host in data"> <span ng-repeat="(host_name, host_obj) in data">
<a href="#/view?view=drupal&id=Drupal"> <a href="#/view?view=drupal&id={{host_name}}">
<div class="tile__main"> <div class="tile__main">
<h3>{{host.host_text}}</h3> <h3>{{host_obj.host_name}}</h3>
<label ng-repeat="service in data[0].services" <table class="data-table">
ng-hide="{{service.hide}}" <tr>
class="btn {{service.state}}">{{service.description}} <td style="text-align:center;">Address</td>
</label> <td style="text-align:center;">{{host_obj.address}}</td>
</tr>
<tr>
<td style="text-align:center;">Core version</td>
<td style="text-align:center;">{{host_obj.core_version}}</td>
</tr>
<tr>
<td style="text-align:center;">PHP version</td>
<td style="text-align:center;">{{host_obj.php_version}}</td>
</tr>
<tr ng-class="host_obj.security_class">
<td style="text-align:center;">Security updates</td>
<td style="text-align:center;">{{host_obj.security}}</td>
</tr>
</table>
</div> </div>
</a> </a>
</span> </span>
<a href="#/view?view=drupal&id=Drupal">
<div class="tile__main">
<h3>Site B</h3>
<label class="btn btn-success">Bandwith Ok</label>
<label class="btn btn-warning">Cache Warning</label>
<label class="btn btn-danger">Security update Critical</label>
</div>
</a>
<a href="#/view?view=drupal&id=Drupal">
<div class="tile__main">
<h3>Site C</h3>
<label class="btn btn-success">Bandwith Ok</label>
<label class="btn btn-warning">Cache Warning</label>
<label class="btn btn-danger">Security update Critical</label>
</div>
</a>
<a href="#/view?view=drupal&id=Drupal">
<div class="tile__main">
<h3>Site D</h3>
<label class="btn btn-success">Bandwith Ok</label>
<label class="btn btn-warning">Cache Warning</label>
<label class="btn btn-danger">Security update Critical</label>
</div>
</a>
</article> </article>

View File

@ -4,63 +4,57 @@ angular.module("bansho.view.drupalDashboard", [])
.controller("DrupalDashboardViewCtrl", ["$scope", "$routeParams", 'surveilStatus', 'configManager', .controller("DrupalDashboardViewCtrl", ["$scope", "$routeParams", 'surveilStatus', 'configManager',
function ($scope, $routeParams, surveilStatus, configManager) { function ($scope, $routeParams, surveilStatus, configManager) {
var out_data = [], var config = configManager.readConfig()[$routeParams.view],
config = configManager.readConfig()[$routeParams.view],
hostsMap = config.hostsMap, hostsMap = config.hostsMap,
servicesMap = config.servicesMap, filters_host, filters_service,
hideStatusOk = config.hideStatusOk,
filters = {},
hosts = []; hosts = [];
$scope.title = config.title;
angular.forEach(hostsMap, function (host_text, host_name) { angular.forEach(hostsMap, function (host_text, host_name) {
hosts.push(host_name); hosts.push(host_name);
}); });
filters = {'is': {'host_name': hosts}}; filters_host = {'is': {'host_name': hosts}};
filters_service = {'is': {'host_name': hosts,
'service_description': ['drupal_status']}};
surveilStatus.getObjects([], filters, 'services').success(function (services) { surveilStatus.getObjects([], filters_host, 'hosts').success(function (host_objects) {
var out_dict = {};
for (var i = 0; i < services.length; i++) { for (var i = 0; i < host_objects.length; i++) {
var index, var obj = {};
service = services[i], obj.address = host_objects[i].address;
service_out = {}; obj.host_name = hostsMap[host_objects[i].host_name];
out_dict[host_objects[i].host_name] = obj;
// Look if host_name already in the array
for (var j = 0; j < out_data.length; j++) {
if (service.host_name === out_data[j].host_name) {
index = j;
break;
}
}
if (index === undefined) {
out_data.push({'host_name': service.host_name});
index = out_data.length - 1;
out_data[index].host_text = hostsMap[service.host_name];
}
if (!('services' in out_data[index])) {
out_data[index].services = [];
}
out_data[index].services.push({});
service_out = out_data[index].services[out_data[index].services.length - 1];
service_out.description = servicesMap[service.service_description];
if (service.state === 'CRITICAL') {
service_out.state = 'btn-danger';
} else if (service.state === 'WARNING') {
service_out.state = 'btn-warning';
} else if (service.state === 'OK') {
if (hideStatusOk) {
service_out.hide = true;
}
service_out.state = 'btn-success';
} else {
service_out.state = '';
}
} }
$scope.data = out_data;
surveilStatus.getObjects([], filters_service, 'services').success(function (status) {
for (var i = 0; i < status.length; i++) {
var stat = status[i],
obj = out_dict[stat.host_name],
long_out;
if (stat.plugin_output.indexOf('SECURITY UPDATE available') !== -1) {
obj.security = 'Available';
obj.security_class = 'btn-danger';
} else {
obj.security = 'None';
}
long_out = stat.long_output.split('\n');
for (var j = 0; j < long_out.length; j++) {
if (long_out[j].indexOf('Drupal Core version') !== -1) {
obj.core_version = long_out[j].split(';')[1];
} else if (long_out[j].indexOf('PHP version') !== -1) {
obj.php_version = long_out[j].split(';')[1];
}
}
out_dict[stat.host_name] = obj;
}
$scope.data = out_dict;
});
}); });
}]); }]);