mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-07 18:28:55 +00:00
102 lines
3.2 KiB
JavaScript
102 lines
3.2 KiB
JavaScript
/*
|
|
* 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.
|
|
*/
|
|
import * as modules from 'ui/modules'
|
|
import * as FileSaver from '../services/file-saver'
|
|
|
|
const app = modules.get('app/wazuh', []);
|
|
|
|
// Logs controller
|
|
app.controller('managerLogController', function ($scope, $rootScope, Logs, apiReq, errorHandler, csvReq, appState) {
|
|
$scope.searchTerm = '';
|
|
$scope.loading = true;
|
|
$scope.logs = Logs;
|
|
$scope.realtime = false;
|
|
$scope.realLogs = [];
|
|
$scope.type_log = 'all';
|
|
$scope.category = 'all';
|
|
let intervalId = null;
|
|
|
|
const getRealLogs = async params => {
|
|
try{
|
|
const data = await apiReq.request('GET', '/manager/logs', params);
|
|
$scope.realLogs = data.data.data.items;
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
return;
|
|
} catch (error) {
|
|
errorHandler.handle(error,'Logs');
|
|
}
|
|
return;
|
|
};
|
|
|
|
$scope.playRealtime = async () => {
|
|
const params = { limit: 20 };
|
|
if($scope.logs && $scope.logs.filters && Array.isArray($scope.logs.filters)){
|
|
for(const filter of $scope.logs.filters){
|
|
if(!filter.name || !filter.value) continue;
|
|
params[filter.name] = filter.value;
|
|
}
|
|
}
|
|
$scope.realtime = true;
|
|
await getRealLogs(params);
|
|
intervalId = setInterval(() => getRealLogs(params), 2500);
|
|
};
|
|
|
|
$scope.stopRealtime = () => {
|
|
$scope.realtime = false;
|
|
clearInterval(intervalId);
|
|
if(!$scope.$$phase) $scope.$digest();
|
|
}
|
|
|
|
$scope.downloadCsv = async () => {
|
|
try {
|
|
errorHandler.info('Your download should begin automatically...', 'CSV')
|
|
const currentApi = JSON.parse(appState.getCurrentAPI()).id;
|
|
const output = await csvReq.fetch('/manager/logs', currentApi, $scope.logs ? $scope.logs.filters : null);
|
|
const blob = new Blob([output], {type: 'text/csv'});
|
|
|
|
FileSaver.saveAs(blob, 'logs.csv');
|
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
errorHandler.handle(error,'Download CSV');
|
|
}
|
|
return;
|
|
}
|
|
|
|
const initialize = async () => {
|
|
try{
|
|
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) {
|
|
errorHandler.handle(error,'Logs');
|
|
}
|
|
return;
|
|
}
|
|
|
|
initialize();
|
|
|
|
// Resetting the factory configuration
|
|
$scope.$on("$destroy", () => {
|
|
if($scope.realtime) {
|
|
$scope.realtime = false;
|
|
clearInterval(intervalId);
|
|
}
|
|
$scope.logs.reset();
|
|
|
|
});
|
|
});
|