2017-10-30 09:08:42 +00:00
|
|
|
let app = require('ui/modules').get('app/wazuh', []);
|
2016-09-16 18:44:04 +00:00
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
app.controller('agentsPreviewController', function ($scope,$rootScope, genericReq, apiReq, appState, Agents, $location, errorHandler) {
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.loading = true;
|
|
|
|
$scope.agents = Agents;
|
|
|
|
$scope.status = 'all';
|
|
|
|
$scope.osPlatform = 'all';
|
|
|
|
$scope.osPlatforms = [];
|
2018-01-29 11:37:29 +00:00
|
|
|
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.mostActiveAgent = {
|
2018-01-29 11:37:29 +00:00
|
|
|
name: '',
|
|
|
|
id : ''
|
2017-10-30 09:08:42 +00:00
|
|
|
};
|
2016-09-16 18:44:04 +00:00
|
|
|
|
2017-12-03 14:30:47 +00:00
|
|
|
let tmpUrl, tmpUrl2;
|
|
|
|
if (appState.getClusterInfo().status === 'enabled') {
|
|
|
|
tmpUrl = `/api/wazuh-elastic/top/cluster/${appState.getClusterInfo().cluster}/agent.name`;
|
|
|
|
tmpUrl2 = `/api/wazuh-elastic/top/cluster/${appState.getClusterInfo().cluster}/agent.id`;
|
|
|
|
} else {
|
|
|
|
tmpUrl = `/api/wazuh-elastic/top/manager/${appState.getClusterInfo().manager}/agent.name`;
|
|
|
|
tmpUrl2 = `/api/wazuh-elastic/top/manager/${appState.getClusterInfo().manager}/agent.id`;
|
|
|
|
}
|
2016-09-16 18:44:04 +00:00
|
|
|
|
2017-12-21 09:39:54 +00:00
|
|
|
$scope.applyFilters = filter => {
|
2017-12-21 10:22:38 +00:00
|
|
|
$scope.agents.filters = [];
|
|
|
|
if(filter.includes('Unknown')){
|
|
|
|
$scope.agents.addFilter('status','Never connected');
|
|
|
|
} else {
|
|
|
|
const platform = filter.split(' - ')[0];
|
|
|
|
const version = filter.split(' - ')[1];
|
2017-12-21 10:32:05 +00:00
|
|
|
$scope.agents.addMultipleFilters([
|
|
|
|
{ name: 'os.platform', value: platform },
|
|
|
|
{ name: 'os.version', value: version }
|
|
|
|
]);
|
2017-12-21 10:22:38 +00:00
|
|
|
}
|
2017-12-21 09:39:54 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 16:18:04 +00:00
|
|
|
// Retrieve os list
|
2017-12-21 09:33:15 +00:00
|
|
|
const retrieveList = agents => {
|
|
|
|
for(let agent of agents){
|
|
|
|
|
2017-11-24 16:18:04 +00:00
|
|
|
if('os' in agent && 'name' in agent.os){
|
2017-12-12 16:59:19 +00:00
|
|
|
let exists = $scope.osPlatforms.filter((e) => e.name === agent.os.name && e.platform === agent.os.platform && e.version === agent.os.version);
|
2017-11-24 16:18:04 +00:00
|
|
|
if(!exists.length){
|
|
|
|
$scope.osPlatforms.push({
|
|
|
|
name: agent.os.name,
|
|
|
|
platform: agent.os.platform,
|
|
|
|
version: agent.os.version
|
|
|
|
});
|
2017-11-02 09:22:15 +00:00
|
|
|
}
|
2017-10-30 09:08:42 +00:00
|
|
|
}
|
2017-11-24 16:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 11:37:29 +00:00
|
|
|
const load = async () => {
|
|
|
|
try{
|
|
|
|
const data = await Promise.all([
|
|
|
|
$scope.agents.nextPage(),
|
|
|
|
apiReq.request('GET', '/agents/summary', { }),
|
|
|
|
genericReq.request('GET', tmpUrl),
|
|
|
|
apiReq.request('GET', '/agents', { sort:'-date_add', limit:9999999 })
|
|
|
|
]);
|
2017-11-24 16:18:04 +00:00
|
|
|
|
|
|
|
// Agents summary
|
|
|
|
if(parseInt(data[1].data.data['Never connected']) > 0){
|
2017-11-08 15:00:58 +00:00
|
|
|
$scope.osPlatforms.push({
|
|
|
|
name: 'Unknown',
|
|
|
|
platform: 'Unknown',
|
2017-12-21 10:22:38 +00:00
|
|
|
version: ''
|
2017-11-08 15:00:58 +00:00
|
|
|
});
|
|
|
|
}
|
2017-11-24 16:18:04 +00:00
|
|
|
$scope.agentsCountActive = data[1].data.data.Active;
|
|
|
|
$scope.agentsCountDisconnected = data[1].data.data.Disconnected;
|
|
|
|
$scope.agentsCountNeverConnected = data[1].data.data['Never connected'];
|
|
|
|
$scope.agentsCountTotal = data[1].data.data.Total;
|
|
|
|
$scope.agentsCoverity = (data[1].data.data.Active / data[1].data.data.Total) * 100;
|
2016-09-16 18:44:04 +00:00
|
|
|
|
2017-11-24 16:18:04 +00:00
|
|
|
// tmpUrl y tmpUrl2
|
|
|
|
if (data[2].data.data === '') {
|
2017-12-18 12:00:00 +00:00
|
|
|
$scope.mostActiveAgent.name = appState.getClusterInfo().manager;
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.mostActiveAgent.id = '000';
|
2017-11-24 16:18:04 +00:00
|
|
|
} else {
|
|
|
|
$scope.mostActiveAgent.name = data[2].data.data;
|
2018-01-29 11:37:29 +00:00
|
|
|
const info = await genericReq.request('GET', tmpUrl2);
|
|
|
|
if (info.data.data === '' && $scope.mostActiveAgent.name !== '') {
|
|
|
|
$scope.mostActiveAgent.id = '000';
|
|
|
|
} else {
|
|
|
|
$scope.mostActiveAgent.id = info.data.data;
|
|
|
|
}
|
2017-10-30 09:08:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-24 16:18:04 +00:00
|
|
|
// Last agent
|
2017-12-21 09:33:15 +00:00
|
|
|
$scope.lastAgent = data[3].data.data.items[0];
|
|
|
|
|
|
|
|
retrieveList(data[3].data.data.items);
|
2017-11-24 16:18:04 +00:00
|
|
|
|
|
|
|
$scope.loading = false;
|
2018-01-26 10:21:50 +00:00
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
2018-01-29 11:37:29 +00:00
|
|
|
return;
|
|
|
|
} catch (error) {
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle(error,'Agents Preview');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2018-01-29 11:37:29 +00:00
|
|
|
}
|
2016-09-16 18:44:04 +00:00
|
|
|
};
|
|
|
|
|
2017-11-28 15:42:00 +00:00
|
|
|
$scope.showAgent = agent => {
|
2017-11-29 09:55:47 +00:00
|
|
|
$rootScope.globalAgent = agent.id;
|
2017-11-28 15:46:10 +00:00
|
|
|
$rootScope.comeFrom = 'agentsPreview';
|
2017-11-28 15:42:00 +00:00
|
|
|
$location.path('/agents');
|
|
|
|
};
|
|
|
|
|
2016-09-16 18:44:04 +00:00
|
|
|
//Load
|
2018-01-29 11:37:29 +00:00
|
|
|
load();
|
|
|
|
|
2016-09-16 18:44:04 +00:00
|
|
|
//Destroy
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.$on("$destroy", () => $scope.agents.reset());
|
2017-11-20 18:20:27 +00:00
|
|
|
});
|