Modularized syscheck and rootcheck validations

This commit is contained in:
Jesús Ángel González 2018-06-12 14:46:01 +02:00 committed by Javier Castro
parent 277789c95a
commit 24312e183a
2 changed files with 24 additions and 33 deletions

View File

@ -152,47 +152,20 @@ app.controller('agentsController', function ($timeout, $scope, $location, $rootS
};
// Agent data
$scope.getAgentStatusClass = (agentStatus) => agentStatus === "Active" ? "teal" : "red";
$scope.getAgentStatusClass = agentStatus => agentStatus === "Active" ? "teal" : "red";
$scope.formatAgentStatus = (agentStatus) => {
$scope.formatAgentStatus = agentStatus => {
return ['Active','Disconnected'].includes(agentStatus) ? agentStatus : 'Never connected';
};
const validateRootCheck = () => {
$scope.agent.rootcheck.duration = 'Unknown';
if ($scope.agent.rootcheck.end && $scope.agent.rootcheck.start) {
$scope.agent.rootcheck.duration = ((new Date($scope.agent.rootcheck.end) - new Date($scope.agent.rootcheck.start))/1000)/60;
$scope.agent.rootcheck.duration = Math.round($scope.agent.rootcheck.duration * 100) / 100;
if($scope.agent.rootcheck.duration <= 0){
$scope.agent.rootcheck.inProgress = true;
}
} else {
if (!$scope.agent.rootcheck.end) {
$scope.agent.rootcheck.end = 'Unknown';
}
if (!$scope.agent.rootcheck.start){
$scope.agent.rootcheck.start = 'Unknown';
}
}
const result = commonData.validateRange($scope.agent.rootcheck)
$scope.agent.rootcheck = result;
}
const validateSysCheck = () => {
$scope.agent.syscheck.duration = 'Unknown';
if ($scope.agent.syscheck.end && $scope.agent.syscheck.start) {
$scope.agent.syscheck.duration = ((new Date($scope.agent.syscheck.end) - new Date($scope.agent.syscheck.start))/1000)/60;
$scope.agent.syscheck.duration = Math.round($scope.agent.syscheck.duration * 100) / 100;
if($scope.agent.syscheck.duration <= 0){
$scope.agent.syscheck.inProgress = true;
}
} else {
if (!$scope.agent.syscheck.end) {
$scope.agent.syscheck.end = 'Unknown';
}
if (!$scope.agent.syscheck.start){
$scope.agent.syscheck.start = 'Unknown';
}
}
const result = commonData.validateRange($scope.agent.syscheck)
$scope.agent.syscheck = result;
}
$scope.getAgent = async (newAgentId,fromAutocomplete) => {

View File

@ -83,6 +83,24 @@ app.service('commonData', function ($rootScope, $timeout, genericReq, appState,
} catch(error) {
errorHandler.handle('An error occurred while creating custom filters for visualizations',agent ? 'Agents' : 'Overview',true);
}
},
validateRange: data => {
const result = {
duration : 'Unknown',
inProgress: false,
end : data.end || 'Unknown',
start : data.start || 'Unknown'
}
if(data.end && data.start) {
result.duration = ((new Date(data.end) - new Date(data.start))/1000)/60;
result.duration = Math.round(result.duration * 100) / 100;
if(result.duration <= 0){
result.inProgress = true;
}
}
return result;
}
}
});