Merge pull request #39 from Freddrickk/dashFix

Dashboard displays real number of problems
This commit is contained in:
Frédéric Vachon 2015-03-24 16:32:24 -04:00
commit cba41216de
7 changed files with 232 additions and 49 deletions

View File

@ -15,6 +15,71 @@
} }
} }
}, },
{
"type": "table",
"config": {
"title": "Hosts",
"cells": {
"text": [
"Host",
"Address",
"Duration",
"Last check",
"Host status"
],
"name": [
"hosts_host",
"host_address",
"duration",
"last_check",
"host_status"
]
},
"apiName": "hosts",
"additionnalQueryFields": {
"acknowledged": 0,
"state": 1
},
"isWrappable" : false,
"noRepeatCell" : ""
}
},
{
"type": "table",
"config": {
"title": "Service problems",
"cells": {
"text": [
"Host",
"Service check",
"Duration",
"Last check"
],
"name": [
"host",
"service_check",
"duration",
"last_check"
]
},
"apiName": "services",
"filters": {
"isnot": {
"state": [
"0"
],
"host_state": [
"2"
]
}
},
"additionnalQueryFields": {
"acknowledged": 0
},
"isWrappable" : true,
"noRepeatCell" : "host"
}
},
{ {
"type": "table", "type": "table",
"config": { "config": {

View File

@ -12,10 +12,11 @@ angular.module('adagios.live')
regex: '__regex' regex: '__regex'
}) })
.factory('getServices', ['$http', 'filterSuffixes', .service('getServices', ['$http', 'filterSuffixes',
function ($http, filterSuffixes) { function ($http, filterSuffixes) {
return function (columns, filters, apiName) { return function (columns, filters, apiName, additionnalFields) {
var filtersQuery = ''; var filtersQuery = '',
additionnalQuery = '';
function createFiltersQuery(filters) { function createFiltersQuery(filters) {
var builtQuery = ''; var builtQuery = '';
@ -33,11 +34,77 @@ angular.module('adagios.live')
return builtQuery; return builtQuery;
} }
filtersQuery = createFiltersQuery(filters); function createAdditionnalQuery(additionnalFields) {
var query = '';
angular.forEach(additionnalFields, function (value, key) {
query += '&' + key + '=' + value;
});
return $http.get('/rest/status/json/' + apiName + '/?fields=' + columns + filtersQuery) return query;
}
filtersQuery = createFiltersQuery(filters);
additionnalQuery = createAdditionnalQuery(additionnalFields);
return $http.get('/rest/status/json/' + apiName + '/?fields=' + columns + filtersQuery + additionnalQuery)
.error(function () { .error(function () {
throw new Error('getServices : GET Request failed'); throw new Error('getServices : GET Request failed');
}); });
}; };
}])
// This service is used to count the number of host open problems
.service('getHostOpenProblems', ['$http', 'getServices',
function ($http, getServices) {
var fields = ['state'],
filters = {},
apiName = 'hosts',
additionnalQueryFields = {'acknowledged': 0, 'state': 1};
return getServices(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getServices : GET Request failed');
});
}])
// This service is used to count the number of service open problems
.service('getServiceOpenProblems', ['$http', 'getServices',
function ($http, getServices) {
var fields = ['state'],
filters = { "isnot": { "state": [ "0" ], "host_state": [ "2" ] }},
apiName = 'services',
additionnalQueryFields = {'acknowledged': 0};
return getServices(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getServices : GET Request failed');
});
}])
// This service is used to count the number of host problems
.service('getHostProblems', ['$http', 'getServices',
function ($http, getServices) {
var fields = ['state'],
filters = { 'isnot': {'state': [0]} },
apiName = 'hosts',
additionnalQueryFields = {};
return getServices(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getServices : GET Request failed');
});
}])
// This service is used to count the number of service problems
.service('getServiceProblems', ['$http', 'getServices',
function ($http, getServices) {
var fields = ['state'],
filters = { 'isnot': {'state': [0]} },
apiName = 'services',
additionnalQueryFields = {};
return getServices(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getServices : GET Request failed');
});
}]); }]);

View File

@ -16,9 +16,9 @@ angular.module('adagios.table.cell_host_status', ['adagios.table'])
$scope.alert_level = "alert alert-danger"; $scope.alert_level = "alert alert-danger";
if ($scope.entry.childs.length !== 0) { if ($scope.entry.childs.length !== 0) {
$scope.entry.host_status = "Network outage";
} else {
$scope.entry.host_status = "Host down"; $scope.entry.host_status = "Host down";
} else {
$scope.entry.host_status = "Network outage";
} }
} }
}]) }])

View File

@ -6,11 +6,11 @@ angular.module('adagios.table.cell_hosts_host', ['adagios.table'])
if ($scope.entry.state === 0) { if ($scope.entry.state === 0) {
$scope.state = 'state--ok'; $scope.state = 'state--ok';
} else if ($scope.entry.state === 1) { } else if ($scope.entry.state === 1) {
$scope.state = 'state--warning'; $scope.state = 'state--error';
} else if ($scope.entry.state === "") { } else if ($scope.entry.state === "") {
$scope.state = ''; $scope.state = '';
} else { } else {
$scope.state = 'state--error'; $scope.state = 'state--unreachable';
} }
}]) }])

View File

@ -16,8 +16,8 @@ angular.module('adagios.table', ['adagios.live',
.controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'actionbarFilters', .controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'actionbarFilters',
function ($scope, $interval, getServices, tableConfig, actionbarFilters) { function ($scope, $interval, getServices, tableConfig, actionbarFilters) {
console.log(tableConfig[tableConfig.index].additionnalQueryFields);
var requestFields = [], var requestFields = [],
filters = JSON.parse(tableConfig[tableConfig.index].filters),
conf = tableConfig[tableConfig.index], conf = tableConfig[tableConfig.index],
getData, getData,
i; i;
@ -36,18 +36,19 @@ angular.module('adagios.table', ['adagios.live',
}); });
}); });
getData = function (requestFields, filters, apiName) { getData = function (requestFields, filters, apiName, additionnalFields) {
getServices(requestFields, filters, apiName) console.log(additionnalFields);
getServices(requestFields, filters, apiName, additionnalFields)
.success(function (data) { .success(function (data) {
$scope.entries = data; $scope.entries = data;
}); });
}; };
getData(requestFields, filters, conf.apiName); getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
if (tableConfig.refreshInterval !== '0') { if (tableConfig.refreshInterval !== '0') {
$interval(function () { $interval(function () {
getData(requestFields, filters, conf.apiName); getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
}, tableConfig.refreshInterval); }, tableConfig.refreshInterval);
} }
@ -64,34 +65,41 @@ angular.module('adagios.table', ['adagios.live',
compile: function () { compile: function () {
return function (scope, element, attrs) { return function (scope, element, attrs) {
var template = 'components/table/table.html',
conf;
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) { if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
throw new Error('<adg-table> "cells-text", "cells-name", "api-name"' throw new Error('<adg-table> "cells-text", "cells-name", "api-name"'
+ ' and "is-wrappable" attributes must be defined'); + ' and "is-wrappable" attributes must be defined');
} }
tableConfig[attrs.tableId] = {}; tableConfig[attrs.tableId] = {};
tableConfig[attrs.tableId].filters = {}; conf = tableConfig[attrs.tableId];
conf.filters = {};
conf.additionnalQueryFields = {};
tableConfig[attrs.tableId].cells = { 'text': [], 'name': [] }; conf.cells = { 'text': [], 'name': [] };
tableConfig[attrs.tableId].cells.text = attrs.cellsText.split(','); conf.cells.text = attrs.cellsText.split(',');
tableConfig[attrs.tableId].cells.name = attrs.cellsName.split(','); conf.cells.name = attrs.cellsName.split(',');
tableConfig[attrs.tableId].apiName = attrs.apiName; conf.apiName = attrs.apiName;
tableConfig[attrs.tableId].isWrappable = false; conf.isWrappable = JSON.parse(attrs.isWrappable);
tableConfig[attrs.tableId].isWrappable = attrs.isWrappable; conf.noRepeatCell = attrs.noRepeatCell;
tableConfig[attrs.tableId].noRepeatCell = attrs.noRepeatCell; conf.tableId = attrs.tableId;
tableConfig[attrs.tableId].tableId = attrs.tableId;
if (!!attrs.filters) {
conf.filters = JSON.parse(attrs.filters);
}
if (!!attrs.additionnalQueryFields) {
conf.additionnalQueryFields = JSON.parse(attrs.additionnalQueryFields);
}
if (!!attrs.refreshInterval) { if (!!attrs.refreshInterval) {
tableConfig.refreshInterval = attrs.refreshInterval; tableConfig.refreshInterval = attrs.refreshInterval;
} }
if (!!attrs.filters) {
tableConfig[attrs.tableId].filters = attrs.filters;
}
var template = 'components/table/table.html';
$http.get(template, { cache: true }) $http.get(template, { cache: true })
.success(function (data) { .success(function (data) {
@ -134,6 +142,7 @@ angular.module('adagios.table', ['adagios.live',
this.Filters = config.filters; this.Filters = config.filters;
this.IsWrappable = config.isWrappable; this.IsWrappable = config.isWrappable;
this.NoRepeatCell = config.noRepeatCell; this.NoRepeatCell = config.noRepeatCell;
this.additionnalQueryFields = config.additionnalQueryFields;
}) })
.filter('wrappableStyle', ['tableConfig', function (tableConfig) { .filter('wrappableStyle', ['tableConfig', function (tableConfig) {

View File

@ -40,9 +40,12 @@
<div role="tabpanel" class="problems tab-pane active" id="openProblems"> <div role="tabpanel" class="problems tab-pane active" id="openProblems">
<header class="main__content__header clearfix"> <header class="main__content__header clearfix">
<h2 class="main__content__title">{{dashboardTables[0].title}}</h2> <h2 class="main__content__title">{{dashboardTables[0].title}}</h2>
<p class="main__content__alert state--error">There are {{nbHostProblems}} host problems.</p> <p class="main__content__alert state--error">
There are {{nbHostOpenProblems}} host
<ng-pluralize count="nbHostOpenProblems" when="{'0':'problem', '1': 'problem', 'other': 'problems'}"/>
</p>
</header> </header>
<adg-table cells-text="{{dashboardTables[0].CellsText}}" <adg-table cells-text="{{dashboardTables[0].CellsText}}"
cells-name="{{dashboardTables[0].CellsName}}" cells-name="{{dashboardTables[0].CellsName}}"
api-name="{{dashboardTables[0].ApiName}}" api-name="{{dashboardTables[0].ApiName}}"
@ -50,16 +53,17 @@
is-wrappable="{{dashboardTables[0].IsWrappable}}" is-wrappable="{{dashboardTables[0].IsWrappable}}"
no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}" no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}"
refresh-interval="{{dashboardRefreshInterval}}" refresh-interval="{{dashboardRefreshInterval}}"
additionnal-query-fields="{{dashboardTables[0].additionnalQueryFields}}"
table-id="0"></adg-table> table-id="0"></adg-table>
</div>
<div role="tabpanel" class="problems tab-pane active" id="openProblems">
<header class="main__content__header clearfix"> <header class="main__content__header clearfix">
<h2 class="main__content__title">{{dashboardTables[1].title}}</h2> <h2 class="main__content__title">{{dashboardTables[1].title}}</h2>
<p class="main__content__alert state--error">There are {{nbHostProblems}} host problems.</p> <p class="main__content__alert state--error">
There are {{nbServiceOpenProblems}} host
<ng-pluralize count="nbServiceOpenProblems" when="{'0':'problem', '1': 'problem', 'other': 'problems'}"/>
</p>
</header> </header>
<adg-table cells-text="{{dashboardTables[1].CellsText}}" <adg-table cells-text="{{dashboardTables[1].CellsText}}"
cells-name="{{dashboardTables[1].CellsName}}" cells-name="{{dashboardTables[1].CellsName}}"
api-name="{{dashboardTables[1].ApiName}}" api-name="{{dashboardTables[1].ApiName}}"
@ -67,17 +71,45 @@
is-wrappable="{{dashboardTables[1].IsWrappable}}" is-wrappable="{{dashboardTables[1].IsWrappable}}"
no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}" no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}"
refresh-interval="{{dashboardRefreshInterval}}" refresh-interval="{{dashboardRefreshInterval}}"
additionnal-query-fields="{{dashboardTables[1].additionnalQueryFields}}"
table-id="1"></adg-table> table-id="1"></adg-table>
</div> </div>
<div role="tabpanel" class="problems tab-pane" id="allProblems"> <div role="tabpanel" class="problems tab-pane" id="allProblems">
<header class="main__content__header clearfix"> <header class="main__content__header clearfix">
<h2 class="main__content__title">{{dashboardTables[1].title}}</h2> <h2 class="main__content__title">{{dashboardTables[2].title}}</h2>
<p class="main__content__alert state--error">There are {{nbHostProblems}} host problems.</p> <p class="main__content__alert state--error">
There are {{nbHostProblems}} host
<ng-pluralize count="nbHostProblems" when="{'0':'problem', '1': 'problem', 'other': 'problems'}"/>
</p>
</header> </header>
<p>Pas de tableaux encore pour All problems.</p> <adg-table cells-text="{{dashboardTables[2].CellsText}}"
cells-name="{{dashboardTables[2].CellsName}}"
api-name="{{dashboardTables[2].ApiName}}"
filters="{{dashboardTables[2].Filters}}"
is-wrappable="{{dashboardTables[2].IsWrappable}}"
no-repeat-cell="{{dashboardTables[2].NoRepeatCell}}"
refresh-interval="{{dashboardRefreshInterval}}"
table-id="2"></adg-table>
<header class="main__content__header clearfix">
<h2 class="main__content__title">{{dashboardTables[3].title}}</h2>
<p class="main__content__alert state--error">
There are {{nbServiceProblems}} service
<ng-pluralize count="nbServiceProblems" when="{'0':'problem', '1': 'problem', 'other': 'problems'}"/>
</p>
</header>
<adg-table cells-text="{{dashboardTables[3].CellsText}}"
cells-name="{{dashboardTables[3].CellsName}}"
api-name="{{dashboardTables[3].ApiName}}"
filters="{{dashboardTables[3].Filters}}"
is-wrappable="{{dashboardTables[3].IsWrappable}}"
no-repeat-cell="{{dashboardTables[3].NoRepeatCell}}"
refresh-interval="{{dashboardRefreshInterval}}"
table-id="3"></adg-table>
</div> </div>
</div> </div>

View File

@ -15,13 +15,12 @@ angular.module('adagios.view.dashboard', ['ngRoute',
}); });
}]) }])
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices', 'tableConfig', 'TableConfigObj', 'TacticalConfigObj', .controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices', 'tableConfig',
function ($scope, $routeParams, dashboardConfig, getServices, tableConfig, TableConfigObj, TacticalConfigObj) { 'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems',
'getServiceProblems',
var fields = ['state'], function ($scope, $routeParams, dashboardConfig, getServices, tableConfig, TableConfigObj,
filters = {'isnot' : { 'state' : ['0'] }}, TacticalConfigObj, getHostOpenProblems, getServiceOpenProblems, getHostProblems, getServiceProblems) {
apiName = 'hosts', var components = [],
components = [],
component, component,
config, config,
viewName, viewName,
@ -55,10 +54,21 @@ angular.module('adagios.view.dashboard', ['ngRoute',
} }
} }
getServices(fields, filters, apiName) getHostOpenProblems.success(function (data) {
.success(function (data) { $scope.nbHostOpenProblems = data.length;
$scope.nbHostProblems = data.length; });
});
getServiceOpenProblems.success(function (data) {
$scope.nbServiceOpenProblems = data.length;
});
getHostProblems.success(function (data) {
$scope.nbHostProblems = data.length;
});
getServiceProblems.success(function (data) {
$scope.nbServiceProblems = data.length;
});
}]) }])
.run(['readConfig', 'dashboardConfig', function (readConfig, dashboardConfig) { .run(['readConfig', 'dashboardConfig', function (readConfig, dashboardConfig) {