wazuh-kibana-app/public/controllers/policy-monitoring.js

157 lines
5.7 KiB
JavaScript
Raw Normal View History

2016-06-29 01:43:18 +00:00
// Require config
2016-07-08 12:26:48 +00:00
var app = require('ui/modules').get('app/wazuh', []);
2016-06-29 01:43:18 +00:00
2016-09-20 08:55:43 +00:00
app.controller('pmController', function ($scope, DataFactory, $mdToast, errlog) {
2016-07-08 12:26:48 +00:00
//Initialisation
$scope.load = true;
var objectsArray = [];
2016-09-20 08:55:43 +00:00
var loadWatch;
2016-09-14 13:58:41 +00:00
2016-07-08 12:26:48 +00:00
$scope.events = [];
//Print Error
var printError = function (error) {
$mdToast.show({
template: '<md-toast>' + error.html + '</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
2016-07-28 15:58:25 +00:00
if ($scope._eblocked) {
$scope._eblocked = false;
}
2016-07-08 12:26:48 +00:00
}
//Functions
2016-09-22 15:24:30 +00:00
$scope.setTimer = function (time) {
$scope.timerFilterValue = time;
};
2016-09-01 12:28:34 +00:00
$scope.setSort = function (field) {
if ($scope._sort === field) {
if ($scope._sortOrder) {
$scope._sortOrder = false;
$scope._sort = '';
DataFactory.filters.unset(objectsArray['/rootcheck'], 'filter-sort');
} else {
$scope._sortOrder = true;
DataFactory.filters.set(objectsArray['/rootcheck'], 'filter-sort', field);
}
} else {
$scope._sortOrder = false;
$scope._sort = field;
2016-09-20 08:55:43 +00:00
DataFactory.filters.set(objectsArray['/rootcheck'], 'filter-sort', '-' + field);
2016-09-01 12:28:34 +00:00
}
}
$scope.eventSearchFilter = function (search) {
if (search) {
DataFactory.filters.set(objectsArray['/rootcheck'], 'search', search);
} else {
DataFactory.filters.unset(objectsArray['/rootcheck'], 'search');
}
};
$scope.eventsObj = {
//Obj with methods for virtual scrolling
getItemAtIndex: function (index) {
if ($scope._eblocked) {
return null;
}
var _pos = index - DataFactory.getOffset(objectsArray['/rootcheck']);
2016-08-31 10:20:04 +00:00
if (DataFactory.filters.flag(objectsArray['/rootcheck'])) {
$scope._eblocked = true;
DataFactory.scrollTo(objectsArray['/rootcheck'], 200)
.then(function (data) {
$scope.events.length = 0;
$scope.events = data.data.items;
DataFactory.filters.unflag(objectsArray['/rootcheck']);
$scope._eblocked = false;
}, printError);
} else if ((_pos > 150) || (_pos < 0)) {
$scope._eblocked = true;
DataFactory.scrollTo(objectsArray['/rootcheck'], index)
.then(function (data) {
$scope.events.length = 0;
$scope.events = data.data.items;
$scope._eblocked = false;
}, printError);
} else {
return $scope.events[_pos];
}
},
getLength: function () {
return DataFactory.getTotalItems(objectsArray['/rootcheck']);
},
};
2016-09-02 17:15:00 +00:00
2016-09-20 08:55:43 +00:00
var createWatch = function () {
2016-08-31 10:20:04 +00:00
loadWatch = $scope.$watch(function () {
return $scope.$parent._agent;
}, function () {
2016-09-20 08:55:43 +00:00
DataFactory.initialize('get', '/rootcheck/' + $scope.$parent._agent.id, {}, 200, 0)
.then(function (data) {
DataFactory.clean(objectsArray['/rootcheck']);
objectsArray['/rootcheck'] = data;
DataFactory.get(objectsArray['/rootcheck'])
.then(function (data) {
$scope.events.length = 0;
$scope.events = data.data.items;
DataFactory.filters.register(objectsArray['/rootcheck'], 'search', 'string');
DataFactory.filters.register(objectsArray['/rootcheck'], 'filter-sort', 'string');
$scope._sort = '';
$scope.eventSearchFilter($scope._eventSearch);
}, printError);
}, printError);
2016-08-31 10:20:04 +00:00
});
};
2016-09-02 17:15:00 +00:00
2016-07-08 12:26:48 +00:00
var load = function () {
2016-09-20 08:55:43 +00:00
DataFactory.initialize('get', '/rootcheck/' + $scope.$parent._agent.id, {}, 200, 0)
.then(function (data) {
objectsArray['/rootcheck'] = data;
DataFactory.get(objectsArray['/rootcheck'])
.then(function (data) {
$scope.events = data.data.items;
$scope.totalEvents = data.data.totalItems;
DataFactory.filters.register(objectsArray['/rootcheck'], 'search', 'string');
DataFactory.filters.register(objectsArray['/rootcheck'], 'filter-sort', 'string');
createWatch();
$scope.load = false;
}, printError);
}, printError);
2016-07-08 12:26:48 +00:00
};
//Load
2016-09-16 12:32:22 +00:00
try {
load();
2016-09-22 15:24:30 +00:00
$scope.setTimer($scope.$parent.timeFilter);
2016-09-16 12:32:22 +00:00
} catch (e) {
$mdToast.show({
template: '<md-toast> Unexpected exception loading controller </md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
2016-09-16 12:32:22 +00:00
errlog.log('Unexpected exception loading controller', e);
}
2016-07-08 12:26:48 +00:00
2016-09-22 15:24:30 +00:00
// Timer filter watch
var loadWatch2 = $scope.$watch(function () {
return $scope.$parent.timeFilter;
}, function () {
$scope.setTimer($scope.$parent.timeFilter);
});
2016-07-08 12:26:48 +00:00
//Destroy
$scope.$on("$destroy", function () {
angular.forEach(objectsArray, function (value) {
DataFactory.clean(value)
});
$scope.events.length = 0;
2016-08-31 10:20:04 +00:00
loadWatch();
2016-09-22 15:24:30 +00:00
loadWatch2();
2016-07-08 12:26:48 +00:00
});
})