Supports adagios and surveil backend

This commit is contained in:
Frédéric Vachon 2015-04-21 16:27:15 -04:00
parent 92485a1026
commit 7b51802b52
5 changed files with 104 additions and 327 deletions

View File

@ -41,7 +41,7 @@ module.exports = function (grunt) {
'!<%= project.build %>/**',
'!<%= project.assets %>/**'
],
tasks: ['uglify:dev']
tasks: ['uglify:surveil']
}
},
@ -92,7 +92,7 @@ module.exports = function (grunt) {
'<%= project.app %>/components/config/config.js',
'<%= project.app %>/components/utils/promise_manager.js',
'<%= project.app %>/components/live/live.js',
'<%= project.app %>/components/live/get_objects.js',
'<%= project.app %>/components/live/surveil.js',
'<%= project.app %>/components/ng-justgage/ng-justgage.js',
'<%= project.app %>/components/filters/filters.js',
'<%= project.app %>/components/sidebar/sidebar.js',
@ -107,7 +107,6 @@ module.exports = function (grunt) {
'<%= project.app %>/components/table/cell_host/cell_host.js',
'<%= project.app %>/components/table/cell_last_check/cell_last_check.js',
'<%= project.app %>/components/table/cell_service_check/cell_service_check.js',
'<%= 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',
@ -131,14 +130,14 @@ module.exports = function (grunt) {
mangle: true
}
},
dev: {
adagios: {
files: [
{
'<%= project.build %>/app.js': '<%= project.app %>/app.js',
'<%= project.build %>/components/config/config.js': '<%= project.app %>/components/config/config.js',
'<%= project.build %>/components/utils/promise_manager.js': '<%= project.app %>/components/utils/promise_manager.js',
'<%= project.build %>/components/live/live.js': '<%= project.app %>/components/live/live.js',
'<%= project.build %>/components/live/get_objects.js': '<%= project.app %>/components/live/get_objects.js',
'<%= project.build %>/components/live/surveil.js': '<%= project.app %>/components/live/surveil.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',
@ -153,7 +152,6 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_host/cell_host.js': '<%= project.app %>/components/table/cell_host/cell_host.js',
'<%= project.build %>/components/table/cell_last_check/cell_last_check.js': '<%= project.app %>/components/table/cell_last_check/cell_last_check.js',
'<%= project.build %>/components/table/cell_service_check/cell_service_check.js': '<%= project.app %>/components/table/cell_service_check/cell_service_check.js',
'<%= 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',
@ -180,7 +178,95 @@ module.exports = function (grunt) {
'<%= project.build %>/components/config/config.js',
'<%= project.build %>/components/utils/promise_manager.js',
'<%= project.build %>/components/live/live.js',
'<%= project.build %>/components/live/get_objects.js',
'<%= project.build %>/components/live/surveil.js',
'<%= project.build %>/components/ng-justgage/ng-justgage.js',
'<%= project.build %>/components/filters/filters.js',
'<%= project.build %>/components/sidebar/sidebar.js',
'<%= project.build %>/components/topbar/topbar.js',
'<%= project.build %>/components/tactical/tactical.js',
'<%= project.build %>/components/tactical/status_overview/status_overview.js',
'<%= project.build %>/components/tactical/current_health/current_health.js',
'<%= project.build %>/components/tactical/top_alert_producers/top_alert_producers.js',
'<%= project.build %>/components/table/actionbar/actionbar.js',
'<%= project.build %>/components/table/table.js',
'<%= project.build %>/components/table/cell_duration/cell_duration.js',
'<%= project.build %>/components/table/cell_host/cell_host.js',
'<%= project.build %>/components/table/cell_last_check/cell_last_check.js',
'<%= project.build %>/components/table/cell_service_check/cell_service_check.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 %>/components/service/service.js',
'<%= project.build %>/components/service/service_main/service_main.js',
'<%= project.build %>/components/service/service_info/service_info.js',
'<%= project.build %>/components/service/service_metrics/service_metrics.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/host/host.js',
'<%= project.build %>/templates/service/service.js'
]
}
],
options: {
mangle: false,
beautify: true
}
},
surveil: {
files: [
{
'<%= project.build %>/app.js': '<%= project.app %>/app.js',
'<%= project.build %>/components/config/config.js': '<%= project.app %>/components/config/config.js',
'<%= project.build %>/components/utils/promise_manager.js': '<%= project.app %>/components/utils/promise_manager.js',
'<%= project.build %>/components/live/live.js': '<%= project.app %>/components/live/live.js',
'<%= project.build %>/components/live/surveil.js': '<%= project.app %>/components/live/surveil.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',
'<%= project.build %>/components/topbar/topbar.js': '<%= project.app %>/components/topbar/topbar.js',
'<%= project.build %>/components/tactical/tactical.js': '<%= project.app %>/components/tactical/tactical.js',
'<%= project.build %>/components/tactical/status_overview/status_overview.js': '<%= project.app %>/components/tactical/status_overview/status_overview.js',
'<%= project.build %>/components/tactical/current_health/current_health.js': '<%= project.app %>/components/tactical/current_health/current_health.js',
'<%= project.build %>/components/tactical/top_alert_producers/top_alert_producers.js': '<%= project.app %>/components/tactical/top_alert_producers/top_alert_producers.js',
'<%= project.build %>/components/table/actionbar/actionbar.js': '<%= project.app %>/components/table/actionbar/actionbar.js',
'<%= project.build %>/components/table/table.js': '<%= project.app %>/components/table/table.js',
'<%= project.build %>/components/table/cell_duration/cell_duration.js': '<%= project.app %>/components/table/cell_duration/cell_duration.js',
'<%= project.build %>/components/table/cell_host/cell_host.js': '<%= project.app %>/components/table/cell_host/cell_host.js',
'<%= project.build %>/components/table/cell_last_check/cell_last_check.js': '<%= project.app %>/components/table/cell_last_check/cell_last_check.js',
'<%= project.build %>/components/table/cell_service_check/cell_service_check.js': '<%= project.app %>/components/table/cell_service_check/cell_service_check.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 %>/components/service/service.js': '<%= project.app %>/components/service/service.js',
'<%= project.build %>/components/service/service_main/service_main.js': '<%= project.app %>/components/service/service_main/service_main.js',
'<%= project.build %>/components/service/service_info/service_info.js': '<%= project.app %>/components/service/service_info/service_info.js',
'<%= project.build %>/components/service/service_metrics/service_metrics.js': '<%= project.app %>/components/service/service_metrics/service_metrics.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/host/host.js': '<%= project.app %>/templates/host/host.js',
'<%= project.build %>/templates/service/service.js': '<%= project.app %>/templates/service/service.js'
},
{
'<%= project.build %>/js/adagios.min.js' : [
'<%= project.build %>/app.js',
'<%= project.build %>/components/config/config.js',
'<%= project.build %>/components/utils/promise_manager.js',
'<%= project.build %>/components/live/live.js',
'<%= project.build %>/components/live/surveil.js',
'<%= project.build %>/components/ng-justgage/ng-justgage.js',
'<%= project.build %>/components/filters/filters.js',
'<%= project.build %>/components/sidebar/sidebar.js',
@ -195,7 +281,6 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_host/cell_host.js',
'<%= project.build %>/components/table/cell_last_check/cell_last_check.js',
'<%= project.build %>/components/table/cell_service_check/cell_service_check.js',
'<%= 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',

View File

@ -1,291 +0,0 @@
'use strict';
angular.module('adagios.live')
.constant('filterSuffixes', { contains: '__contains',
has_field: '__has_field',
startswith: '__startswith',
endswith: '__endswith',
exists: '__exists',
in: '__in',
isnot: '__isnot',
regex: '__regex'
})
.service('getObjects', ['$http', 'filterSuffixes', 'hostMiddleware',
function ($http, filterSuffixes, hostMiddleware) {
return 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('getService', ['$http',
function ($http) {
return function (hostName, description) {
return $http.get('/adagios/rest/status/json/services/?host_name=' + hostName + '&description=' + description)
.error(function () {
throw new Error('getService : GET Request failed');
});
};
}])
// This service is used to count the number of host open problems
.service('getHostOpenProblems', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['state'],
filters = {},
apiName = 'hosts',
additionnalQueryFields = {'acknowledged': 0, 'state': 1};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getHostOpenProblems : GET Request failed');
});
};
}])
// This service is used to count the number of service open problems
.service('getServiceOpenProblems', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
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('getServiceOpenProblems : GET Request failed');
});
};
}])
// This service is used to count the number of host problems
.service('getHostProblems', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['state'],
filters = { 'isnot': {'state': [0]} },
apiName = 'hosts',
additionnalQueryFields = {};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getHostProblems : GET Request failed');
});
};
}])
// This service is used to count the number of service problems
.service('getServiceProblems', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['state'],
filters = { 'isnot': {'state': [0]} },
apiName = 'services',
additionnalQueryFields = {};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getServiceOpenProblems : GET Request failed');
});
};
}])
// This service is used to count the number of hosts
.service('getTotalHosts', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['name'],
filters = {},
apiName = 'hosts',
additionnalQueryFields = {};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getTotalHosts : GET Request failed');
});
};
}])
// This service is used to count the number of services
.service('getTotalServices', ['$http', 'getObjects',
function ($http, getObjects) {
return function () {
var fields = ['name'],
filters = {},
apiName = 'services',
additionnalQueryFields = {};
return getObjects(fields, filters, apiName, additionnalQueryFields)
.error(function () {
throw new Error('getTotalServices : 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: '/adagios/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: '/adagios/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 = "/adagios/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;
});
});
});
};
}])
// Modify response object to conform to web ui
.service('hostMiddleware', function() {
return function(data) {
var i = 0,
conversions = {
'name': 'host_name',
'state': 'host_state'
};
for (i = 0; i < data.length; i += 1) {
angular.forEach(data[i], function (value, field) {
if (field in conversions) {
data[i][conversions[field]] = value;
delete data[i][field];
}
});
}
};
});

View File

@ -1,25 +0,0 @@
'use strict';
describe('In Adagios Live', function () {
var $httpBackend;
beforeEach(module('adagios.live'));
beforeEach(inject(function (_$httpBackend_) {
$httpBackend = _$httpBackend_;
}));
describe('getObjects', function () {
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';
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

@ -8,7 +8,6 @@ angular.module('adagios.table', ['adagios.live',
'adagios.table.cell_duration',
'adagios.table.cell_service_check',
'adagios.table.cell_last_check',
'adagios.table.cell_hosts_host',
'adagios.table.cell_host_address',
'adagios.table.cell_host_status'
])

View File

@ -31,11 +31,19 @@ To compile css files run :
grunt sass
To compile js files run :
Adagios frontend now supports two backends : adagios and surveil.
To compile js for adagios run :
::
grunt uglify
grunt uglify:adagios
To compile js for surveil run :
::
grunt uglify:surveil
If you wish to develop in a docker container, here is how to proceed (assuming
you already have docker installed) :
@ -48,6 +56,7 @@ you already have docker installed) :
You must leave grunt running in the background to automatically compile css
and minify/compress js files when source code changes
By default, grunt uses surveil backend
::