Major refactoring of surveil backend

This commit is contained in:
Vincent Fournier 2015-04-30 14:55:32 -04:00
parent f44133ec78
commit 67c8f3051b
11 changed files with 223 additions and 189 deletions

View File

@ -9,7 +9,7 @@ angular.module('bansho.host', ['bansho.live',
.value('hostConfig', {}) .value('hostConfig', {})
.controller('HostCtrl', ['$scope', 'hostConfig', 'getHost', function ($scope, hostConfig, getHost) { .controller('HostCtrl', ['$scope', 'hostConfig', 'backendClient', function ($scope, hostConfig, backendClient) {
var objectType = 'host', var objectType = 'host',
objectIdentifier = {}; objectIdentifier = {};
@ -17,7 +17,7 @@ angular.module('bansho.host', ['bansho.live',
$scope.hostName = hostConfig.hostName; $scope.hostName = hostConfig.hostName;
$scope.data = {}; $scope.data = {};
getHost(objectType, objectIdentifier).then(function (data) { backendClient.getHost(objectType, objectIdentifier).then(function (data) {
$scope.data = data; $scope.data = data;
}); });
}]) }])

View File

@ -2,7 +2,7 @@
angular.module('bansho.host.cpu', ['bansho.live']) angular.module('bansho.host.cpu', ['bansho.live'])
.controller('HostCpuCtrl', ['$scope', 'getObjects', function ($scope, getObjects) { .controller('HostCpuCtrl', ['$scope', 'backendClient', function ($scope, backendClient) {
var hostName = $scope.hostName, var hostName = $scope.hostName,
service = 'cpu', service = 'cpu',
fields = ['state', 'description', 'plugin_output'], fields = ['state', 'description', 'plugin_output'],
@ -10,7 +10,7 @@ angular.module('bansho.host.cpu', ['bansho.live'])
apiName = 'services', apiName = 'services',
additionnalFields = {'host_name': hostName, 'description': service}; additionnalFields = {'host_name': hostName, 'description': service};
getObjects(fields, filters, apiName, additionnalFields) backendClient.getObjects(fields, filters, apiName, additionnalFields)
.success(function (data) { .success(function (data) {
$scope.cpuData = data[0]; $scope.cpuData = data[0];
}); });

View File

@ -2,7 +2,7 @@
angular.module('bansho.host.load', []) angular.module('bansho.host.load', [])
.controller('HostLoadCtrl', ['$scope', 'getObjects', function ($scope, getObjects) { .controller('HostLoadCtrl', ['$scope', 'backendClient', function ($scope, backendClient) {
var hostName = $scope.hostName, var hostName = $scope.hostName,
service = 'load', service = 'load',
fields = ['state', 'description', 'plugin_output'], fields = ['state', 'description', 'plugin_output'],
@ -10,7 +10,7 @@ angular.module('bansho.host.load', [])
apiName = 'services', apiName = 'services',
additionnalFields = {'host_name': hostName, 'description': service}; additionnalFields = {'host_name': hostName, 'description': service};
getObjects(fields, filters, apiName, additionnalFields) backendClient.getObjects(fields, filters, apiName, additionnalFields)
.success(function (data) { .success(function (data) {
$scope.loadData = data[0]; $scope.loadData = data[0];
}); });

View File

@ -12,6 +12,64 @@ angular.module('bansho.live', [])
regex: '__regex' regex: '__regex'
}) })
.service('backendClient', ['$http', 'filterSuffixes', 'hostMiddleware', function ($http, filterSuffixes, hostMiddleware) {
this.getObjects = function (fields, filters, apiName, additionnalFields) {
var filtersQuery = '',
additionnalQuery = '';
function createFiltersQuery(filters) {
var builtQuery = '';
angular.forEach(filters, function (value, key) {
var filterType = filterSuffixes[key];
angular.forEach(value, function (fieldValues, fieldName) {
var filter = fieldName + filterType;
angular.forEach(fieldValues, function (_value) {
var filterQuery = '&' + filter + '=' + _value;
builtQuery += filterQuery;
});
});
});
return builtQuery;
}
function createAdditionnalQuery(additionnalFields) {
var query = '';
angular.forEach(additionnalFields, function (value, key) {
query += '&' + key + '=' + value;
});
return query;
}
filtersQuery = createFiltersQuery(filters);
additionnalQuery = createAdditionnalQuery(additionnalFields);
function appendTransform(defaults, transform) {
// We can't guarantee that the default transformation is an array
defaults = angular.isArray(defaults) ? defaults : [defaults];
return defaults.concat(transform);
};
function transformations(data) {
if (apiName === 'hosts') {
hostMiddleware(data);
}
return data;
}
return $http({
url: '/adagios/rest/status/json/' + apiName + '/?fields=' + fields + filtersQuery + additionnalQuery,
method: 'GET',
transformResponse: appendTransform($http.defaults.transformResponse, transformations)
}).error(function () {
throw new Error('getObjects : GET Request failed');
});
};
}])
.service('getObjects', ['$http', 'filterSuffixes', 'hostMiddleware', .service('getObjects', ['$http', 'filterSuffixes', 'hostMiddleware',
function ($http, filterSuffixes, hostMiddleware) { function ($http, filterSuffixes, hostMiddleware) {
return function (fields, filters, apiName, additionnalFields) { return function (fields, filters, apiName, additionnalFields) {

View File

@ -1,13 +1,12 @@
'use strict'; 'use strict';
angular.module('bansho.live', []) angular.module('bansho.live', [])
.service('backendClient', ['$http', '$q',
.service('getObjects', ['$http', 'hostQueryTransform', 'hostMiddleware', 'serviceMiddleware', function ($http, $q) {
function ($http, hostQueryTransform, hostMiddleware, serviceMiddleware) { var getObjects = function (fields, filters, apiName, additionnalFields) {
return function (fields, filters, apiName, additionnalFields) {
var query = {}, var query = {},
transformations; transformations;
// Merges additionnalFields into filters as 'is' filter // Merges additionnalFields into filters as 'is' filter
angular.forEach(additionnalFields, function (value, key) { angular.forEach(additionnalFields, function (value, key) {
if (!('is' in filters)) { if (!('is' in filters)) {
@ -19,7 +18,7 @@ angular.module('bansho.live', [])
} }
filters.is[key].push(value); filters.is[key].push(value);
}) });
function appendTransform(defaults, transform) { function appendTransform(defaults, transform) {
// We can't guarantee that the default transformation is an array // We can't guarantee that the default transformation is an array
@ -55,26 +54,20 @@ angular.module('bansho.live', [])
throw new Error('getObjects : POST Request failed'); throw new Error('getObjects : POST Request failed');
}); });
}; };
}])
.service('getService', ['$http', 'getObjects',
function ($http, getObjects) { var getService = function (hostName, description) {
return function (hostName, description) {
var fields = [], var fields = [],
filters = {}, filters = {},
additionnalFields = { 'host_name': hostName, 'description': description }; additionnalFields = {'host_name': hostName, 'description': description};
return getObjects(fields, filters, 'services', additionnalFields) return this.getObjects(fields, filters, 'services', additionnalFields)
.error(function () { .error(function () {
throw new Error('getService : POST Request failed'); throw new Error('getService : POST Request failed');
}); });
}; };
}])
// This service is used to count the number of host open problems var getHostOpenProblems = function () {
.service('getHostOpenProblems', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['state'], var fields = ['state'],
filters = {}, filters = {},
apiName = 'hosts', apiName = 'hosts',
@ -85,17 +78,13 @@ angular.module('bansho.live', [])
throw new Error('getHostOpenProblems : POST Request failed'); throw new Error('getHostOpenProblems : POST Request failed');
}); });
}; };
}])
// This service is used to count the number of service open problems var getServiceOpenProblems = function () {
.service('getServiceOpenProblems', ['$http', '$q', 'getObjects',
function ($http, $q, getObjects) {
return function () {
var serviceFields = ['host_name', 'state'], var serviceFields = ['host_name', 'state'],
serviceFilters = { 'isnot': { 'state': [0] } }, serviceFilters = {'isnot': {'state': [0]}},
serviceAdditionnalFields = { 'acknowledged': 0 }, serviceAdditionnalFields = {'acknowledged': 0},
hostFields = ['host_name', 'state'], hostFields = ['host_name', 'state'],
hostFilters = { 'isnot': { 'state': [2] } }, hostFilters = {'isnot': {'state': [2]}},
hostAdditionnalFields = {}, hostAdditionnalFields = {},
responsePromise = $q.defer(); responsePromise = $q.defer();
@ -113,7 +102,7 @@ angular.module('bansho.live', [])
.success(function (serviceData) { .success(function (serviceData) {
var result = []; var result = [];
for (i = 0; i < serviceData.length; i += 1) { for (i = 0; i < serviceData.length; i += 1) {
if (serviceData[i].host_name in hostsResult) { if (serviceData[i].host_name in hostsResult) {
result.push(serviceData[i]); result.push(serviceData[i]);
} }
} }
@ -122,15 +111,11 @@ angular.module('bansho.live', [])
}); });
return responsePromise.promise; return responsePromise.promise;
}; }
}])
// This service is used to count the number of host problems var getHostProblems = function () {
.service('getHostProblems', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['state'], var fields = ['state'],
filters = { 'isnot': {'state': [0]} }, filters = {'isnot': {'state': [0]}},
apiName = 'hosts', apiName = 'hosts',
additionnalFields = {}; additionnalFields = {};
@ -139,14 +124,11 @@ angular.module('bansho.live', [])
throw new Error('getHostProblems : POST Request failed'); throw new Error('getHostProblems : POST Request failed');
}); });
}; };
}])
// This service is used to count the number of service problems // This service is used to count the number of service problems
.service('getServiceProblems', ['$http', 'getObjects', var getServiceProblems = function () {
function ($http, getObjects) {
return function () {
var fields = ['state'], var fields = ['state'],
filters = { 'isnot': {'state': [0]} }, filters = {'isnot': {'state': [0]}},
apiName = 'services', apiName = 'services',
additionnalFields = {}; additionnalFields = {};
@ -154,13 +136,10 @@ angular.module('bansho.live', [])
.error(function () { .error(function () {
throw new Error('getServiceOpenProblems : POST Request failed'); throw new Error('getServiceOpenProblems : POST Request failed');
}); });
}; }
}])
// This service is used to count the number of hosts // This service is used to count the number of hosts
.service('getTotalHosts', ['$http', 'getObjects', var getTotalHosts = function () {
function ($http, getObjects) {
return function () {
var fields = ['host_name'], var fields = ['host_name'],
filters = {}, filters = {},
apiName = 'hosts', apiName = 'hosts',
@ -170,13 +149,10 @@ angular.module('bansho.live', [])
.error(function () { .error(function () {
throw new Error('getTotalHosts : POST Request failed'); throw new Error('getTotalHosts : POST Request failed');
}); });
}; }
}])
// This service is used to count the number of services // This service is used to count the number of services
.service('getTotalServices', ['$http', 'getObjects', var getTotalServices = function () {
function ($http, getObjects) {
return function () {
var fields = ['host_name'], var fields = ['host_name'],
filters = {}, filters = {},
apiName = 'services', apiName = 'services',
@ -186,95 +162,83 @@ angular.module('bansho.live', [])
.error(function () { .error(function () {
throw new Error('getTotalServices : POST Request failed'); throw new Error('getTotalServices : POST Request failed');
}); });
}; }
}])
.service('getHost', ['$http', '$q', function ($http, $q) { var getHost = function (objectType, objectIdentifier) {
return function (objectType, objectIdentifier) { var objectData = {},
var objectData = {}, endpoints = {
endpoints = { "host": "hosts",
"host" : "hosts", "service": "services"
"service" : "services" },
}, liveUrl = '/surveil/v2/status/' + endpoints[objectType] + '/' + objectIdentifier.host_name + '/',
liveUrl = '/surveil/v2/status/' + endpoints[objectType] + '/' + objectIdentifier.host_name + '/', configUrl = '/surveil/v2/config/' + endpoints[objectType] + '/' + objectIdentifier.host_name + '/',
configUrl = '/surveil/v2/config/'+ endpoints[objectType] + '/' + objectIdentifier.host_name + '/', responsePromise = $q.defer();
responsePromise = $q.defer();
$http.get(liveUrl) .success(function (liveData) { $http.get(liveUrl).success(function (liveData) {
$http.get(configUrl).success(function (configData) { $http.get(configUrl).success(function (configData) {
objectData.live = liveData; objectData.live = liveData;
objectData.config = configData; objectData.config = configData;
responsePromise.resolve(objectData); responsePromise.resolve(objectData);
}) })
}); });
return responsePromise.promise; return responsePromise.promise;
}; }
}])
.service('hostQueryTransform', function () { var hostQueryTransform = function (fields, filters) {
return function (fields, filters) { var i,
var i, transformations = {
transformations = { 'host_state': 'state',
'host_state': 'state', };
};
for (i = 0; i < fields.length; i += 1) { for (i = 0; i < fields.length; i += 1) {
if (fields[i] in transformations) { if (fields[i] in transformations) {
fields[i] = transformations[fields[i]]; fields[i] = transformations[fields[i]];
}
} }
} }
}
})
// Modify response object to conform to web ui // Modify response object to conform to web ui
.service('hostMiddleware', function() { var hostMiddleware = function (data) {
return function (data) { var i = 0,
var i = 0, conversions = {
conversions = { 'state': 'host_state'
'state': 'host_state' };
};
for (i = 0; i < data.length; i += 1) { for (i = 0; i < data.length; i += 1) {
angular.forEach(data[i], function (value, field) { angular.forEach(data[i], function (value, field) {
if (field in conversions) { if (field in conversions) {
data[i][conversions[field]] = value; data[i][conversions[field]] = value;
delete data[i][field]; delete data[i][field];
} }
}); });
} }
return data;
};
})
// Modify response object to conform to web ui
.service('serviceMiddleware', function() {
return function (data) {
var i = 0,
conversions = {
};
if (jQuery.isEmptyObject(conversions)) {
return data; return data;
} }
for (i = 0; i < data.length; i += 1) { // Modify response object to conform to web ui
angular.forEach(data[i], function (value, field) { var serviceMiddleware = function (data) {
if (field in conversions) { var i = 0,
data[i][conversions[field]] = value; conversions = {};
delete data[i][field];
}
});
}
return data; if (jQuery.isEmptyObject(conversions)) {
}; return data;
}) }
.service('getTableData', ['$q', 'getObjects', for (i = 0; i < data.length; i += 1) {
function ($q, getObjects) { angular.forEach(data[i], function (value, field) {
return function (fields, filters, apiName, additionnalFields) { if (field in conversions) {
data[i][conversions[field]] = value;
delete data[i][field];
}
});
}
return data;
};
var getTableData = function (fields, filters, apiName, additionnalFields) {
var hostFields = [], var hostFields = [],
serviceFields = [], serviceFields = [],
hostFilters = {}, hostFilters = {},
@ -291,13 +255,13 @@ angular.module('bansho.live', [])
found = false; found = false;
if (apiName === 'hosts') { if (apiName === 'hosts') {
getObjects(fields, filters, 'hosts', additionnalFields) this.getObjects(fields, filters, 'hosts', additionnalFields)
.success(function (data) { .success(function (data) {
responsePromise.resolve(data); responsePromise.resolve(data);
}); });
return responsePromise.promise; return responsePromise.promise;
} }
angular.forEach(fields, function (field) { angular.forEach(fields, function (field) {
if (field in hostKeys) { if (field in hostKeys) {
hostFields.push(hostKeys[field]); hostFields.push(hostKeys[field]);
@ -355,7 +319,7 @@ angular.module('bansho.live', [])
hostDict[host_name] = {}; hostDict[host_name] = {};
} }
hostDict[host_name][field] = value; hostDict[host_name][field] = value;
}); });
} }
@ -371,30 +335,45 @@ angular.module('bansho.live', [])
}); });
return responsePromise.promise; return responsePromise.promise;
};
}])
.service('acknowledge', ['$http', function($http) {
return function (host_name, service_description, attrs) {
var data = {};
data.host_name = host_name;
data.author = attrs.author;
data.comment = attrs.comment;
data.sticky = parseInt(attrs.sticky, 10);
data.notify = parseInt(attrs.notify, 10);
data.persistent = parseInt(attrs.persistent, 10);
if (service_description !== undefined) {
data.service_description = service_description;
} }
return $http({ var acknowledge = function (host_name, service_description, attrs) {
url: '/surveil/v2/actions/acknowledge/', var data = {};
method: 'POST',
data: data, data.host_name = host_name;
}).error(function () { data.author = attrs.author;
throw new Error('acknowledge : POST Request failed'); data.comment = attrs.comment;
}); data.sticky = parseInt(attrs.sticky, 10);
}; data.notify = parseInt(attrs.notify, 10);
}]) data.persistent = parseInt(attrs.persistent, 10);
if (service_description !== undefined) {
data.service_description = service_description;
}
return $http({
url: '/surveil/v2/actions/acknowledge/',
method: 'POST',
data: data
}).error(function () {
throw new Error('acknowledge : POST Request failed');
});
}
return {
getHost: getHost,
getObjects : getObjects,
getService : getService,
hostQueryTransform: hostQueryTransform,
acknowledge: acknowledge,
getHostOpenProblems: getHostOpenProblems,
hostMiddleware: hostMiddleware,
getServiceProblems: getServiceProblems,
getServiceOpenProblems: getServiceOpenProblems,
getHostProblems: getHostProblems,
getTableData: getTableData,
getTotalHosts: getTotalHosts,
getTotalServices: getTotalServices
}
}]);

View File

@ -7,12 +7,12 @@ angular.module('bansho.service', ['bansho.live',
.value('serviceConfig', {}) .value('serviceConfig', {})
.controller('ServiceCtrl', ['$scope', 'serviceConfig', 'getService', .controller('ServiceCtrl', ['$scope', 'serviceConfig', 'backendClient',
function ($scope, serviceConfig, getService) { function ($scope, serviceConfig, backendClient) {
var hostName = serviceConfig.hostName, var hostName = serviceConfig.hostName,
description = serviceConfig.description; description = serviceConfig.description;
getService(hostName, description).success(function (data) { backendClient.getService(hostName, description).success(function (data) {
$scope.data = data; $scope.data = data;
}); });
}]) }])

View File

@ -28,8 +28,8 @@ angular.module('bansho.table.actionbar', ['bansho.table',
return actionbarFilters; return actionbarFilters;
}) })
.controller('TableActionbarCtrl', ['$scope', '$filter', 'acknowledge', 'actionbarFilters', 'tablesConfig', .controller('TableActionbarCtrl', ['$scope', '$filter', 'backendClient', 'actionbarFilters', 'tablesConfig',
function ($scope, $filter, acknowledge, actionbarFilters, tablesConfig, actionbarSelectFilter) { function ($scope, $filter, backendClient, actionbarFilters, tablesConfig, actionbarSelectFilter) {
$scope.actionbarFilters = actionbarFilters; $scope.actionbarFilters = actionbarFilters;
$scope.actionbarFilters.activeFilter = $scope.actionbarFilters.possibleFilters[0]; $scope.actionbarFilters.activeFilter = $scope.actionbarFilters.possibleFilters[0];
$scope.ackFormIsOpen = false; $scope.ackFormIsOpen = false;
@ -54,7 +54,7 @@ angular.module('bansho.table.actionbar', ['bansho.table',
service_description = entry.description; service_description = entry.description;
} }
acknowledge(entry.host_name, service_description, $scope.acknowledgeData) backendClient.acknowledge(entry.host_name, service_description, $scope.acknowledgeData)
.error(function (data) { .error(function (data) {
throw new Error('Acknowledge request failed'); throw new Error('Acknowledge request failed');
}); });

View File

@ -16,9 +16,9 @@ angular.module('bansho.table', ['bansho.live',
.value('tablesConfig', []) .value('tablesConfig', [])
.controller('TableCtrl', ['$scope', '$interval', 'getTableData', 'tablesConfig', .controller('TableCtrl', ['$scope', '$interval', 'backendClient', 'tablesConfig',
'actionbarFilters', 'promisesManager', 'tableGlobalConfig', 'actionbarFilters', 'promisesManager', 'tableGlobalConfig',
function ($scope, $interval, getTableData, tablesConfig, actionbarFilters, promisesManager, tableGlobalConfig) { function ($scope, $interval, backendClient, tablesConfig, actionbarFilters, promisesManager, tableGlobalConfig) {
var requestFields = [], var requestFields = [],
conf = tablesConfig[tableGlobalConfig.nextTableIndex], conf = tablesConfig[tableGlobalConfig.nextTableIndex],
getData, getData,
@ -39,7 +39,7 @@ angular.module('bansho.table', ['bansho.live',
}); });
getData = function (requestFields, filters, apiName, additionnalFields) { getData = function (requestFields, filters, apiName, additionnalFields) {
var promise = getTableData(requestFields, filters, apiName, additionnalFields); var promise = backendClient.getTableData(requestFields, filters, apiName, additionnalFields);
promise.then(function (data) { promise.then(function (data) {
$scope.entries = data; $scope.entries = data;
conf.entries = data; conf.entries = data;

View File

@ -16,10 +16,8 @@ angular.module('bansho.tactical', ['bansho.live',
this.topAlertProducers = config.components.topAlertProducers; this.topAlertProducers = config.components.topAlertProducers;
}) })
.controller('TacticalCtrl', ['$scope', '$interval', 'tacticalConfig', 'getHostProblems', 'getServiceProblems', .controller('TacticalCtrl', ['$scope', '$interval', 'tacticalConfig', 'backendClient', 'promisesManager',
'getTotalHosts', 'getTotalServices', 'promisesManager', function ($scope, $interval, tacticalConfig, backendClient, promisesManager) {
function ($scope, $interval, tacticalConfig, getHostProblems, getServiceProblems, getTotalHosts,
getTotalServices, promisesManager) {
var getData; var getData;
@ -35,17 +33,17 @@ angular.module('bansho.tactical', ['bansho.live',
$scope.totalServices = undefined; $scope.totalServices = undefined;
getData = function () { getData = function () {
getHostProblems().success(function (hostProblems) { backendClient.getHostProblems().success(function (hostProblems) {
$scope.hostProblems = hostProblems.length; $scope.hostProblems = hostProblems.length;
getTotalHosts().success(function (allHosts) { backendClient.getTotalHosts().success(function (allHosts) {
$scope.totalHosts = allHosts.length; $scope.totalHosts = allHosts.length;
$scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100; $scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100;
}); });
}); });
getServiceProblems().success(function (serviceProblems) { backendClient.getServiceProblems().success(function (serviceProblems) {
$scope.serviceProblems = serviceProblems.length; $scope.serviceProblems = serviceProblems.length;
getTotalServices().success(function (allServices) { backendClient.getTotalServices().success(function (allServices) {
$scope.totalServices = allServices.length; $scope.totalServices = allServices.length;
$scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100; $scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100;
}); });

View File

@ -2,16 +2,16 @@
angular.module('bansho.topbar', ['bansho.live']) angular.module('bansho.topbar', ['bansho.live'])
.controller('TopBarCtrl', ['$scope', '$interval', 'getServiceProblems', 'getHostProblems', 'promisesManager', .controller('TopBarCtrl', ['$scope', '$interval', 'backendClient', 'promisesManager',
function ($scope, $interval, getServiceProblems, getHostProblems, promisesManager) { function ($scope, $interval, backendClient, promisesManager) {
var getData, var getData,
hostProblems, hostProblems,
serviceProblems; serviceProblems;
getData = function () { getData = function () {
getServiceProblems().success(function (data) { backendClient.getServiceProblems().success(function (data) {
serviceProblems = data.length; serviceProblems = data.length;
getHostProblems().success(function (data) { backendClient.getHostProblems().success(function (data) {
hostProblems = data.length; hostProblems = data.length;
$scope.allProblems = serviceProblems + hostProblems; $scope.allProblems = serviceProblems + hostProblems;
}); });

View File

@ -9,11 +9,10 @@ angular.module('bansho.view.dashboard', ['ngRoute',
.value('dashboardConfig', {}) .value('dashboardConfig', {})
.controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'dashboardConfig', 'getObjects', .controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'dashboardConfig',
'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems', 'TableConfigObj', 'TacticalConfigObj', 'backendClient', 'promisesManager',
'getServiceProblems', 'promisesManager', function ($scope, $routeParams, $interval, dashboardConfig, TableConfigObj, TacticalConfigObj,
function ($scope, $routeParams, $interval, dashboardConfig, getObjects, TableConfigObj, TacticalConfigObj, getHostOpenProblems, backendClient, promisesManager) {
getServiceOpenProblems, getHostProblems, getServiceProblems, promisesManager) {
var components = [], var components = [],
component, component,
config, config,
@ -42,17 +41,17 @@ angular.module('bansho.view.dashboard', ['ngRoute',
} }
getData = function () { getData = function () {
getHostOpenProblems().success(function (data) { backendClient.getHostOpenProblems().success(function (data) {
$scope.nbHostOpenProblems = data.length; $scope.nbHostOpenProblems = data.length;
getServiceOpenProblems().then(function (openProblems) { backendClient.getServiceOpenProblems().then(function (openProblems) {
$scope.nbServiceOpenProblems = openProblems.length; $scope.nbServiceOpenProblems = openProblems.length;
$scope.totalOpenProblems = $scope.nbServiceOpenProblems + $scope.nbHostOpenProblems; $scope.totalOpenProblems = $scope.nbServiceOpenProblems + $scope.nbHostOpenProblems;
}); });
}); });
getHostProblems().success(function (data) { backendClient.getHostProblems().success(function (data) {
$scope.nbHostProblems = data.length; $scope.nbHostProblems = data.length;
getServiceProblems().success(function (data) { backendClient.getServiceProblems().success(function (data) {
$scope.nbServiceProblems = data.length; $scope.nbServiceProblems = data.length;
$scope.totalProblems = $scope.nbHostProblems + $scope.nbServiceProblems; $scope.totalProblems = $scope.nbHostProblems + $scope.nbServiceProblems;
}); });