Merge pull request #39 from Freddrickk/dashFix
Dashboard displays real number of problems
This commit is contained in:
commit
cba41216de
@ -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",
|
||||
"config": {
|
||||
|
@ -12,10 +12,11 @@ angular.module('adagios.live')
|
||||
regex: '__regex'
|
||||
})
|
||||
|
||||
.factory('getServices', ['$http', 'filterSuffixes',
|
||||
.service('getServices', ['$http', 'filterSuffixes',
|
||||
function ($http, filterSuffixes) {
|
||||
return function (columns, filters, apiName) {
|
||||
var filtersQuery = '';
|
||||
return function (columns, filters, apiName, additionnalFields) {
|
||||
var filtersQuery = '',
|
||||
additionnalQuery = '';
|
||||
|
||||
function createFiltersQuery(filters) {
|
||||
var builtQuery = '';
|
||||
@ -33,11 +34,77 @@ angular.module('adagios.live')
|
||||
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 () {
|
||||
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');
|
||||
});
|
||||
}]);
|
||||
|
@ -16,9 +16,9 @@ angular.module('adagios.table.cell_host_status', ['adagios.table'])
|
||||
$scope.alert_level = "alert alert-danger";
|
||||
|
||||
if ($scope.entry.childs.length !== 0) {
|
||||
$scope.entry.host_status = "Network outage";
|
||||
} else {
|
||||
$scope.entry.host_status = "Host down";
|
||||
} else {
|
||||
$scope.entry.host_status = "Network outage";
|
||||
}
|
||||
}
|
||||
}])
|
||||
|
@ -6,11 +6,11 @@ angular.module('adagios.table.cell_hosts_host', ['adagios.table'])
|
||||
if ($scope.entry.state === 0) {
|
||||
$scope.state = 'state--ok';
|
||||
} else if ($scope.entry.state === 1) {
|
||||
$scope.state = 'state--warning';
|
||||
$scope.state = 'state--error';
|
||||
} else if ($scope.entry.state === "") {
|
||||
$scope.state = '';
|
||||
} else {
|
||||
$scope.state = 'state--error';
|
||||
$scope.state = 'state--unreachable';
|
||||
}
|
||||
}])
|
||||
|
||||
|
@ -16,8 +16,8 @@ angular.module('adagios.table', ['adagios.live',
|
||||
|
||||
.controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'actionbarFilters',
|
||||
function ($scope, $interval, getServices, tableConfig, actionbarFilters) {
|
||||
console.log(tableConfig[tableConfig.index].additionnalQueryFields);
|
||||
var requestFields = [],
|
||||
filters = JSON.parse(tableConfig[tableConfig.index].filters),
|
||||
conf = tableConfig[tableConfig.index],
|
||||
getData,
|
||||
i;
|
||||
@ -36,18 +36,19 @@ angular.module('adagios.table', ['adagios.live',
|
||||
});
|
||||
});
|
||||
|
||||
getData = function (requestFields, filters, apiName) {
|
||||
getServices(requestFields, filters, apiName)
|
||||
getData = function (requestFields, filters, apiName, additionnalFields) {
|
||||
console.log(additionnalFields);
|
||||
getServices(requestFields, filters, apiName, additionnalFields)
|
||||
.success(function (data) {
|
||||
$scope.entries = data;
|
||||
});
|
||||
};
|
||||
|
||||
getData(requestFields, filters, conf.apiName);
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
|
||||
if (tableConfig.refreshInterval !== '0') {
|
||||
$interval(function () {
|
||||
getData(requestFields, filters, conf.apiName);
|
||||
getData(requestFields, conf.filters, conf.apiName, conf.additionnalQueryFields);
|
||||
}, tableConfig.refreshInterval);
|
||||
}
|
||||
|
||||
@ -64,34 +65,41 @@ angular.module('adagios.table', ['adagios.live',
|
||||
compile: function () {
|
||||
return function (scope, element, attrs) {
|
||||
|
||||
var template = 'components/table/table.html',
|
||||
conf;
|
||||
|
||||
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
|
||||
throw new Error('<adg-table> "cells-text", "cells-name", "api-name"'
|
||||
+ ' and "is-wrappable" attributes must be defined');
|
||||
}
|
||||
|
||||
tableConfig[attrs.tableId] = {};
|
||||
tableConfig[attrs.tableId].filters = {};
|
||||
conf = tableConfig[attrs.tableId];
|
||||
conf.filters = {};
|
||||
conf.additionnalQueryFields = {};
|
||||
|
||||
tableConfig[attrs.tableId].cells = { 'text': [], 'name': [] };
|
||||
tableConfig[attrs.tableId].cells.text = attrs.cellsText.split(',');
|
||||
tableConfig[attrs.tableId].cells.name = attrs.cellsName.split(',');
|
||||
conf.cells = { 'text': [], 'name': [] };
|
||||
conf.cells.text = attrs.cellsText.split(',');
|
||||
conf.cells.name = attrs.cellsName.split(',');
|
||||
|
||||
tableConfig[attrs.tableId].apiName = attrs.apiName;
|
||||
conf.apiName = attrs.apiName;
|
||||
|
||||
tableConfig[attrs.tableId].isWrappable = false;
|
||||
tableConfig[attrs.tableId].isWrappable = attrs.isWrappable;
|
||||
tableConfig[attrs.tableId].noRepeatCell = attrs.noRepeatCell;
|
||||
tableConfig[attrs.tableId].tableId = attrs.tableId;
|
||||
conf.isWrappable = JSON.parse(attrs.isWrappable);
|
||||
conf.noRepeatCell = attrs.noRepeatCell;
|
||||
conf.tableId = attrs.tableId;
|
||||
|
||||
if (!!attrs.filters) {
|
||||
conf.filters = JSON.parse(attrs.filters);
|
||||
}
|
||||
|
||||
if (!!attrs.additionnalQueryFields) {
|
||||
conf.additionnalQueryFields = JSON.parse(attrs.additionnalQueryFields);
|
||||
}
|
||||
|
||||
if (!!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 })
|
||||
.success(function (data) {
|
||||
@ -134,6 +142,7 @@ angular.module('adagios.table', ['adagios.live',
|
||||
this.Filters = config.filters;
|
||||
this.IsWrappable = config.isWrappable;
|
||||
this.NoRepeatCell = config.noRepeatCell;
|
||||
this.additionnalQueryFields = config.additionnalQueryFields;
|
||||
})
|
||||
|
||||
.filter('wrappableStyle', ['tableConfig', function (tableConfig) {
|
||||
|
@ -40,7 +40,10 @@
|
||||
<div role="tabpanel" class="problems tab-pane active" id="openProblems">
|
||||
<header class="main__content__header clearfix">
|
||||
<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>
|
||||
|
||||
<adg-table cells-text="{{dashboardTables[0].CellsText}}"
|
||||
@ -50,16 +53,17 @@
|
||||
is-wrappable="{{dashboardTables[0].IsWrappable}}"
|
||||
no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}"
|
||||
refresh-interval="{{dashboardRefreshInterval}}"
|
||||
additionnal-query-fields="{{dashboardTables[0].additionnalQueryFields}}"
|
||||
table-id="0"></adg-table>
|
||||
</div>
|
||||
|
||||
<div role="tabpanel" class="problems tab-pane active" id="openProblems">
|
||||
<header class="main__content__header clearfix">
|
||||
<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>
|
||||
|
||||
|
||||
<adg-table cells-text="{{dashboardTables[1].CellsText}}"
|
||||
cells-name="{{dashboardTables[1].CellsName}}"
|
||||
api-name="{{dashboardTables[1].ApiName}}"
|
||||
@ -67,17 +71,45 @@
|
||||
is-wrappable="{{dashboardTables[1].IsWrappable}}"
|
||||
no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}"
|
||||
refresh-interval="{{dashboardRefreshInterval}}"
|
||||
additionnal-query-fields="{{dashboardTables[1].additionnalQueryFields}}"
|
||||
table-id="1"></adg-table>
|
||||
|
||||
</div>
|
||||
|
||||
<div role="tabpanel" class="problems tab-pane" id="allProblems">
|
||||
<header class="main__content__header clearfix">
|
||||
<h2 class="main__content__title">{{dashboardTables[1].title}}</h2>
|
||||
<p class="main__content__alert state--error">There are {{nbHostProblems}} host problems.</p>
|
||||
<h2 class="main__content__title">{{dashboardTables[2].title}}</h2>
|
||||
<p class="main__content__alert state--error">
|
||||
There are {{nbHostProblems}} host
|
||||
<ng-pluralize count="nbHostProblems" when="{'0':'problem', '1': 'problem', 'other': 'problems'}"/>
|
||||
</p>
|
||||
</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>
|
||||
|
||||
|
@ -15,13 +15,12 @@ angular.module('adagios.view.dashboard', ['ngRoute',
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices', 'tableConfig', 'TableConfigObj', 'TacticalConfigObj',
|
||||
function ($scope, $routeParams, dashboardConfig, getServices, tableConfig, TableConfigObj, TacticalConfigObj) {
|
||||
|
||||
var fields = ['state'],
|
||||
filters = {'isnot' : { 'state' : ['0'] }},
|
||||
apiName = 'hosts',
|
||||
components = [],
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices', 'tableConfig',
|
||||
'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems',
|
||||
'getServiceProblems',
|
||||
function ($scope, $routeParams, dashboardConfig, getServices, tableConfig, TableConfigObj,
|
||||
TacticalConfigObj, getHostOpenProblems, getServiceOpenProblems, getHostProblems, getServiceProblems) {
|
||||
var components = [],
|
||||
component,
|
||||
config,
|
||||
viewName,
|
||||
@ -55,10 +54,21 @@ angular.module('adagios.view.dashboard', ['ngRoute',
|
||||
}
|
||||
}
|
||||
|
||||
getServices(fields, filters, apiName)
|
||||
.success(function (data) {
|
||||
getHostOpenProblems.success(function (data) {
|
||||
$scope.nbHostOpenProblems = 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user