Refactored Surveil API Client
Change-Id: Ic8f4f196157073ddba1e0f3d00f2f2cca8ea28ad
This commit is contained in:
parent
63f3ad58d6
commit
8bb198e6f8
@ -9,6 +9,7 @@ angular.module('bansho', [
|
||||
'bansho.utils.promiseManager',
|
||||
'bansho.topbar',
|
||||
'bansho.sidebar',
|
||||
'bansho.surveil',
|
||||
'bansho.host',
|
||||
'bansho.service',
|
||||
'bansho.view',
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.host', ['bansho.live',
|
||||
angular.module('bansho.host', ['bansho.surveil',
|
||||
'bansho.host.main',
|
||||
'bansho.host.load',
|
||||
'bansho.host.cpu',
|
||||
@ -9,16 +9,16 @@ angular.module('bansho.host', ['bansho.live',
|
||||
|
||||
.value('hostConfig', {})
|
||||
|
||||
.controller('HostCtrl', ['$scope', 'hostConfig', 'backendClient', function ($scope, hostConfig, backendClient) {
|
||||
.controller('HostCtrl', ['$scope', 'hostConfig', 'surveilStatus', function ($scope, hostConfig, surveilStatus) {
|
||||
var objectType = 'host',
|
||||
objectIdentifier = {};
|
||||
|
||||
objectIdentifier.host_name = hostConfig.hostName;
|
||||
backendClient.getHost(objectType, objectIdentifier).then(function (data) {
|
||||
surveilStatus.getHost(objectType, objectIdentifier).then(function (data) {
|
||||
$scope.host = data;
|
||||
$scope.data = data;
|
||||
|
||||
backendClient.getServicesByHost($scope.hostName).success(function (data) {
|
||||
surveilStatus.getServicesByHost($scope.hostName).success(function (data) {
|
||||
var i,
|
||||
service;
|
||||
|
||||
@ -40,8 +40,8 @@ angular.module('bansho.host', ['bansho.live',
|
||||
});
|
||||
}])
|
||||
|
||||
.directive('banshoHost', ['$http', '$compile', 'backendClient', 'hostConfig',
|
||||
function ($http, $compile, backendClient, hostConfig) {
|
||||
.directive('banshoHost', ['$http', '$compile', 'surveilStatus', 'hostConfig',
|
||||
function ($http, $compile, surveilStatus, hostConfig) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
compile: function () {
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.host.cpu', ['bansho.live'])
|
||||
angular.module('bansho.host.cpu', ['bansho.surveil'])
|
||||
.directive('banshoHostCpu', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.service', ['bansho.live',
|
||||
angular.module('bansho.service', ['bansho.surveil',
|
||||
'bansho.service.main',
|
||||
'bansho.service.info',
|
||||
'bansho.service.metrics',
|
||||
@ -8,12 +8,12 @@ angular.module('bansho.service', ['bansho.live',
|
||||
|
||||
.value('serviceConfig', {})
|
||||
|
||||
.controller('ServiceCtrl', ['$scope', 'serviceConfig', 'backendClient',
|
||||
function ($scope, serviceConfig, backendClient) {
|
||||
.controller('ServiceCtrl', ['$scope', 'serviceConfig', 'surveilStatus',
|
||||
function ($scope, serviceConfig, surveilStatus) {
|
||||
var hostName = serviceConfig.hostName,
|
||||
description = serviceConfig.description;
|
||||
|
||||
backendClient.getService(hostName, description).success(function (data) {
|
||||
surveilStatus.getService(hostName, description).success(function (data) {
|
||||
$scope.service = data[0];
|
||||
});
|
||||
}])
|
||||
|
67
app/components/surveil/actions.js
Normal file
67
app/components/surveil/actions.js
Normal file
@ -0,0 +1,67 @@
|
||||
/*global jQuery */
|
||||
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.surveil')
|
||||
.service('surveilActions', ['$http', '$q',
|
||||
function ($http, $q) {
|
||||
var acknowledge = function (host_name, service_description, attrs) {
|
||||
var data = {};
|
||||
|
||||
data.host_name = host_name;
|
||||
if (attrs.sticky) {
|
||||
data.sticky = parseInt(attrs.sticky, 10);
|
||||
}
|
||||
|
||||
if (attrs.notify) {
|
||||
data.notify = parseInt(attrs.notify, 10);
|
||||
}
|
||||
|
||||
if (attrs.persistent) {
|
||||
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
|
||||
});
|
||||
};
|
||||
|
||||
var downtime = function (host_name, service_description, attrs) {
|
||||
attrs.host_name = host_name;
|
||||
if (service_description !== undefined) {
|
||||
attrs.service_description = service_description;
|
||||
}
|
||||
|
||||
return $http({
|
||||
url: '/surveil/v2/actions/downtime/',
|
||||
method: 'POST',
|
||||
data: attrs
|
||||
});
|
||||
};
|
||||
|
||||
var recheck = function (host_name, service_description) {
|
||||
var attrs = {};
|
||||
attrs.host_name = host_name;
|
||||
if (service_description !== undefined) {
|
||||
attrs.service_description = service_description;
|
||||
}
|
||||
|
||||
return $http({
|
||||
url: '/surveil/v2/actions/recheck/',
|
||||
method: 'POST',
|
||||
data: attrs
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
acknowledge: acknowledge,
|
||||
downtime: downtime,
|
||||
recheck: recheck
|
||||
};
|
||||
}]);
|
@ -2,8 +2,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.live', [])
|
||||
.service('backendClient', ['$http', '$q',
|
||||
angular.module('bansho.surveil')
|
||||
.service('surveilStatus', ['$http', '$q',
|
||||
function ($http, $q) {
|
||||
var getObjects = function (fields, filters, apiName) {
|
||||
var query = {},
|
||||
@ -339,66 +339,11 @@ angular.module('bansho.live', [])
|
||||
return responsePromise.promise;
|
||||
};
|
||||
|
||||
var acknowledge = function (host_name, service_description, attrs) {
|
||||
var data = {};
|
||||
|
||||
data.host_name = host_name;
|
||||
if (attrs.sticky) {
|
||||
data.sticky = parseInt(attrs.sticky, 10);
|
||||
}
|
||||
|
||||
if (attrs.notify) {
|
||||
data.notify = parseInt(attrs.notify, 10);
|
||||
}
|
||||
|
||||
if (attrs.persistent) {
|
||||
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
|
||||
});
|
||||
};
|
||||
|
||||
var downtime = function (host_name, service_description, attrs) {
|
||||
attrs.host_name = host_name;
|
||||
if (service_description !== undefined) {
|
||||
attrs.service_description = service_description;
|
||||
}
|
||||
|
||||
return $http({
|
||||
url: '/surveil/v2/actions/downtime/',
|
||||
method: 'POST',
|
||||
data: attrs
|
||||
});
|
||||
};
|
||||
|
||||
var recheck = function (host_name, service_description) {
|
||||
var attrs = {};
|
||||
attrs.host_name = host_name;
|
||||
if (service_description !== undefined) {
|
||||
attrs.service_description = service_description;
|
||||
}
|
||||
|
||||
return $http({
|
||||
url: '/surveil/v2/actions/recheck/',
|
||||
method: 'POST',
|
||||
data: attrs
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
getHost: getHost,
|
||||
getObjects : getObjects,
|
||||
getService : getService,
|
||||
hostQueryTransform: hostQueryTransform,
|
||||
acknowledge: acknowledge,
|
||||
getHostOpenProblems: getHostOpenProblems,
|
||||
hostMiddleware: hostMiddleware,
|
||||
getServiceProblems: getServiceProblems,
|
||||
@ -407,8 +352,6 @@ angular.module('bansho.live', [])
|
||||
getTableData: getTableData,
|
||||
getTotalHosts: getTotalHosts,
|
||||
getTotalServices: getTotalServices,
|
||||
downtime: downtime,
|
||||
recheck: recheck,
|
||||
getServicesByHost: getServicesByHost
|
||||
};
|
||||
}]);
|
1
app/components/surveil/surveil.js
Normal file
1
app/components/surveil/surveil.js
Normal file
@ -0,0 +1 @@
|
||||
angular.module('bansho.surveil', []);
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.table.actionbar', ['bansho.table', 'bansho.live', 'bansho.notifications'])
|
||||
angular.module('bansho.table.actionbar', ['bansho.table', 'bansho.surveil', 'bansho.notifications'])
|
||||
|
||||
.service('actionbarFilters', function () {
|
||||
var actionbarFilters = {
|
||||
@ -27,8 +27,8 @@ angular.module('bansho.table.actionbar', ['bansho.table', 'bansho.live', 'bansho
|
||||
return actionbarFilters;
|
||||
})
|
||||
|
||||
.controller('TableActionbarCtrl', ['$scope', '$filter', 'backendClient', 'actionbarFilters', 'tablesConfig',
|
||||
function ($scope, $filter, backendClient, actionbarFilters, tablesConfig, actionbarSelectFilter) {
|
||||
.controller('TableActionbarCtrl', ['$scope', '$filter', 'surveilStatus', 'actionbarFilters', 'tablesConfig',
|
||||
function ($scope, $filter, surveilStatus, actionbarFilters, tablesConfig, actionbarSelectFilter) {
|
||||
$scope.isDowntimeShown = false;
|
||||
$scope.isAcknowledgeShown = false;
|
||||
|
||||
|
@ -14,8 +14,8 @@ angular.module('bansho.table.actionbar')
|
||||
})
|
||||
|
||||
.controller('banshoAcknowledgeFormCtrl',
|
||||
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient', 'notifications',
|
||||
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient, notifications) {
|
||||
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'surveilActions', 'notifications',
|
||||
function ($scope, $filter, tablesConfig, actionbarFilters, surveilActions, notifications) {
|
||||
|
||||
$scope.acknowledgeProblems = function () {
|
||||
angular.forEach(tablesConfig, function (table) {
|
||||
@ -32,7 +32,7 @@ angular.module('bansho.table.actionbar')
|
||||
service_description = entry.description;
|
||||
}
|
||||
|
||||
backendClient.acknowledge(entry.host_name, service_description, $scope.attrs).then(function (data) {
|
||||
surveilActions.acknowledge(entry.host_name, service_description, $scope.attrs).then(function (data) {
|
||||
notifications.push('success', 'Acknowledgement', 'Acknowledged ' + entry.host_name);
|
||||
},
|
||||
function (error) {
|
||||
@ -57,8 +57,8 @@ angular.module('bansho.table.actionbar')
|
||||
})
|
||||
|
||||
.controller('banshoDowntimeFormCtrl',
|
||||
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient', 'notifications',
|
||||
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient, notifications) {
|
||||
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'surveilActions', 'notifications',
|
||||
function ($scope, $filter, tablesConfig, actionbarFilters, surveilActions, notifications) {
|
||||
|
||||
$scope.sendDowntime = function () {
|
||||
angular.forEach(tablesConfig, function (table) {
|
||||
@ -74,7 +74,7 @@ angular.module('bansho.table.actionbar')
|
||||
service_description = entry.description;
|
||||
}
|
||||
|
||||
backendClient.downtime(entry.host_name, service_description, $scope.attrs).then(function (data) {
|
||||
surveilActions.downtime(entry.host_name, service_description, $scope.attrs).then(function (data) {
|
||||
notifications.push('success', 'Downtime', 'Added downtime for ' + entry.host_name);
|
||||
},
|
||||
function (error) {
|
||||
@ -96,8 +96,8 @@ angular.module('bansho.table.actionbar')
|
||||
})
|
||||
|
||||
.controller('banshoRecheckButtonCtrl',
|
||||
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'backendClient', 'notifications',
|
||||
function ($scope, $filter, tablesConfig, actionbarFilters, backendClient, notifications) {
|
||||
['$scope', '$filter', 'tablesConfig', 'actionbarFilters', 'surveilActions', 'notifications',
|
||||
function ($scope, $filter, tablesConfig, actionbarFilters, surveilActions, notifications) {
|
||||
|
||||
$scope.sendRecheck = function () {
|
||||
angular.forEach(tablesConfig, function (table) {
|
||||
@ -113,7 +113,7 @@ angular.module('bansho.table.actionbar')
|
||||
service_description = entry.description;
|
||||
}
|
||||
|
||||
backendClient.recheck(entry.host_name, service_description).then(function (data) {
|
||||
surveilActions.recheck(entry.host_name, service_description).then(function (data) {
|
||||
notifications.push('success', 'Recheck', 'Scheduled recheck for ' + entry.host_name);
|
||||
},
|
||||
function (error) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.table', ['bansho.live',
|
||||
angular.module('bansho.table', ['bansho.surveil',
|
||||
'bansho.utils.promiseManager',
|
||||
'bansho.table.actionbar',
|
||||
'bansho.filters',
|
||||
@ -16,9 +16,9 @@ angular.module('bansho.table', ['bansho.live',
|
||||
|
||||
.value('tablesConfig', [])
|
||||
|
||||
.controller('TableCtrl', ['$scope', '$interval', 'backendClient', 'tablesConfig',
|
||||
.controller('TableCtrl', ['$scope', '$interval', 'surveilStatus', 'tablesConfig',
|
||||
'actionbarFilters', 'promisesManager', 'tableGlobalConfig',
|
||||
function ($scope, $interval, backendClient, tablesConfig, actionbarFilters, promisesManager, tableGlobalConfig) {
|
||||
function ($scope, $interval, surveilStatus, tablesConfig, actionbarFilters, promisesManager, tableGlobalConfig) {
|
||||
var requestFields = [],
|
||||
conf = tablesConfig[tableGlobalConfig.nextTableIndex],
|
||||
getData,
|
||||
@ -53,7 +53,7 @@ angular.module('bansho.table', ['bansho.live',
|
||||
});
|
||||
|
||||
getData = function (requestFields, filters, apiName) {
|
||||
var promise = backendClient.getTableData(requestFields, filters, apiName);
|
||||
var promise = surveilStatus.getTableData(requestFields, filters, apiName);
|
||||
promise.then(function (data) {
|
||||
$scope.entries = data;
|
||||
conf.entries = data;
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.tactical.current_health', ['bansho.live',
|
||||
angular.module('bansho.tactical.current_health', ['bansho.surveil',
|
||||
'ngJustGage'])
|
||||
|
||||
.controller('TacticalCurrentHealth', ['$scope', function ($scope) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.tactical', ['bansho.live',
|
||||
angular.module('bansho.tactical', ['bansho.surveil',
|
||||
'bansho.utils.promiseManager',
|
||||
'bansho.tactical.status_overview',
|
||||
'bansho.tactical.current_health',
|
||||
@ -16,8 +16,8 @@ angular.module('bansho.tactical', ['bansho.live',
|
||||
this.topAlertProducers = config.components.topAlertProducers;
|
||||
})
|
||||
|
||||
.controller('TacticalCtrl', ['$scope', '$interval', 'tacticalConfig', 'backendClient', 'promisesManager',
|
||||
function ($scope, $interval, tacticalConfig, backendClient, promisesManager) {
|
||||
.controller('TacticalCtrl', ['$scope', '$interval', 'tacticalConfig', 'surveilStatus', 'promisesManager',
|
||||
function ($scope, $interval, tacticalConfig, surveilStatus, promisesManager) {
|
||||
|
||||
var getData;
|
||||
|
||||
@ -33,17 +33,17 @@ angular.module('bansho.tactical', ['bansho.live',
|
||||
$scope.totalServices = undefined;
|
||||
|
||||
getData = function () {
|
||||
backendClient.getHostProblems().success(function (hostProblems) {
|
||||
surveilStatus.getHostProblems().success(function (hostProblems) {
|
||||
$scope.hostProblems = hostProblems.length;
|
||||
backendClient.getTotalHosts().success(function (allHosts) {
|
||||
surveilStatus.getTotalHosts().success(function (allHosts) {
|
||||
$scope.totalHosts = allHosts.length;
|
||||
$scope.hostsRatio = ($scope.totalHosts - $scope.hostProblems) / $scope.totalHosts * 100;
|
||||
});
|
||||
});
|
||||
|
||||
backendClient.getServiceProblems().success(function (serviceProblems) {
|
||||
surveilStatus.getServiceProblems().success(function (serviceProblems) {
|
||||
$scope.serviceProblems = serviceProblems.length;
|
||||
backendClient.getTotalServices().success(function (allServices) {
|
||||
surveilStatus.getTotalServices().success(function (allServices) {
|
||||
$scope.totalServices = allServices.length;
|
||||
$scope.servicesRatio = ($scope.totalServices - $scope.serviceProblems) / $scope.totalServices * 100;
|
||||
});
|
||||
|
@ -1,18 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.topbar', ['bansho.live'])
|
||||
angular.module('bansho.topbar', ['bansho.surveil'])
|
||||
|
||||
.controller('TopBarCtrl', ['$rootScope', '$scope', '$interval', 'backendClient', 'promisesManager', 'authService',
|
||||
function ($rootScope, $scope, $interval, backendClient, promisesManager, authService) {
|
||||
.controller('TopBarCtrl', ['$rootScope', '$scope', '$interval', 'surveilStatus', 'promisesManager', 'authService',
|
||||
function ($rootScope, $scope, $interval, surveilStatus, promisesManager, authService) {
|
||||
var getData,
|
||||
hostProblems,
|
||||
serviceProblems;
|
||||
|
||||
getData = function () {
|
||||
if ($rootScope.isAuthenticated) {
|
||||
backendClient.getServiceProblems().success(function (data) {
|
||||
surveilStatus.getServiceProblems().success(function (data) {
|
||||
serviceProblems = data.length;
|
||||
backendClient.getHostProblems().success(function (data) {
|
||||
surveilStatus.getHostProblems().success(function (data) {
|
||||
hostProblems = data.length;
|
||||
$scope.allProblems = serviceProblems + hostProblems;
|
||||
});
|
||||
|
@ -42,7 +42,12 @@
|
||||
<script src="app.js"></script>
|
||||
<script src="components/config/config.js"></script>
|
||||
<script src="components/utils/promise_manager.js"></script>
|
||||
<script src="components/live/live.js"></script>
|
||||
|
||||
<!-- Surveil API client -->
|
||||
<script src="components/surveil/surveil.js"></script>
|
||||
<script src="components/surveil/status.js"></script>
|
||||
<script src="components/surveil/actions.js"></script>
|
||||
|
||||
<script src="components/authentication/authentication.js"></script>
|
||||
<script src="components/ng-justgage/ng-justgage.js"></script>
|
||||
<script src="components/filters/filters.js"></script>
|
||||
|
@ -6,13 +6,13 @@ angular.module('bansho.view.dashboard', ['ngRoute',
|
||||
'bansho.utils.promiseManager',
|
||||
'bansho.tactical',
|
||||
'bansho.table',
|
||||
'bansho.live'
|
||||
'bansho.surveil'
|
||||
])
|
||||
|
||||
.value('dashboardConfig', {})
|
||||
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'configManager', 'dashboardConfig', 'TableConfigObj', 'TacticalConfigObj', 'backendClient', 'promisesManager',
|
||||
function ($scope, $routeParams, $interval, configManager, dashboardConfig, TableConfigObj, TacticalConfigObj, backendClient, promisesManager) {
|
||||
.controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'configManager', 'dashboardConfig', 'TableConfigObj', 'TacticalConfigObj', 'surveilStatus', 'promisesManager',
|
||||
function ($scope, $routeParams, $interval, configManager, dashboardConfig, TableConfigObj, TacticalConfigObj, surveilStatus, promisesManager) {
|
||||
var components = [],
|
||||
component,
|
||||
config,
|
||||
@ -45,17 +45,17 @@ angular.module('bansho.view.dashboard', ['ngRoute',
|
||||
}
|
||||
|
||||
getData = function () {
|
||||
backendClient.getHostOpenProblems().success(function (data) {
|
||||
surveilStatus.getHostOpenProblems().success(function (data) {
|
||||
$scope.nbHostOpenProblems = data.length;
|
||||
backendClient.getServiceOpenProblems().then(function (openProblems) {
|
||||
surveilStatus.getServiceOpenProblems().then(function (openProblems) {
|
||||
$scope.nbServiceOpenProblems = openProblems.length;
|
||||
$scope.totalOpenProblems = $scope.nbServiceOpenProblems + $scope.nbHostOpenProblems;
|
||||
});
|
||||
});
|
||||
|
||||
backendClient.getHostProblems().success(function (data) {
|
||||
surveilStatus.getHostProblems().success(function (data) {
|
||||
$scope.nbHostProblems = data.length;
|
||||
backendClient.getServiceProblems().success(function (data) {
|
||||
surveilStatus.getServiceProblems().success(function (data) {
|
||||
$scope.nbServiceProblems = data.length;
|
||||
$scope.totalProblems = $scope.nbHostProblems + $scope.nbServiceProblems;
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('bansho.view.host', ['bansho.live'])
|
||||
angular.module('bansho.view.host', ['bansho.surveil'])
|
||||
|
||||
.controller('HostViewCtrl', ['$http', '$scope', '$routeParams',
|
||||
function ($http, $scope, $routeParams) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
angular.module("bansho.view.service", [ "bansho.live" ])
|
||||
angular.module("bansho.view.service", [ "bansho.surveil" ])
|
||||
|
||||
.controller("ServiceViewCtrl", [ "$scope", "$routeParams",
|
||||
function ($scope, $routeParams) {
|
||||
|
Loading…
Reference in New Issue
Block a user