2018-04-22 20:16:38 +00:00
|
|
|
/*
|
|
|
|
* Wazuh app - Manager logs controller
|
|
|
|
* Copyright (C) 2018 Wazuh, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Find more information about this on the LICENSE file.
|
|
|
|
*/
|
2018-04-21 11:31:47 +00:00
|
|
|
import * as modules from 'ui/modules'
|
2018-04-26 12:47:56 +00:00
|
|
|
import CsvGenerator from './csv-generator'
|
2018-04-21 11:31:47 +00:00
|
|
|
|
|
|
|
const app = modules.get('app/wazuh', []);
|
2017-10-20 19:04:22 +00:00
|
|
|
|
|
|
|
// Logs controller
|
2018-04-26 12:47:56 +00:00
|
|
|
app.controller('managerLogController', function ($scope, $rootScope, Logs, apiReq, errorHandler, csvReq, appState) {
|
2017-10-30 09:08:42 +00:00
|
|
|
$scope.searchTerm = '';
|
|
|
|
$scope.loading = true;
|
|
|
|
$scope.logs = Logs;
|
2018-01-23 12:10:43 +00:00
|
|
|
$scope.realtime = false;
|
2018-02-14 15:43:07 +00:00
|
|
|
$scope.realLogs = [];
|
2018-03-08 11:59:39 +00:00
|
|
|
$scope.type_log = 'all';
|
|
|
|
$scope.category = 'all';
|
2018-01-23 12:10:43 +00:00
|
|
|
let intervalId = null;
|
2017-10-20 19:04:22 +00:00
|
|
|
|
2018-01-23 12:10:43 +00:00
|
|
|
const getRealLogs = async () => {
|
|
|
|
try{
|
|
|
|
const data = await apiReq.request('GET', '/manager/logs', {limit:20});
|
|
|
|
$scope.realLogs = data.data.data.items;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle(error,'Logs');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2018-01-23 12:10:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.playRealtime = async () => {
|
|
|
|
$scope.realtime = true;
|
|
|
|
await getRealLogs();
|
|
|
|
intervalId = setInterval(getRealLogs,2500);
|
2018-04-22 20:16:38 +00:00
|
|
|
};
|
2018-01-23 12:10:43 +00:00
|
|
|
|
|
|
|
$scope.stopRealtime = () => {
|
|
|
|
$scope.realtime = false;
|
|
|
|
clearInterval(intervalId);
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
}
|
|
|
|
|
2018-04-26 11:51:49 +00:00
|
|
|
$scope.downloadCsv = async () => {
|
2018-04-26 12:47:56 +00:00
|
|
|
try {
|
|
|
|
const currentApi = JSON.parse(appState.getCurrentAPI()).id;
|
2018-04-30 11:18:40 +00:00
|
|
|
const output = await csvReq.fetch('/manager/logs', currentApi, $scope.logs ? $scope.logs.filters : null);
|
2018-04-30 09:18:21 +00:00
|
|
|
const csvGenerator = new CsvGenerator(output.csv, 'logs.csv');
|
2018-04-26 12:47:56 +00:00
|
|
|
csvGenerator.download(true);
|
|
|
|
} catch (error) {
|
|
|
|
errorHandler.handle(error,'Download CSV');
|
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
|
|
|
}
|
2018-04-26 11:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 12:10:43 +00:00
|
|
|
const initialize = async () => {
|
2018-04-26 11:51:49 +00:00
|
|
|
try{
|
2018-01-23 12:10:43 +00:00
|
|
|
await $scope.logs.nextPage();
|
|
|
|
const data = await apiReq.request('GET', '/manager/logs/summary', {});
|
|
|
|
$scope.summary = data.data.data;
|
|
|
|
$scope.loading = false;
|
|
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
2018-01-29 14:39:21 +00:00
|
|
|
errorHandler.handle(error,'Logs');
|
2018-01-29 12:16:59 +00:00
|
|
|
if(!$rootScope.$$phase) $rootScope.$digest();
|
2018-01-23 12:10:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize();
|
2017-10-30 09:08:42 +00:00
|
|
|
|
|
|
|
// Resetting the factory configuration
|
2018-02-06 15:34:10 +00:00
|
|
|
$scope.$on("$destroy", () => {
|
|
|
|
if($scope.realtime) {
|
|
|
|
$scope.realtime = false;
|
|
|
|
clearInterval(intervalId);
|
|
|
|
}
|
|
|
|
$scope.logs.reset();
|
2018-02-12 15:15:16 +00:00
|
|
|
if($rootScope.ownHandlers){
|
|
|
|
for(let h of $rootScope.ownHandlers){
|
|
|
|
h._scope.$destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$rootScope.ownHandlers = [];
|
2018-02-06 15:34:10 +00:00
|
|
|
});
|
2018-04-22 20:16:38 +00:00
|
|
|
});
|