2018-06-12 13:22:37 +00:00
|
|
|
/*
|
|
|
|
* Wazuh app - Reporting service
|
2019-01-14 16:36:47 +00:00
|
|
|
* Copyright (C) 2015-2019 Wazuh, Inc.
|
2018-06-12 13:22:37 +00:00
|
|
|
*
|
|
|
|
* 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-09-11 09:52:54 +00:00
|
|
|
import $ from 'jquery';
|
2019-03-13 17:06:07 +00:00
|
|
|
import moment from 'moment';
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-11 09:52:54 +00:00
|
|
|
export class ReportingService {
|
2018-09-10 08:32:49 +00:00
|
|
|
constructor(
|
|
|
|
$rootScope,
|
|
|
|
vis2png,
|
|
|
|
rawVisualizations,
|
|
|
|
visHandlers,
|
|
|
|
genericReq,
|
|
|
|
errorHandler
|
|
|
|
) {
|
|
|
|
this.$rootScope = $rootScope;
|
|
|
|
this.vis2png = vis2png;
|
|
|
|
this.rawVisualizations = rawVisualizations;
|
|
|
|
this.visHandlers = visHandlers;
|
|
|
|
this.genericReq = genericReq;
|
|
|
|
this.errorHandler = errorHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
async startVis2Png(tab, isAgents = false, syscollectorFilters = null) {
|
|
|
|
try {
|
|
|
|
if (this.vis2png.isWorking()) {
|
|
|
|
this.errorHandler.handle('Report in progress', 'Reporting', true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.$rootScope.reportBusy = true;
|
|
|
|
this.$rootScope.reportStatus = 'Generating report...0%';
|
|
|
|
if (!this.$rootScope.$$phase) this.$rootScope.$digest();
|
|
|
|
|
|
|
|
this.vis2png.clear();
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const idArray = this.rawVisualizations.getList().map(item => item.id);
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
for (const item of idArray) {
|
|
|
|
const tmpHTMLElement = $(`#${item}`);
|
|
|
|
this.vis2png.assignHTMLItem(item, tmpHTMLElement);
|
|
|
|
}
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const appliedFilters = this.visHandlers.getAppliedFilters(
|
|
|
|
syscollectorFilters
|
|
|
|
);
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const array = await this.vis2png.checkArray(idArray);
|
|
|
|
const name = `wazuh-${
|
|
|
|
isAgents ? 'agents' : 'overview'
|
2019-03-18 12:15:40 +00:00
|
|
|
}-${tab}-${(Date.now() / 1000) | 0}.pdf`;
|
2019-03-13 17:06:07 +00:00
|
|
|
|
|
|
|
const browserTimezone = moment.tz.guess(true);
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const data = {
|
|
|
|
array,
|
|
|
|
name,
|
|
|
|
title: isAgents ? `Agents ${tab}` : `Overview ${tab}`,
|
|
|
|
filters: appliedFilters.filters,
|
|
|
|
time: appliedFilters.time,
|
|
|
|
searchBar: appliedFilters.searchBar,
|
|
|
|
tables: appliedFilters.tables,
|
|
|
|
tab,
|
|
|
|
section: isAgents ? 'agents' : 'overview',
|
2019-03-13 17:06:07 +00:00
|
|
|
isAgents,
|
|
|
|
browserTimezone
|
2018-09-10 08:32:49 +00:00
|
|
|
};
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-11-02 17:23:00 +00:00
|
|
|
await this.genericReq.request('POST', '/reports', data);
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
this.$rootScope.reportBusy = false;
|
|
|
|
this.$rootScope.reportStatus = false;
|
|
|
|
if (!this.$rootScope.$$phase) this.$rootScope.$digest();
|
|
|
|
this.errorHandler.info(
|
2018-12-18 16:14:30 +00:00
|
|
|
'Success. Go to Wazuh > Management > Reporting',
|
2018-09-10 08:32:49 +00:00
|
|
|
'Reporting'
|
|
|
|
);
|
2018-06-12 13:22:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
return;
|
|
|
|
} catch (error) {
|
|
|
|
this.$rootScope.reportBusy = false;
|
|
|
|
this.$rootScope.reportStatus = false;
|
2019-03-26 20:37:23 +00:00
|
|
|
this.errorHandler.handle(error.message || error);
|
2018-08-20 07:00:50 +00:00
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
2018-08-20 07:00:50 +00:00
|
|
|
}
|