diff --git a/app/components/config/config.json b/app/components/config/config.json index f3247ae..ffeab98 100644 --- a/app/components/config/config.json +++ b/app/components/config/config.json @@ -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": { diff --git a/app/components/live/get_services.js b/app/components/live/get_services.js index 99fbc7b..2a1558c 100644 --- a/app/components/live/get_services.js +++ b/app/components/live/get_services.js @@ -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'); + }); }]); diff --git a/app/components/table/cell_host_status/cell_host_status.js b/app/components/table/cell_host_status/cell_host_status.js index 0e40186..0560306 100644 --- a/app/components/table/cell_host_status/cell_host_status.js +++ b/app/components/table/cell_host_status/cell_host_status.js @@ -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"; } } }]) diff --git a/app/components/table/cell_hosts_host/cell_hosts_host.js b/app/components/table/cell_hosts_host/cell_hosts_host.js index 0be8a79..1f82021 100644 --- a/app/components/table/cell_hosts_host/cell_hosts_host.js +++ b/app/components/table/cell_hosts_host/cell_hosts_host.js @@ -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'; } }]) diff --git a/app/components/table/table.js b/app/components/table/table.js index 35f8a57..335fb6d 100644 --- a/app/components/table/table.js +++ b/app/components/table/table.js @@ -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(' "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) { diff --git a/app/dashboard/dashboard.html b/app/dashboard/dashboard.html index 974d048..4db0a83 100644 --- a/app/dashboard/dashboard.html +++ b/app/dashboard/dashboard.html @@ -40,9 +40,12 @@

{{dashboardTables[0].title}}

-

There are {{nbHostProblems}} host problems.

+

+ There are {{nbHostOpenProblems}} host + +

- + -
-

{{dashboardTables[1].title}}

-

There are {{nbHostProblems}} host problems.

+

+ There are {{nbServiceOpenProblems}} host + +

-
-

{{dashboardTables[1].title}}

-

There are {{nbHostProblems}} host problems.

+

{{dashboardTables[2].title}}

+

+ There are {{nbHostProblems}} host + +

- -

Pas de tableaux encore pour All problems.

+ + + +
+

{{dashboardTables[3].title}}

+

+ There are {{nbServiceProblems}} service + +

+
+ +
diff --git a/app/dashboard/dashboard.js b/app/dashboard/dashboard.js index eae2367..000712b 100644 --- a/app/dashboard/dashboard.js +++ b/app/dashboard/dashboard.js @@ -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) { - $scope.nbHostProblems = data.length; - }); + 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) {