wazuh-kibana-app/public/controllers/overview.js

225 lines
7.0 KiB
JavaScript
Raw Normal View History

2016-09-16 12:35:56 +00:00
var app = require('ui/modules').get('app/wazuh', []);
2016-09-20 08:55:43 +00:00
app.controller('overviewGeneralController', function ($scope, DataFactory, genericReq, $mdToast, errlog) {
2016-09-16 12:35:56 +00:00
//Initialisation
$scope.load = true;
$scope.$parent.state.setOverviewState('general');
2016-09-20 08:55:43 +00:00
$scope.timeFilter = "24h";
$scope.stats = [];
//Print Error
var printError = function (error) {
$mdToast.show({
template: '<md-toast>' + error.html + '</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
};
2016-09-20 08:55:43 +00:00
//Functions
$scope.setTimer = function (time) {
2016-09-20 18:07:07 +00:00
$scope.timerFilterValue = time;
};
2016-09-20 08:55:43 +00:00
var load_tops = function () {
var daysAgo = 1;
2016-09-20 18:07:07 +00:00
if ($scope.timerFilterValue == "24h") {
daysAgo = 1;
} else if ($scope.timerFilterValue == "7d") {
daysAgo = 7;
} else if ($scope.timerFilterValue == "30d") {
daysAgo = 30;
2016-09-20 08:55:43 +00:00
} else {
2016-09-20 18:07:07 +00:00
daysAgo = 1;
2016-09-20 08:55:43 +00:00
}
2016-09-20 18:07:07 +00:00
2016-09-20 08:55:43 +00:00
var date = new Date();
date.setDate(date.getDate() - daysAgo);
var timeAgo = date.getTime();
genericReq.request('GET', '/api/wazuh-elastic/top/srcuser/' + timeAgo)
.then(function (data) {
$scope.topsrcuser = data.data;
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/top/srcip/' + timeAgo)
.then(function (data) {
$scope.topsrcip = data.data;
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/top/rule.groups/' + timeAgo)
.then(function (data) {
$scope.topgroup = data.data;
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/top/rule.PCI_DSS/' + timeAgo)
.then(function (data) {
$scope.toppci = data.data;
}, printError);
};
var load = function () {
2016-09-20 08:55:43 +00:00
DataFactory.getAndClean('get', '/agents/summary', {})
.then(function (data) {
$scope.agentsCountActive = data.data.active;
$scope.agentsCountDisconnected = data.data.disconnected;
$scope.agentsCountNeverConnected = data.data.neverConnected;
$scope.agentsCountTotal = data.data.total;
$scope.load = false;
}, printError);
};
//Load
2016-09-20 08:55:43 +00:00
try {
load();
load_tops();
} catch (e) {
$mdToast.show({
template: '<md-toast> Unexpected exception loading controller </md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
errlog.log('Unexpected exception loading controller', e);
}
2016-09-20 08:55:43 +00:00
// Timer filter watch
var loadWatch = $scope.$watch(function () {
return $scope.$parent.timeFilter;
}, function () {
$scope.setTimer($scope.$parent.timeFilter);
2016-09-20 08:55:43 +00:00
load_tops();
});
2016-09-20 08:55:43 +00:00
//Destroy
$scope.$on("$destroy", function () {
$scope.stats.length = 0;
2016-09-20 08:55:43 +00:00
loadWatch();
});
});
2016-09-20 08:55:43 +00:00
app.controller('overviewFimController', function ($scope, DataFactory, genericReq, $mdToast, errlog) {
//Initialisation
$scope.load = true;
$scope.$parent.state.setOverviewState('fim');
2016-09-20 08:55:43 +00:00
$scope.timeFilter = "24h";
2016-09-16 12:35:56 +00:00
2016-09-20 08:55:43 +00:00
$scope.stats = [];
2016-09-16 12:35:56 +00:00
//Print Error
var printError = function (error) {
$mdToast.show({
template: '<md-toast>' + error.html + '</md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
};
2016-09-20 08:55:43 +00:00
//Functions
$scope.setTimer = function (time) {
if (time == "24h") {
$scope.timerFilterValue = "24h";
} else if (time == "48h") {
$scope.timerFilterValue = "48h";
} else {
$scope.timerFilterValue = "7d";
}
2016-09-16 12:35:56 +00:00
};
2016-09-20 08:55:43 +00:00
var load_tops = function () {
2016-09-20 18:07:07 +00:00
2016-09-20 08:55:43 +00:00
var daysAgo = 1;
2016-09-20 18:07:07 +00:00
if ($scope.timerFilterValue == "24h") {
daysAgo = 1;
} else if ($scope.timerFilterValue == "7d") {
daysAgo = 7;
} else if ($scope.timerFilterValue == "30d") {
daysAgo = 30;
2016-09-20 08:55:43 +00:00
} else {
2016-09-20 18:07:07 +00:00
daysAgo = 1;
2016-09-20 08:55:43 +00:00
}
2016-09-20 18:07:07 +00:00
2016-09-20 08:55:43 +00:00
var date = new Date();
date.setDate(date.getDate() - daysAgo);
var timeAgo = date.getTime();
2016-09-20 14:16:44 +00:00
// Top fields
genericReq.request('GET', '/api/wazuh-elastic/top/AgentName/'+timeAgo)
2016-09-20 08:55:43 +00:00
.then(function (data) {
2016-09-20 14:16:44 +00:00
$scope.topagent = data.data;
2016-09-20 08:55:43 +00:00
}, printError);
2016-09-20 14:16:44 +00:00
genericReq.request('GET', '/api/wazuh-elastic/top/SyscheckFile.perm_before/'+timeAgo)
2016-09-20 08:55:43 +00:00
.then(function (data) {
2016-09-20 14:16:44 +00:00
$scope.toppermissions = data.data;
2016-09-20 08:55:43 +00:00
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/top/rule.PCI_DSS/' + timeAgo)
.then(function (data) {
$scope.toppci = data.data;
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/top/SyscheckFile.path/' + timeAgo + '/location/syscheck')
.then(function (data) {
$scope.topfile = data.data;
}, printError);
2016-09-20 14:16:44 +00:00
// Last fields
genericReq.request('GET', '/api/wazuh-elastic/last/SyscheckFile/SyscheckFile.event/modified')
.then(function (data) {
if(data.data != "")
$scope.last_file_changed = (data.data != "") ? data.data.path : "(no data)";
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/last/SyscheckFile/SyscheckFile.event/addded')
.then(function (data) {
$scope.last_file_added = (data.data != "") ? data.data.path : "(no data)";
}, printError);
genericReq.request('GET', '/api/wazuh-elastic/last/SyscheckFile/SyscheckFile.event/deleted')
.then(function (data) {
if(data.data != "")
$scope.last_file_deleted = (data.data != "") ? data.data.path : "(no data)";
}, printError);
2016-09-16 12:35:56 +00:00
};
var load = function () {
2016-09-20 08:55:43 +00:00
DataFactory.getAndClean('get', '/agents/summary', {})
.then(function (data) {
$scope.agentsCountActive = data.data.active;
$scope.agentsCountDisconnected = data.data.disconnected;
$scope.agentsCountNeverConnected = data.data.neverConnected;
$scope.agentsCountTotal = data.data.total;
$scope.load = false;
}, printError);
2016-09-16 12:35:56 +00:00
};
//Load
2016-09-20 08:55:43 +00:00
try {
load();
load_tops();
} catch (e) {
$mdToast.show({
template: '<md-toast> Unexpected exception loading controller </md-toast>',
position: 'bottom left',
hideDelay: 5000,
});
errlog.log('Unexpected exception loading controller', e);
}
2016-09-16 12:35:56 +00:00
2016-09-20 08:55:43 +00:00
// Timer filter watch
var loadWatch = $scope.$watch(function () {
2016-09-16 12:35:56 +00:00
return $scope.$parent.timeFilter;
}, function () {
$scope.setTimer($scope.$parent.timeFilter);
2016-09-20 08:55:43 +00:00
load_tops();
2016-09-16 12:35:56 +00:00
});
//Destroy
$scope.$on("$destroy", function () {
$scope.stats.length = 0;
2016-09-20 08:55:43 +00:00
loadWatch();
2016-09-16 12:35:56 +00:00
});
});