Surveil backend support completed
This commit is contained in:
parent
f4261e117b
commit
e0bf937e6a
@ -9,7 +9,7 @@ angular.module('adagios.host', ['adagios.live',
|
|||||||
|
|
||||||
.value('hostConfig', {})
|
.value('hostConfig', {})
|
||||||
|
|
||||||
.controller('HostCtrl', ['$scope', 'hostConfig', 'addObjectToScope', function ($scope, hostConfig, addObjectToScope) {
|
.controller('HostCtrl', ['$scope', 'hostConfig', 'getHost', function ($scope, hostConfig, getHost) {
|
||||||
var objectType = 'host',
|
var objectType = 'host',
|
||||||
objectIdentifier = {};
|
objectIdentifier = {};
|
||||||
|
|
||||||
@ -17,7 +17,9 @@ angular.module('adagios.host', ['adagios.live',
|
|||||||
$scope.hostName = hostConfig.hostName;
|
$scope.hostName = hostConfig.hostName;
|
||||||
$scope.data = {};
|
$scope.data = {};
|
||||||
|
|
||||||
addObjectToScope(objectType, objectIdentifier, $scope);
|
getHost(objectType, objectIdentifier).then(function (data) {
|
||||||
|
$scope.data = data;
|
||||||
|
});
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.directive('adgHost', ['$http', '$compile', 'hostConfig',
|
.directive('adgHost', ['$http', '$compile', 'hostConfig',
|
||||||
|
@ -98,18 +98,24 @@ angular.module('adagios.live')
|
|||||||
}])
|
}])
|
||||||
|
|
||||||
// This service is used to count the number of service open problems
|
// This service is used to count the number of service open problems
|
||||||
.service('getServiceOpenProblems', ['$http', 'getObjects',
|
.service('getServiceOpenProblems', ['$http', '$q', 'getObjects',
|
||||||
function ($http, getObjects) {
|
function ($http, $q, getObjects) {
|
||||||
return function () {
|
return function () {
|
||||||
var fields = ['state'],
|
var fields = ['state'],
|
||||||
filters = { "isnot": { "state": [0], "host_state": [2] }},
|
filters = { "isnot": { "state": [0], "host_state": [2] }},
|
||||||
apiName = 'services',
|
apiName = 'services',
|
||||||
additionnalQueryFields = {'acknowledged': 0};
|
additionnalQueryFields = {'acknowledged': 0},
|
||||||
|
responsePromise = $q.defer();
|
||||||
|
|
||||||
return getObjects(fields, filters, apiName, additionnalQueryFields)
|
getObjects(fields, filters, apiName, additionnalQueryFields)
|
||||||
|
.success(function (data) {
|
||||||
|
responsePromise.resolve(data);
|
||||||
|
})
|
||||||
.error(function () {
|
.error(function () {
|
||||||
throw new Error('getServiceOpenProblems : GET Request failed');
|
throw new Error('getServiceOpenProblems : GET Request failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return responsePromise.promise;
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
@ -231,43 +237,47 @@ angular.module('adagios.live')
|
|||||||
}])
|
}])
|
||||||
|
|
||||||
// Add object of specified type to $scope.data
|
// Add object of specified type to $scope.data
|
||||||
.service('addObjectToScope', ['$http', 'getObjectId', 'getObjectById', function ($http, getObjectId, getObjectById) {
|
.service('getHost', ['$http', '$q', 'getObjectId', 'getObjectById',
|
||||||
return function (objectType, objectIdentifier, scope) {
|
function ($http, $q, getObjectId, getObjectById) {
|
||||||
var objectData = {},
|
return function (objectType, objectIdentifier) {
|
||||||
url = "/adagios/rest/status/json/",
|
var objectData = {},
|
||||||
firstParameter = true,
|
url = "/adagios/rest/status/json/",
|
||||||
endpoints = {
|
firstParameter = true,
|
||||||
"host" : "hosts",
|
endpoints = {
|
||||||
"service" : "services"
|
"host" : "hosts",
|
||||||
};
|
"service" : "services"
|
||||||
|
},
|
||||||
|
response = {},
|
||||||
|
responsePromise = $q.defer();
|
||||||
|
|
||||||
url += endpoints[objectType];
|
url += endpoints[objectType];
|
||||||
url += "/?";
|
url += "/?";
|
||||||
|
|
||||||
angular.forEach(objectIdentifier, function (value, key) {
|
angular.forEach(objectIdentifier, function (value, key) {
|
||||||
if (!firstParameter) {
|
if (!firstParameter) {
|
||||||
url += "&";
|
url += "&";
|
||||||
}
|
}
|
||||||
url += key + "=" + value;
|
url += key + "=" + value;
|
||||||
firstParameter = false;
|
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;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
$http.get(url)
|
||||||
|
.success(function (data) {
|
||||||
|
response.live = data[0];
|
||||||
|
getObjectId(objectType, objectIdentifier)
|
||||||
|
.success(function (data) {
|
||||||
|
var objectId = data[0].id;
|
||||||
|
getObjectById(objectId)
|
||||||
|
.success(function (data) {
|
||||||
|
response.config = data;
|
||||||
|
responsePromise.resolve(response);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return responsePromise.promise;
|
||||||
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
// Modify response object to conform to web ui
|
// Modify response object to conform to web ui
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
angular.module('adagios.live')
|
angular.module('adagios.live')
|
||||||
|
|
||||||
.service('getObjects', ['$http', 'hostQueryTransform',
|
.service('getObjects', ['$http', 'hostQueryTransform', 'hostMiddleware', 'serviceMiddleware',
|
||||||
function ($http, hostQueryTransform) {
|
function ($http, hostQueryTransform, hostMiddleware, serviceMiddleware) {
|
||||||
return function (fields, filters, apiName, additionnalFields) {
|
return function (fields, filters, apiName, additionnalFields) {
|
||||||
var query = {};
|
var query = {},
|
||||||
|
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) {
|
||||||
@ -27,13 +28,14 @@ angular.module('adagios.live')
|
|||||||
return defaults.concat(transform);
|
return defaults.concat(transform);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (apiName === 'hosts') {
|
||||||
function transformations(data) {
|
transformations = hostMiddleware;
|
||||||
// TODO: implement transformation
|
} else if (apiName === 'services') {
|
||||||
return data;
|
transformations = serviceMiddleware;
|
||||||
|
} else {
|
||||||
|
throw new Error('getObjects : ' + apiName + ' API is not supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (apiName === 'hosts') {
|
if (apiName === 'hosts') {
|
||||||
hostQueryTransform(fields, filters);
|
hostQueryTransform(fields, filters);
|
||||||
}
|
}
|
||||||
@ -62,7 +64,7 @@ angular.module('adagios.live')
|
|||||||
filters = {},
|
filters = {},
|
||||||
additionnalFields = { 'host_name': hostName, 'description': description };
|
additionnalFields = { 'host_name': hostName, 'description': description };
|
||||||
|
|
||||||
return getObjects(fields, filters, additionnalFields)
|
return getObjects(fields, filters, 'services', additionnalFields)
|
||||||
.error(function () {
|
.error(function () {
|
||||||
throw new Error('getService : POST Request failed');
|
throw new Error('getService : POST Request failed');
|
||||||
});
|
});
|
||||||
@ -187,96 +189,26 @@ angular.module('adagios.live')
|
|||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.service('getObjectId', ['$http', function ($http) {
|
.service('getHost', ['$http', '$q', function ($http, $q) {
|
||||||
return function (objectType, objectIdentifier) {
|
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 = {},
|
var objectData = {},
|
||||||
url = "/rest/status/json/",
|
|
||||||
firstParameter = true,
|
|
||||||
endpoints = {
|
endpoints = {
|
||||||
"host" : "hosts",
|
"host" : "hosts",
|
||||||
"service" : "services"
|
"service" : "services"
|
||||||
};
|
},
|
||||||
|
liveUrl = '/surveil/v2/status/' + endpoints[objectType] + '/' + objectIdentifier.host_name + '/',
|
||||||
url += endpoints[objectType];
|
configUrl = '/surveil/v2/config/'+ endpoints[objectType] + '/' + objectIdentifier.host_name + '/',
|
||||||
url += "/?";
|
responsePromise = $q.defer();
|
||||||
|
|
||||||
angular.forEach(objectIdentifier, function (value, key) {
|
|
||||||
if (!firstParameter) {
|
|
||||||
url += "&";
|
|
||||||
}
|
|
||||||
url += key + "=" + value;
|
|
||||||
firstParameter = false;
|
|
||||||
|
|
||||||
|
$http.get(liveUrl) .success(function (liveData) {
|
||||||
|
$http.get(configUrl).success(function (configData) {
|
||||||
|
objectData.live = liveData;
|
||||||
|
objectData.config = configData;
|
||||||
|
responsePromise.resolve(objectData);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
$http.get(url)
|
return responsePromise.promise;
|
||||||
.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;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
@ -297,7 +229,7 @@ angular.module('adagios.live')
|
|||||||
|
|
||||||
// Modify response object to conform to web ui
|
// Modify response object to conform to web ui
|
||||||
.service('hostMiddleware', function() {
|
.service('hostMiddleware', function() {
|
||||||
return function(data) {
|
return function (data) {
|
||||||
var i = 0,
|
var i = 0,
|
||||||
conversions = {
|
conversions = {
|
||||||
'state': 'host_state'
|
'state': 'host_state'
|
||||||
@ -311,6 +243,32 @@ angular.module('adagios.live')
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -332,36 +290,28 @@ angular.module('adagios.live')
|
|||||||
i,
|
i,
|
||||||
found = false;
|
found = false;
|
||||||
|
|
||||||
for (i = 0; i < fields.length; i += 1) {
|
if (apiName === 'hosts') {
|
||||||
if (fields[i] in hostKeys) {
|
getObjects(fields, filters, 'hosts', additionnalFields)
|
||||||
hostFields.push(hostKeys[fields[i]]);
|
.success(function (data) {
|
||||||
} else {
|
responsePromise.resolve(data);
|
||||||
serviceFields.push(fields[i]);
|
});
|
||||||
}
|
return responsePromise.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
angular.forEach(fields, function (field) {
|
||||||
|
if (field in hostKeys) {
|
||||||
|
hostFields.push(hostKeys[field]);
|
||||||
|
} else {
|
||||||
|
serviceFields.push(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Make sure that 'host_name' is in both queries as we
|
// Make sure that 'host_name' is in both queries as we
|
||||||
// use this field to merge data
|
// use this field to merge data
|
||||||
for (i = 0; i < hostFields.length; i += 1) {
|
if ($.inArray('host_name', hostFields) === -1) {
|
||||||
if (hostFields[i] === 'host_name') {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
hostFields.push('host_name');
|
hostFields.push('host_name');
|
||||||
}
|
}
|
||||||
|
if ($.inArray('host_name', serviceFields) === -1) {
|
||||||
found = false;
|
|
||||||
for (i = 0; i < serviceFields.length; i += 1) {
|
|
||||||
if (serviceFields[i] === 'host_name') {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
serviceFields.push('host_name');
|
serviceFields.push('host_name');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +323,6 @@ angular.module('adagios.live')
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
//{ 'isnot': {'state': [0]} },
|
|
||||||
angular.forEach(filters, function (filterData, filterName) {
|
angular.forEach(filters, function (filterData, filterName) {
|
||||||
angular.forEach(filterData, function (values, field) {
|
angular.forEach(filterData, function (values, field) {
|
||||||
if (field in hostKeys) {
|
if (field in hostKeys) {
|
||||||
@ -390,7 +339,7 @@ angular.module('adagios.live')
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Query host and service APIs and merges responses
|
// Queries host and service APIs and merges responses
|
||||||
getObjects(hostFields, hostFilters, 'hosts', hostAdditionnalFields)
|
getObjects(hostFields, hostFilters, 'hosts', hostAdditionnalFields)
|
||||||
.success(function (hostData) {
|
.success(function (hostData) {
|
||||||
getObjects(serviceFields, serviceFilters, 'services', serviceAdditionnalFields)
|
getObjects(serviceFields, serviceFilters, 'services', serviceAdditionnalFields)
|
||||||
@ -402,30 +351,11 @@ angular.module('adagios.live')
|
|||||||
var host_name = hostData[i].host_name;
|
var host_name = hostData[i].host_name;
|
||||||
|
|
||||||
angular.forEach(hostData[i], function (value, field) {
|
angular.forEach(hostData[i], function (value, field) {
|
||||||
var field_ = undefined,
|
if (!(host_name in hostDict)) {
|
||||||
skip = false;
|
hostDict[host_name] = {};
|
||||||
|
|
||||||
if (field === 'host_name') {
|
|
||||||
skip = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip) {
|
hostDict[host_name][field] = value;
|
||||||
angular.forEach(hostKeys, function (value, key) {
|
|
||||||
if (value === field) {
|
|
||||||
field_ = key;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (field === undefined) {
|
|
||||||
field_ = field;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(host_name in hostDict)) {
|
|
||||||
hostDict[host_name] = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
hostDict[host_name][field_] = value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ angular.module('adagios.table.cell_host', ['adagios.table'])
|
|||||||
$scope.state = 'state--ok';
|
$scope.state = 'state--ok';
|
||||||
} else if ($scope.entry.host_state === 1) {
|
} else if ($scope.entry.host_state === 1) {
|
||||||
$scope.state = 'state--warning';
|
$scope.state = 'state--warning';
|
||||||
} else if ($scope.entry.host_state === "") {
|
} else if ($scope.entry.host_state === '') {
|
||||||
$scope.state = '';
|
$scope.state = '';
|
||||||
} else {
|
} else {
|
||||||
$scope.state = 'state--error';
|
$scope.state = 'state--error';
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
angular.module('adagios.view.host', ['adagios.live'])
|
angular.module('adagios.view.host', ['adagios.live'])
|
||||||
|
|
||||||
.controller('HostViewCtrl', ['$http', '$scope', '$routeParams', 'getObjectId', 'getObjectById', 'addObjectToScope',
|
.controller('HostViewCtrl', ['$http', '$scope', '$routeParams',
|
||||||
function ($http, $scope, $routeParams, getObjectId, getObjectById, addObjectToScope) {
|
function ($http, $scope, $routeParams) {
|
||||||
if (!!$routeParams.host_name) {
|
if (!!$routeParams.host_name) {
|
||||||
$scope.hostName = $routeParams.host_name;
|
$scope.hostName = $routeParams.host_name;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user