2016-06-29 01:43:18 +00:00
|
|
|
// Require config
|
|
|
|
var app = require('ui/modules').get('app/wazuh', []);
|
|
|
|
|
2016-08-23 14:27:42 +00:00
|
|
|
app.controller('agentsController', function ($scope, DataFactory, $mdToast) {
|
2016-06-29 01:43:18 +00:00
|
|
|
//Initialisation
|
|
|
|
$scope.load = true;
|
2016-07-20 17:34:15 +00:00
|
|
|
$scope.agentInfo = [];
|
2016-08-24 14:13:53 +00:00
|
|
|
$scope.$parent.submenuNavItem = 'overview';
|
2016-06-29 01:43:18 +00:00
|
|
|
|
|
|
|
var objectsArray = [];
|
|
|
|
|
|
|
|
//Print Error
|
|
|
|
var printError = function (error) {
|
2016-07-19 10:38:29 +00:00
|
|
|
$mdToast.show({
|
|
|
|
template: '<md-toast>' + error.html + '</md-toast>',
|
|
|
|
position: 'bottom left',
|
2016-07-21 16:02:09 +00:00
|
|
|
hideDelay: 5000,
|
2016-07-19 10:38:29 +00:00
|
|
|
});
|
2016-07-28 15:58:25 +00:00
|
|
|
if ($scope.blocked) {
|
|
|
|
$scope.blocked = false;
|
|
|
|
}
|
2016-07-19 10:38:29 +00:00
|
|
|
};
|
2016-06-29 01:43:18 +00:00
|
|
|
|
|
|
|
//Functions
|
2016-07-18 14:54:06 +00:00
|
|
|
|
2016-06-29 01:43:18 +00:00
|
|
|
$scope.getAgentStatusClass = function (agentStatus) {
|
|
|
|
if (agentStatus == "Active")
|
|
|
|
return "green"
|
|
|
|
else if (agentStatus == "Disconnected")
|
|
|
|
return "red";
|
|
|
|
else
|
|
|
|
return "red";
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.fetchAgent = function (agent) {
|
2016-06-29 11:15:33 +00:00
|
|
|
DataFactory.getAndClean('get', '/agents/' + agent.id, {})
|
|
|
|
.then(function (data) {
|
2016-07-20 17:34:15 +00:00
|
|
|
$scope.agentInfo = data.data;
|
2016-06-29 11:15:33 +00:00
|
|
|
if (agent.id != '000') {
|
|
|
|
DataFactory.getAndClean('get', '/agents/' + agent.id + '/key', {})
|
|
|
|
.then(function (data) {
|
2016-07-20 17:34:15 +00:00
|
|
|
$scope.agentInfo.key = data.data;
|
2016-08-23 14:27:42 +00:00
|
|
|
$scope.load = false;
|
2016-06-29 11:15:33 +00:00
|
|
|
}, printError);
|
|
|
|
}
|
|
|
|
}, printError);
|
2016-08-23 14:27:42 +00:00
|
|
|
$scope.fetchFim(agent);
|
|
|
|
$scope.fetchRootcheck(agent);
|
2016-06-29 01:43:18 +00:00
|
|
|
};
|
|
|
|
|
2016-07-12 09:11:52 +00:00
|
|
|
$scope.fetchFim = function (agent) {
|
|
|
|
DataFactory.getAndClean('get', '/syscheck/' + agent.id + '/files', { 'offset': 0, 'limit': 5 })
|
|
|
|
.then(function (data) {
|
2016-07-20 17:34:15 +00:00
|
|
|
$scope.agentInfo.syscheckEvents = data.data.items;
|
2016-07-12 09:11:52 +00:00
|
|
|
}, printError);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.fetchRootcheck = function (agent) {
|
|
|
|
DataFactory.getAndClean('get', '/rootcheck/' + agent.id, { 'offset': 0, 'limit': 5 })
|
|
|
|
.then(function (data) {
|
2016-07-20 17:34:15 +00:00
|
|
|
$scope.agentInfo.rootcheckEvents = data.data.items;
|
2016-07-12 09:11:52 +00:00
|
|
|
}, printError);
|
|
|
|
};
|
|
|
|
|
2016-06-29 01:43:18 +00:00
|
|
|
$scope.restart = function (agent) {
|
2016-08-23 14:27:42 +00:00
|
|
|
$mdToast.show({
|
|
|
|
template: '<md-toast>Restarting agent...</md-toast>',
|
|
|
|
position: 'bottom left',
|
|
|
|
hideDelay: 5000,
|
2016-06-29 01:43:18 +00:00
|
|
|
});
|
2016-08-23 14:27:42 +00:00
|
|
|
DataFactory.getAndClean('put', '/agents/' + agent.id + '/restart', {})
|
2016-06-29 01:43:18 +00:00
|
|
|
.then(function (data) {
|
2016-08-23 14:27:42 +00:00
|
|
|
$mdToast.show({
|
|
|
|
template: '<md-toast>Restarted successfully.</md-toast>',
|
|
|
|
position: 'bottom left',
|
|
|
|
hideDelay: 5000,
|
|
|
|
});
|
2016-06-29 01:43:18 +00:00
|
|
|
}, printError);
|
|
|
|
};
|
|
|
|
|
2016-08-24 17:27:40 +00:00
|
|
|
$scope.getDiscoverByAgent = function (agent) {
|
|
|
|
var _urlStr = '/app/kibana#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-7d,mode:quick,to:now))&_a=(columns:!(_source),filters:!((\'$state\':(store:appState),meta:(alias:!n,disabled:!f,index:\'ossec-*\',key:AgentName,negate:!f,value:\'';
|
|
|
|
var _urlStrSf = '\'),query:(match:(AgentName:(query:\'';
|
|
|
|
var _urlStrSSf = '\',type:phrase))))),index:\'ossec-*\',interval:auto,query:(query_string:(analyze_wildcard:!t,query:\'*\')),sort:!(\'@timestamp\',desc),vis:(aggs:!((params:(field:AgentName,orderBy:\'2\',size:20),schema:segment,type:terms),(id:\'2\',schema:metric,type:count)),type:histogram))&indexPattern=ossec-*&type=histogram';
|
|
|
|
|
|
|
|
return _urlStr + agent.name + _urlStrSf + agent.name + _urlStrSSf;
|
|
|
|
}
|
|
|
|
|
2016-06-29 01:43:18 +00:00
|
|
|
$scope.addAgent = function () {
|
|
|
|
if ($scope.newName == undefined) {
|
|
|
|
notify.error('Error adding agent: Specify an agent name');
|
|
|
|
}
|
|
|
|
else if ($scope.newIp == undefined) {
|
|
|
|
notify.error('Error adding agent: Specify an IP address');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DataFactory.getAndClean('post', '/agents', {
|
|
|
|
name: $scope.newName,
|
|
|
|
ip: $scope.newIp
|
|
|
|
}).then(function (data) {
|
2016-07-21 16:02:09 +00:00
|
|
|
$mdToast.show($mdToast.simple().textContent('Agent added successfully.'));
|
2016-06-29 13:44:36 +00:00
|
|
|
$scope.agentsGet();
|
2016-06-29 01:43:18 +00:00
|
|
|
}, printError);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//Load
|
2016-08-24 14:13:53 +00:00
|
|
|
$scope.$watch(function () {
|
|
|
|
return $scope.$parent._agent;
|
|
|
|
}, function () {
|
|
|
|
$scope.fetchAgent($scope.$parent._agent);
|
|
|
|
});
|
2016-06-29 01:43:18 +00:00
|
|
|
|
|
|
|
//Destroy
|
|
|
|
$scope.$on("$destroy", function () {
|
2016-06-30 09:27:47 +00:00
|
|
|
angular.forEach(objectsArray, function (value) {
|
2016-08-23 14:27:42 +00:00
|
|
|
DataFactory.clean(value)
|
|
|
|
});
|
2016-06-29 01:43:18 +00:00
|
|
|
});
|
|
|
|
|
2016-08-03 03:15:37 +00:00
|
|
|
});
|