Merge pull request #146 from wazuh/3.0-dev-agents-prev-fix

Fixes on agents preview tab
This commit is contained in:
Javier Castro 2017-12-21 16:46:27 +01:00 committed by GitHub
commit 4007c0db80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 13 deletions

View File

@ -21,9 +21,24 @@ app.controller('agentsPreviewController', function ($scope,$rootScope, Notifier,
tmpUrl2 = `/api/wazuh-elastic/top/manager/${appState.getClusterInfo().manager}/agent.id`;
}
$scope.applyFilters = filter => {
$scope.agents.filters = [];
if(filter.includes('Unknown')){
$scope.agents.addFilter('status','Never connected');
} else {
const platform = filter.split(' - ')[0];
const version = filter.split(' - ')[1];
$scope.agents.addMultipleFilters([
{ name: 'os.platform', value: platform },
{ name: 'os.version', value: version }
]);
}
}
// Retrieve os list
const retrieveList = () => {
for(let agent of $scope.agents.items){
const retrieveList = agents => {
for(let agent of agents){
if('os' in agent && 'name' in agent.os){
let exists = $scope.osPlatforms.filter((e) => e.name === agent.os.name && e.platform === agent.os.platform && e.version === agent.os.version);
if(!exists.length){
@ -42,19 +57,18 @@ app.controller('agentsPreviewController', function ($scope,$rootScope, Notifier,
$scope.agents.nextPage(''),
apiReq.request('GET', '/agents/summary', { }),
genericReq.request('GET', tmpUrl),
apiReq.request('GET', '/agents', { sort:'-date_add', limit:1 })
apiReq.request('GET', '/agents', { sort:'-date_add', limit:9999999 })
])
.then(data => {
// Next page
retrieveList();
// Agents summary
if(parseInt(data[1].data.data['Never connected']) > 0){
$scope.osPlatforms.push({
name: 'Unknown',
platform: 'Unknown',
version: 'Unknown'
version: ''
});
}
$scope.agentsCountActive = data[1].data.data.Active;
@ -82,7 +96,9 @@ app.controller('agentsPreviewController', function ($scope,$rootScope, Notifier,
}
// Last agent
$scope.lastAgent = data[3].data.data.items[0]
$scope.lastAgent = data[3].data.data.items[0];
retrieveList(data[3].data.data.items);
$scope.loading = false;
$scope.$digest();

View File

@ -311,6 +311,12 @@ let app = require('ui/modules').get('app/wazuh', []).controller('settingsControl
case 'wrong_credentials':
text = 'Wrong Wazuh API credentials, please check them and try again';
break;
case 'invalid_url':
text = 'Wrong Wazuh API url, please check it and try again';
break;
case 'invalid_port':
text = 'Wrong Wazuh API port, please check it and try again';
break;
default:
text = `Unexpected error. ${error.message}`;
}

View File

@ -92,6 +92,14 @@ app.factory('DataHandler', function ($q, apiReq) {
return this.search();
}
///////////////////////////////////////////////////////////////
// Only used by agents preview, don't use for any thing more //
///////////////////////////////////////////////////////////////
addMultipleFilters (arrayOfFilters) {
this.filters = [...arrayOfFilters];
return this.search();
}
removeFilter (filterName, search) {
if(search) this.filters = this.filters.filter(filter => filterName !== filter.name && filter.value !== search);
else this.filters = this.filters.filter(filter => filterName !== filter.name);

View File

@ -32,11 +32,15 @@ require('ui/modules').get('app/wazuh', [])
}
})
.catch(error => {
if(error.status && error.status === -1){
if(error.data && error.data.message && error.data.message.includes('ENOTFOUND')) {
defered.reject({data: 'invalid_url'});
} else if(error.data && error.data.message && error.data.message.includes('ECONNREFUSED')) {
defered.reject({data: 'invalid_port'});
} else if(error.status && error.status === -1){
defered.reject({data: 'request_timeout_checkapi'});
} else if (error.data && error.data.message && error.data.message === 'wrong_credentials') {
defered.reject({data: 'wrong_credentials'});
}else if (error.error) {
} else if (error.error) {
defered.reject(error);
}
});

View File

@ -53,10 +53,10 @@
</md-input-container>
<md-input-container flex="20" class="md-block md-whiteframe-z1">
<md-select id="eventBox" ng-model="osPlatform" ng-change="agents.addFilter('os.platform', osPlatform)" aria-label="Filter by operative system">
<md-select id="eventBox" ng-model="osPlatform" ng-change="applyFilters(osPlatform)" aria-label="Filter by operative system">
<md-option value="all">All OS platforms</md-option>
<md-option ng-repeat='platform in osPlatforms' value="{{platform.platform}}">
{{platform.name}}
<md-option ng-repeat='platform in osPlatforms' value="{{platform.platform}} - {{platform.version}}">
{{platform.name}} {{platform.version}}
</md-option>
</md-select>
</md-input-container>
@ -93,7 +93,7 @@
<span flex="25">{{agent.name || 'Unknown'}}</span>
<span flex="10">{{agent.ip || 'Unknown'}}</span>
<span flex="15">{{agent.status || 'Unknown'}}</span>
<span flex="15">{{agent.os.platform || 'Unknown'}}</span>
<span flex="15">{{agent.os.name || 'Unknown'}}</span>
<span flex="15">{{agent.os.version || 'Unknown'}}</span>
<span flex="15">{{agent.version || 'Unknown'}}</span>
</md-list-item>