2016-09-16 18:44:04 +00:00
|
|
|
// Require config
|
2016-12-29 15:19:37 +00:00
|
|
|
require('plugins/wazuh/utils/infinite_scroll/infinite-scroll.js');
|
2016-09-16 18:44:04 +00:00
|
|
|
var app = require('ui/modules').get('app/wazuh', []);
|
|
|
|
|
2016-12-29 15:19:37 +00:00
|
|
|
app.factory('Agents', function($http, DataFactory) {
|
2017-05-22 15:37:57 +00:00
|
|
|
var Agents = function(objectsArray, items, os_list) {
|
2016-12-29 15:19:37 +00:00
|
|
|
this.items = items;
|
|
|
|
this.objectsArray = objectsArray;
|
|
|
|
this.busy = false;
|
2017-05-22 15:37:57 +00:00
|
|
|
this.os_list = os_list;
|
2016-12-29 15:19:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Agents.prototype.nextPage = function() {
|
|
|
|
|
|
|
|
if (this.busy) return;
|
|
|
|
this.busy = true;
|
|
|
|
DataFactory.next(this.objectsArray['/agents']).then(function (data) {
|
|
|
|
var items = data.data.items;
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
this.items.push(items[i]);
|
|
|
|
}
|
|
|
|
this.busy = false;
|
|
|
|
}.bind(this),
|
|
|
|
function (data) {
|
|
|
|
this.busy = false;
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
};
|
|
|
|
return Agents;
|
|
|
|
});
|
|
|
|
|
2017-02-24 13:29:29 +00:00
|
|
|
app.controller('agentsPreviewController', function ($scope, DataFactory, Notifier, errlog, genericReq, Agents) {
|
2016-09-16 18:44:04 +00:00
|
|
|
|
|
|
|
$scope.load = true;
|
|
|
|
$scope.agents = [];
|
|
|
|
$scope._status = 'all';
|
2017-05-22 15:37:57 +00:00
|
|
|
$scope._os = 'all';
|
2016-11-10 23:07:57 +00:00
|
|
|
$scope.defaultManager = $scope.$parent.state.getDefaultManager().name;
|
|
|
|
$scope.mostActiveAgent = {"name" : "", "id" : ""};
|
2017-02-24 13:29:29 +00:00
|
|
|
const notify = new Notifier({location: 'Agents - Preview'});
|
|
|
|
|
2016-09-16 18:44:04 +00:00
|
|
|
var objectsArray = [];
|
|
|
|
|
|
|
|
//Print Error
|
|
|
|
var printError = function (error) {
|
2017-02-24 13:29:29 +00:00
|
|
|
notify.error(error.message);
|
2016-09-16 18:44:04 +00:00
|
|
|
if ($scope.blocked) {
|
|
|
|
$scope.blocked = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//Functions
|
|
|
|
$scope.setSort = function (field) {
|
2016-12-29 15:19:37 +00:00
|
|
|
$scope._sort = field;
|
|
|
|
$scope._sortOrder = !$scope._sortOrder;
|
|
|
|
if ($scope._sortOrder) {
|
|
|
|
DataFactory.filters.set(objectsArray['/agents'], 'filter-sort',field);
|
|
|
|
} else {
|
|
|
|
DataFactory.filters.set(objectsArray['/agents'], 'filter-sort', '-' + field);
|
|
|
|
}
|
|
|
|
|
|
|
|
DataFactory.setOffset(objectsArray['/agents'],0);
|
|
|
|
DataFactory.get(objectsArray['/agents']).then(function (data) {
|
|
|
|
$scope.agents.items = data.data.items;
|
|
|
|
});
|
2016-09-20 08:55:43 +00:00
|
|
|
};
|
2016-09-16 18:44:04 +00:00
|
|
|
|
|
|
|
$scope.agentSearchFilter = function (search) {
|
|
|
|
if (search) {
|
|
|
|
DataFactory.filters.set(objectsArray['/agents'], 'search', search);
|
|
|
|
} else {
|
|
|
|
DataFactory.filters.unset(objectsArray['/agents'], 'search');
|
|
|
|
}
|
2017-01-16 18:41:10 +00:00
|
|
|
DataFactory.setOffset(objectsArray['/agents'],0);
|
|
|
|
DataFactory.get(objectsArray['/agents']).then(function (data) {
|
|
|
|
$scope.agents.items = data.data.items;
|
|
|
|
});
|
2016-09-16 18:44:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.agentStatusFilter = function (status) {
|
|
|
|
if (status == 'all') {
|
|
|
|
DataFactory.filters.unset(objectsArray['/agents'], 'status');
|
|
|
|
} else {
|
|
|
|
DataFactory.filters.set(objectsArray['/agents'], 'status', status);
|
|
|
|
}
|
2017-01-16 18:41:10 +00:00
|
|
|
DataFactory.setOffset(objectsArray['/agents'],0);
|
|
|
|
DataFactory.get(objectsArray['/agents']).then(function (data) {
|
|
|
|
$scope.agents.items = data.data.items;
|
|
|
|
});
|
2016-09-16 18:44:04 +00:00
|
|
|
};
|
2017-05-22 15:37:57 +00:00
|
|
|
|
|
|
|
$scope.agentOSFilter = function (os) {
|
|
|
|
if (os == 'all') {
|
|
|
|
DataFactory.filters.unset(objectsArray['/agents'], 'os');
|
|
|
|
} else {
|
|
|
|
DataFactory.filters.set(objectsArray['/agents'], 'os', os);
|
|
|
|
}
|
|
|
|
DataFactory.setOffset(objectsArray['/agents'],0);
|
|
|
|
DataFactory.get(objectsArray['/agents']).then(function (data) {
|
|
|
|
$scope.agents.items = data.data.items;
|
|
|
|
});
|
|
|
|
};
|
2016-09-16 18:44:04 +00:00
|
|
|
|
|
|
|
var load = function () {
|
2016-12-29 15:19:37 +00:00
|
|
|
DataFactory.initialize('get', '/agents', {}, 30, 0)
|
2016-09-16 18:44:04 +00:00
|
|
|
.then(function (data) {
|
|
|
|
objectsArray['/agents'] = data;
|
2016-12-29 15:19:37 +00:00
|
|
|
DataFactory.filters.register(objectsArray['/agents'], 'search', 'string');
|
|
|
|
DataFactory.filters.register(objectsArray['/agents'], 'status', 'string');
|
2017-05-22 15:37:57 +00:00
|
|
|
DataFactory.filters.register(objectsArray['/agents'], 'os', 'string');
|
2016-12-29 15:19:37 +00:00
|
|
|
DataFactory.filters.register(objectsArray['/agents'], 'filter-sort', 'string');
|
2016-09-16 18:44:04 +00:00
|
|
|
DataFactory.get(objectsArray['/agents'])
|
|
|
|
.then(function (data) {
|
2017-05-22 15:37:57 +00:00
|
|
|
$scope.agents = new Agents(objectsArray, data.data.items, data.data.os_list);
|
2016-09-16 18:44:04 +00:00
|
|
|
$scope.load = false;
|
|
|
|
}, printError);
|
|
|
|
}, printError);
|
2016-10-02 14:09:46 +00:00
|
|
|
|
|
|
|
DataFactory.getAndClean('get', '/agents', { offset: 0, limit: 1, sort: '-id' })
|
|
|
|
.then(function (data) {
|
|
|
|
DataFactory.getAndClean('get', '/agents/' + data.data.items[0].id, {})
|
|
|
|
.then(function (data) {
|
2016-11-10 23:07:57 +00:00
|
|
|
$scope.lastAgent = data.data;
|
2016-10-02 14:09:46 +00:00
|
|
|
}, printError);
|
|
|
|
}, printError);
|
|
|
|
|
2016-11-10 23:07:57 +00:00
|
|
|
// Tops
|
2017-03-31 17:34:08 +00:00
|
|
|
genericReq.request('GET', '/api/wazuh-elastic/top/'+$scope.defaultManager+'/agent.name')
|
2016-10-02 14:09:46 +00:00
|
|
|
.then(function (data) {
|
2016-11-30 00:43:43 +00:00
|
|
|
if(data.data == ""){
|
|
|
|
$scope.mostActiveAgent.name = $scope.defaultManager;
|
|
|
|
$scope.mostActiveAgent.id = "000";
|
|
|
|
return;
|
|
|
|
}
|
2016-11-10 23:07:57 +00:00
|
|
|
$scope.mostActiveAgent.name = data.data;
|
2017-03-31 17:34:08 +00:00
|
|
|
genericReq.request('GET', '/api/wazuh-elastic/top/'+$scope.defaultManager+'/agent.id')
|
2016-11-10 23:07:57 +00:00
|
|
|
.then(function (data) {
|
|
|
|
if(data.data == "" && $scope.mostActiveAgent.name != ""){
|
|
|
|
$scope.mostActiveAgent.id = "000";
|
|
|
|
}else{
|
|
|
|
$scope.mostActiveAgent.id = data.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
}, printError);
|
2016-10-02 14:09:46 +00:00
|
|
|
}, printError);
|
|
|
|
|
|
|
|
DataFactory.getAndClean('get', '/agents/summary', {})
|
|
|
|
.then(function (data) {
|
|
|
|
$scope.agentsCountActive = data.data.Active;
|
|
|
|
$scope.agentsCountDisconnected = data.data.Disconnected;
|
|
|
|
$scope.agentsCountNeverConnected = data.data['Never connected'];
|
|
|
|
$scope.agentsCountTotal = data.data.Total;
|
|
|
|
$scope.agentsCoverity = (data.data.Active / data.data.Total) * 100;
|
|
|
|
}, printError);
|
2016-09-16 18:44:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Load
|
|
|
|
try {
|
|
|
|
load();
|
|
|
|
} catch (e) {
|
2017-02-24 13:29:29 +00:00
|
|
|
notify.error("Unexpected exception loading controller");
|
2016-09-16 18:44:04 +00:00
|
|
|
errlog.log('Unexpected exception loading controller', e);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Destroy
|
|
|
|
$scope.$on("$destroy", function () {
|
|
|
|
angular.forEach(objectsArray, function (value) {
|
|
|
|
DataFactory.clean(value)
|
|
|
|
});
|
|
|
|
$scope.agents.length = 0;
|
|
|
|
});
|
2017-05-22 15:37:57 +00:00
|
|
|
});
|