Merge pull request #38 from titilambert/pogneMaBranche

Introduces host view
This commit is contained in:
Frédéric Vachon 2015-03-26 16:28:38 -04:00
commit baffe13df6
28 changed files with 400 additions and 134 deletions

View File

@ -91,7 +91,7 @@ module.exports = function (grunt) {
'<%= project.app %>/components/config/config.js',
'<%= project.app %>/components/live/live.js',
'<%= project.app %>/components/live/notifications.js',
'<%= project.app %>/components/live/get_services.js',
'<%= project.app %>/components/live/get_objects.js',
'<%= project.app %>/components/ng-justgage/ng-justgage.js',
'<%= project.app %>/components/filters/filters.js',
'<%= project.app %>/components/sidebar/sidebar.js',
@ -109,9 +109,16 @@ module.exports = function (grunt) {
'<%= project.app %>/components/table/cell_hosts_host/cell_hosts_host.js',
'<%= project.app %>/components/table/cell_host_address/cell_host_address.js',
'<%= project.app %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.app %>/components/host/host.js',
'<%= project.app %>/components/host/host_cpu/host_cpu.js',
'<%= project.app %>/components/host/host_info/host_info.js',
'<%= project.app %>/components/host/host_load/host_load.js',
'<%= project.app %>/components/host/host_main/host_main.js',
'<%= project.app %>/components/host/host_services_list/host_services_list.js',
'<%= project.app %>/routing_view/routing_view.js',
'<%= project.app %>/templates/dashboard/dashboard.js',
'<%= project.app %>/templates/single_table/single_table.js'
'<%= project.app %>/templates/single_table/single_table.js',
'<%= project.app %>/templates/host/host.js'
]
}],
options: {
@ -125,7 +132,7 @@ module.exports = function (grunt) {
'<%= project.build %>/components/config/config.js': '<%= project.app %>/components/config/config.js',
'<%= project.build %>/components/live/live.js': '<%= project.app %>/components/live/live.js',
'<%= project.build %>/components/live/notifications.js': '<%= project.app %>/components/live/notifications.js',
'<%= project.build %>/components/live/get_services.js': '<%= project.app %>/components/live/get_services.js',
'<%= project.build %>/components/live/get_objects.js': '<%= project.app %>/components/live/get_objects.js',
'<%= project.build %>/components/ng-justgage/ng-justgage.js': '<%= project.app %>/components/ng-justgage/ng-justgage.js',
'<%= project.build %>/components/filters/filters.js': '<%= project.app %>/components/filters/filters.js',
'<%= project.build %>/components/sidebar/sidebar.js': '<%= project.app %>/components/sidebar/sidebar.js',
@ -143,9 +150,18 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_hosts_host/cell_hosts_host.js': '<%= project.app %>/components/table/cell_hosts_host/cell_hosts_host.js',
'<%= project.build %>/components/table/cell_host_address/cell_host_address.js': '<%= project.app %>/components/table/cell_host_address/cell_host_address.js',
'<%= project.build %>/components/table/cell_host_status/cell_host_status.js': '<%= project.app %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.build %>/components/host/host.js': '<%= project.app %>/components/host/host.js',
'<%= project.build %>/components/host/host_cpu/host_cpu.js': '<%= project.app %>/components/host/host_cpu/host_cpu.js',
'<%= project.build %>/components/host/host_info/host_info.js': '<%= project.app %>/components/host/host_info/host_info.js',
'<%= project.build %>/components/host/host_load/host_load.js': '<%= project.app %>/components/host/host_load/host_load.js',
'<%= project.build %>/components/host/host_main/host_main.js': '<%= project.app %>/components/host/host_main/host_main.js',
'<%= project.build %>/components/host/host_services_list/host_services_list.js': '<%= project.app %>/components/host/host_services_list/host_services_list.js',
'<%= project.build %>/routing_view/routing_view.js': '<%= project.app %>/routing_view/routing_view.js',
'<%= project.build %>/templates/dashboard/dashboard.js': '<%= project.app %>/templates/dashboard/dashboard.js',
'<%= project.build %>/templates/single_table/single_table.js' : '<%= project.app %>/templates/single_table/single_table.js'
'<%= project.build %>/templates/single_table/single_table.js' : '<%= project.app %>/templates/single_table/single_table.js',
'<%= project.build %>/templates/host/host.js' : '<%= project.app %>/templates/host/host.js'
},
{
'<%= project.build %>/js/adagios.min.js' : [
@ -153,7 +169,7 @@ module.exports = function (grunt) {
'<%= project.build %>/components/config/config.js',
'<%= project.build %>/components/live/live.js',
'<%= project.build %>/components/live/notifications.js',
'<%= project.build %>/components/live/get_services.js',
'<%= project.build %>/components/live/get_objects.js',
'<%= project.build %>/components/ng-justgage/ng-justgage.js',
'<%= project.build %>/components/filters/filters.js',
'<%= project.build %>/components/sidebar/sidebar.js',
@ -171,9 +187,16 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_hosts_host/cell_hosts_host.js',
'<%= project.build %>/components/table/cell_host_address/cell_host_address.js',
'<%= project.build %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.build %>/components/host/host.js',
'<%= project.build %>/components/host/host_cpu/host_cpu.js',
'<%= project.build %>/components/host/host_info/host_info.js',
'<%= project.build %>/components/host/host_load/host_load.js',
'<%= project.build %>/components/host/host_main/host_main.js',
'<%= project.build %>/components/host/host_services_list/host_services_list.js',
'<%= project.build %>/routing_view/routing_view.js',
'<%= project.build %>/templates/dashboard/dashboard.js',
'<%= project.build %>/templates/single_table/single_table.js'
'<%= project.build %>/templates/single_table/single_table.js',
'<%= project.build %>/templates/host/host.js'
]
}
],

View File

@ -15,12 +15,14 @@ angular.element(document).ready(function () {
angular.module('adagios', [
'ngRoute',
'adagios.sidebar',
'adagios.topbar',
'adagios.config',
'adagios.topbar',
'adagios.sidebar',
'adagios.host',
'adagios.view',
'adagios.view.dashboard',
'adagios.view.singleTable',
'adagios.view'
'adagios.view.host'
])
.config(['$routeProvider', function ($routeProvider) {

View File

@ -15,7 +15,7 @@ angular.module('adagios.config', [])
data = value;
};
this.$get = [function getConfigFactory() {
this.$get = [function () {
return new AdagiosConfig(data);
}];
});

View File

@ -205,5 +205,10 @@
"noRepeatCell" : "host"
}
}]
},
"host": {
"title": "Host",
"refreshInterval": 0,
"template": "host"
}
}

View File

@ -0,0 +1,17 @@
<article ng-controller="HostCtrl">
<section class="main__content tabpanel">
<h2 class="main__overview__title">{{hostName}}</h2>
<table class="data-table">
<tbody >
<tr ng-repeat="(key, value) in data.live">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
<tr ng-repeat="(key, value) in data.config">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</tbody>
</table>
</section>
</article>

View File

@ -0,0 +1,41 @@
'use strict';
angular.module('adagios.host', ['adagios.live'])
.value('hostConfig', {})
.controller('HostCtrl', ['$scope', 'hostConfig', 'addObjectToScope', function ($scope, hostConfig, addObjectToScope) {
var objectType = 'host',
objectIdentifier = {};
objectIdentifier.host_name = hostConfig.hostName;
$scope.data = {};
addObjectToScope(objectType, objectIdentifier, $scope);
}])
.directive('adgHost', ['$http', '$compile', 'hostConfig',
function ($http, $compile, hostConfig) {
return {
restrict: 'E',
compile: function () {
return function (scope, element, attrs) {
var template = 'components/host/host.html';
if (!attrs.hostName) {
throw new Error('<adg-host> "host-name" attribute must be defined');
}
hostConfig.hostName = {};
hostConfig.hostName = attrs.hostName;
$http.get(template, { cache: true })
.success(function (data) {
var elem = $compile(data)(scope);
element.append(elem);
});
};
}
};
}]);

View File

@ -0,0 +1,14 @@
'use strict';
angular.module('adagios.host.cpu', [])
.controller('TableCtrl', ['$scope', function ($scope) {
angular.noop();
}])
.directive('adgHostCpu', function () {
return {
restrict: 'E',
templateUrl: 'components/host/host_cpu/host_cpu.html'
};
});

View File

@ -0,0 +1,14 @@
'use strict';
angular.module('adagios.host.cpu', [])
.controller('HostCpuCtrl', ['$scope', function ($scope) {
angular.noop();
}])
.directive('adgHostCpu', function () {
return {
restrict: 'E',
templateUrl: 'components/host/host_cpu/host_cpu.html'
};
});

View File

@ -0,0 +1,14 @@
'use strict';
angular.module('adagios.host.load', [])
.controller('HostLoadCtrl', ['$scope', function ($scope) {
angular.noop();
}])
.directive('adgHostLoad', function () {
return {
restrict: 'E',
templateUrl: 'components/host/host_load/host_load.html'
};
});

View File

@ -0,0 +1,14 @@
'use strict';
angular.module('adagios.host.main', [])
.controller('HostMainCtrl', ['$scope', function ($scope) {
angular.noop();
}])
.directive('adgHostMain', function () {
return {
restrict: 'E',
templateUrl: 'components/host/host_main/host_main.html'
};
});

View File

@ -0,0 +1,14 @@
'use strict';
angular.module('adagios.host.services_list', [])
.controller('HostServicesListCtrl', ['$scope', function ($scope) {
angular.noop();
}])
.directive('adgHostServicesList', function () {
return {
restrict: 'E',
templateUrl: 'components/host/host_services_list/host_services_list.html'
};
});

View File

@ -0,0 +1,203 @@
'use strict';
angular.module('adagios.live')
.constant('filterSuffixes', { contains: '__contains',
has_fields: '__has_field',
startswith: '__startswith',
endswith: '__endswith',
exists: '__exists',
in: '__in',
isnot: '__isnot',
regex: '__regex'
})
.service('getObjects', ['$http', 'filterSuffixes',
function ($http, filterSuffixes) {
return function (columns, 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);
return $http.get('/rest/status/json/' + apiName + '/?fields=' + columns + filtersQuery + additionnalQuery)
.error(function () {
throw new Error('getObjects : GET Request failed');
});
};
}])
// This service is used to count the number of host open problems
.service('getHostOpenProblems', ['$http', 'getObjects',
function ($http, getObjects) {
var fields = ['state'],
filters = {},
apiName = 'hosts',
additionnalQueryFields = {'acknowledged': 0, 'state': 1};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getObjects : GET Request failed');
});
}])
// This service is used to count the number of service open problems
.service('getServiceOpenProblems', ['$http', 'getObjects',
function ($http, getObjects) {
var fields = ['state'],
filters = { "isnot": { "state": [ "0" ], "host_state": [ "2" ] }},
apiName = 'services',
additionnalQueryFields = {'acknowledged': 0};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getObjects : GET Request failed');
});
}])
// This service is used to count the number of host problems
.service('getHostProblems', ['$http', 'getObjects',
function ($http, getObjects) {
var fields = ['state'],
filters = { 'isnot': {'state': [0]} },
apiName = 'hosts',
additionnalQueryFields = {};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getObjects : GET Request failed');
});
}])
// This service is used to count the number of service problems
.service('getServiceProblems', ['$http', 'getObjects',
function ($http, getObjects) {
var fields = ['state'],
filters = { 'isnot': {'state': [0]} },
apiName = 'services',
additionnalQueryFields = {};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getObjects : GET Request failed');
});
}])
.service('getObjectId', ['$http', function ($http) {
return function (objectType, objectIdentifier) {
var postString, req;
postString = "with_fields=id&object_type=" + objectType;
angular.forEach(objectIdentifier, function (value, key) {
if (key === "description") {
key = "service_description";
}
postString += "&" + key + "=" + value;
});
req = {
method: 'POST',
url: '/rest/pynag/json/get_objects',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: postString
};
return $http(req)
.error(function () {
throw new Error('getObjectId : POST Request failed');
});
};
}])
.service('getObjectById', ['$http', function ($http) {
return function (objectId) {
var postString, req;
postString = "with_fields=&id=" + objectId;
req = {
method: 'POST',
url: '/rest/pynag/json/get_object',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: postString
};
return $http(req)
.error(function () {
throw new Error('getHostById : POST Request failed');
});
};
}])
// Add object of specified type to $scope.data
.service('addObjectToScope', ['$http', 'getObjectId', 'getObjectById', function ($http, getObjectId, getObjectById) {
return function (objectType, objectIdentifier, scope) {
var objectData = {},
url = "/rest/status/json/",
firstParameter = true,
endpoints = {
"host" : "hosts",
"service" : "services"
};
url += endpoints[objectType];
url += "/?";
angular.forEach(objectIdentifier, function (value, key) {
if (!firstParameter) {
url += "&";
}
url += key + "=" + value;
firstParameter = false;
});
$http.get(url)
.success(function (data) {
objectData.live = data[0];
getObjectId(objectType, objectIdentifier)
.success(function (data) {
var objectId = data[0].id;
scope.data.id = objectId;
getObjectById(objectId)
.success(function (data) {
objectData.config = data;
scope.data = objectData;
});
});
});
};
}]);

View File

@ -9,15 +9,15 @@ describe('In Adagios Live', function () {
$httpBackend = _$httpBackend_;
}));
describe('getServices', function () {
describe('getObjects', function () {
it('should send the proper GET request', inject(function (getServices) {
it('should send the proper GET request', inject(function (getObjects) {
var fields = ['host_name', 'host_state', 'description'],
filters = { contains: { host_name: ['srv', 'a'], plugin_output: ['SWAP'] },
startswith: { host_name: ['srv'] } },
apiName = 'services';
getServices(fields, filters, apiName);
getObjects(fields, filters, apiName);
$httpBackend.expectGET('/rest/status/json/services/?fields=host_name,host_state,description&host_name__contains=srv&host_name__contains=a&plugin_output__contains=SWAP&host_name__startswith=srv').respond('');
$httpBackend.flush();
}));

View File

@ -1,110 +0,0 @@
'use strict';
angular.module('adagios.live')
.constant('filterSuffixes', { contains: '__contains',
has_fields: '__has_field',
startswith: '__startswith',
endswith: '__endswith',
exists: '__exists',
in: '__in',
isnot: '__isnot',
regex: '__regex'
})
.service('getServices', ['$http', 'filterSuffixes',
function ($http, filterSuffixes) {
return function (columns, 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);
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');
});
}]);

View File

@ -1,3 +1,3 @@
<td class="data-table__host {{entry[cell_name + '_additionnalClass']}} {{state}}" ng-controller="CellHostCtrl">
<a class="data-table__data" href="#">{{entry.host_name}}</a>
<a class="data-table__data" href="#/view?view=host&host_name={{entry.host_name}}">{{entry.host_name}}</a>
</td>

View File

@ -1,3 +1,3 @@
<td class="data-table__hosts_host {{state}}" ng-controller="CellHostsHostCtrl">
<a class="data-table__data" href="#">{{entry.name}}</a>
<a class="data-table__data" href="#/view?view=host&host_name={{entry.name}}">{{entry.name}}</a>
</td>

View File

@ -1,6 +1,8 @@
<td class="data-table__service {{state}}" ng-controller="CellServiceCheckCtrl">
<dl class="data-table__data">
<dt class="data-table__service__name">{{entry.description}}</dt>
<dt class="data-table__service__name">
<a href="#/object_view?object_type=service&host_name={{entry.host_name}}&description={{entry.description}}">{{entry.description}}</a>
</dt>
<dd class="data-table__service__summary">{{entry.plugin_output}}</dd>
</dl>
</td>

View File

@ -5,7 +5,7 @@ angular.module('adagios.table.cell_service_check', ['adagios.table'])
.controller('CellServiceCheckCtrl', ['$scope', function ($scope) {
if ($scope.entry.state === 0) {
$scope.state = 'state--ok';
} else if ($scope.entry === 1) {
} else if ($scope.entry.state === 1) {
$scope.state = 'state--warning';
} else {
$scope.state = 'state--error';

View File

@ -15,5 +15,4 @@
<td adg-cell cell-name="{{cell}}" ng-repeat="cell in cellsName"></td>
</tr>
</tbody>
</table>

View File

@ -18,8 +18,8 @@ angular.module('adagios.table', ['adagios.live',
.value('ajaxQueries', [])
.controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tablesConfig', 'actionbarFilters', 'ajaxQueries', 'tableGlobalConfig',
function ($scope, $interval, getServices, tablesConfig, actionbarFilters, ajaxQueries, tableGlobalConfig) {
.controller('TableCtrl', ['$scope', '$interval', 'getObjects', 'tablesConfig', 'actionbarFilters', 'ajaxQueries', 'tableGlobalConfig',
function ($scope, $interval, getObjects, tablesConfig, actionbarFilters, ajaxQueries, tableGlobalConfig) {
var requestFields = [],
conf = tablesConfig[tableGlobalConfig.nextTableIndex],
getData,
@ -40,7 +40,7 @@ angular.module('adagios.table', ['adagios.live',
});
getData = function (requestFields, filters, apiName, additionnalFields) {
getServices(requestFields, filters, apiName, additionnalFields)
getObjects(requestFields, filters, apiName, additionnalFields)
.success(function (data) {
$scope.entries = data;
});
@ -117,7 +117,6 @@ angular.module('adagios.table', ['adagios.live',
}])
.directive('adgCell', ['$http', '$compile', function ($http, $compile) {
return {
restrict: 'A',
compile: function () {

View File

@ -8,10 +8,10 @@ angular.module('adagios.view.dashboard', ['ngRoute',
.value('dashboardConfig', {})
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getServices',
.controller('DashboardCtrl', ['$scope', '$routeParams', 'dashboardConfig', 'getObjects',
'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems',
'getServiceProblems',
function ($scope, $routeParams, dashboardConfig, getServices, TableConfigObj,
function ($scope, $routeParams, dashboardConfig, getObjects, TableConfigObj,
TacticalConfigObj, getHostOpenProblems, getServiceOpenProblems, getHostProblems, getServiceProblems) {
var components = [],
component,

View File

@ -0,0 +1,3 @@
<article ng-controller="HostViewCtrl">
<adg-host host-name="{{hostName}}"></adg-host>
</article>

View File

@ -0,0 +1,12 @@
'use strict';
angular.module('adagios.view.host', ['adagios.live'])
.controller('HostViewCtrl', ['$http', '$scope', '$routeParams', 'getObjectId', 'getObjectById', 'addObjectToScope',
function ($http, $scope, $routeParams, getObjectId, getObjectById, addObjectToScope) {
if (!!$routeParams.host_name) {
$scope.hostName = $routeParams.host_name;
} else {
throw new Error("ERROR :'host_name' GET parameter must be set");
}
}]);