Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0 7.10 adapt reports new endpoints #2748

Merged
merged 3 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions public/controllers/management/components/files-group-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import {
} from '@elastic/eui';

import { ExportConfiguration } from '../../agent/components/export-configuration';
import { ReportingService } from '../../../react-services/reporting';

export class FilesInGroupTable extends Component {
constructor(props) {
super(props);
this.reportingService = new ReportingService();

this.state = {
groupName: this.props.group.name || 'Group',
Expand Down Expand Up @@ -152,11 +154,13 @@ export class FilesInGroupTable extends Component {
<EuiFlexItem grow={false}>
<ExportConfiguration
exportConfiguration={enabledComponents =>
this.props.exportConfigurationProps.exportConfiguration(
this.reportingService.startConfigReport(
this.props.state.itemDetail,
'groupConfig',
enabledComponents
)
}
type={this.props.exportConfigurationProps.type}
type='group'
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import WzBadge from './util-components/badge';
import WzClusterSelect from './util-components/configuration-cluster-selector';
import WzRefreshClusterInfoButton from './util-components/refresh-cluster-info-button';
import { ExportConfiguration } from '../../../../agent/components/export-configuration';
import { ReportingService } from '../../../../../react-services/reporting';

import configurationSettingsGroup from './configuration-settings';

Expand Down Expand Up @@ -64,6 +65,7 @@ const helpLinks = [
class WzConfigurationOverview extends Component {
constructor(props) {
super(props);
this.reportingService = new ReportingService();
}
updateConfigurationSection(section, title, description, path) {
this.props.updateConfigurationSection(section, title, description, path);
Expand Down Expand Up @@ -140,7 +142,11 @@ class WzConfigurationOverview extends Component {
agent={this.props.agent}
type="agent"
exportConfiguration={enabledComponents => {
this.props.exportConfiguration(enabledComponents);
this.reportingService.startConfigReport(
this.props.agent,
'agentConfig',
enabledComponents
);
}}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import exportCsv from '../../../../../react-services/wz-csv';
import GroupsHandler from './utils/groups-handler';
import { getToasts } from '../../../../../kibana-services';
import { ExportConfiguration } from '../../../../agent/components/export-configuration';
import { ReportingService } from '../../../../../react-services/reporting';

class WzGroupsActionButtonsAgents extends Component {
_isMounted = false;

constructor(props) {
super(props);
this.reportingService = new ReportingService();

this.state = {
generatingCsv: false,
Expand Down Expand Up @@ -210,12 +212,13 @@ class WzGroupsActionButtonsAgents extends Component {
const exportPDFButton = (
<ExportConfiguration
exportConfiguration={enabledComponents =>
this.props.groupsProps.exportConfigurationProps.exportConfiguration(
enabledComponents,
this.props.state.itemDetail
this.reportingService.startConfigReport(
this.props.state.itemDetail,
'groupConfig',
enabledComponents
)
}
type={this.props.groupsProps.exportConfigurationProps.type}
type='group'
/>
);
// Export button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import GroupsHandler from './utils/groups-handler';
import { getToasts } from '../../../../../kibana-services';
import { ExportConfiguration } from '../../../../agent/components/export-configuration';
import { WzButtonPermissions } from '../../../../../components/common/permissions/button';
import { ReportingService } from '../../../../../react-services/reporting';

class WzGroupsActionButtonsFiles extends Component {
_isMounted = false;

constructor(props) {
super(props);
this.reportingService = new ReportingService();

this.state = {
generatingCsv: false,
Expand Down Expand Up @@ -281,12 +283,13 @@ class WzGroupsActionButtonsFiles extends Component {
const exportPDFButton = (
<ExportConfiguration
exportConfiguration={enabledComponents =>
this.props.groupsProps.exportConfigurationProps.exportConfiguration(
enabledComponents,
this.props.state.itemDetail
this.reportingService.startConfigReport(
this.props.state.itemDetail,
'groupConfig',
enabledComponents
)
}
type={this.props.groupsProps.exportConfigurationProps.type}
type='group'
/>
);
// Export button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class WzReportingTable extends Component {
async getItems() {
try {
const rawItems = await this.reportingHandler.listReports();
const items = ((rawItems || {}).data || {}).list || [];
const items = ((rawItems || {}).data || {}).reports || [];
this.setState({
items,
isProcessing: false
Expand Down
5 changes: 3 additions & 2 deletions public/controllers/management/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import { WzRequest } from '../../react-services/wz-request';
import { ShareAgent } from '../../factories/share-agent';
import { GroupHandler } from '../../react-services/group-handler';
import { ErrorHandler } from '../../react-services/error-handler';
import { ReportingService } from '../../react-services/reporting';

export class GroupsController {
constructor($scope, $location, errorHandler, reportingService) {
constructor($scope, $location, errorHandler) {
this.scope = $scope;
this.location = $location;
this.errorHandler = errorHandler;
this.shareAgent = new ShareAgent();
this.groupHandler = GroupHandler;
this.wazuhConfig = new WazuhConfig();
this.reportingService = reportingService;
this.reportingService = new ReportingService();
}

async $onInit() {
Expand Down
22 changes: 9 additions & 13 deletions public/react-services/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class ReportingService {
this.vis2png = new Vis2PNG();
this.rawVisualizations = new RawVisualizations();
this.visHandlers = new VisHandlers();
this.genericReq = GenericRequest;
this.wazuhConfig = new WazuhConfig();
}

Expand Down Expand Up @@ -58,7 +57,7 @@ export class ReportingService {
return idArray;
}

async startVis2Png(tab, isAgents = false, syscollectorFilters = null) {
async startVis2Png(tab, agents = false, syscollectorFilters = null) {
try {
if (this.vis2png.isWorking()) {
this.showToast('danger', 'Error', 'Report in progress', 4000);
Expand Down Expand Up @@ -94,26 +93,27 @@ export class ReportingService {

const array = await this.vis2png.checkArray(idArray);
const name = `wazuh-${
isAgents ? 'agents' : 'overview'
agents ? 'agents' : 'overview'
}-${tab}-${(Date.now() / 1000) | 0}.pdf`;

const browserTimezone = moment.tz.guess(true);

const data = {
array,
name,
title: isAgents ? `Agents ${tab}` : `Overview ${tab}`,
title: agents ? `Agents ${tab}` : `Overview ${tab}`,
filters: appliedFilters.filters,
time: appliedFilters.time,
searchBar: appliedFilters.searchBar,
tables: appliedFilters.tables,
tab,
section: isAgents ? 'agents' : 'overview',
isAgents,
section: agents ? 'agents' : 'overview',
agents,
browserTimezone
};

await this.genericReq.request('POST', '/reports', data);
const apiEndpoint = tab === 'syscollector' ? `/reports/agents/${agents}/inventory` : `/reports/modules/${tab}`
await GenericRequest.request('POST', apiEndpoint, data);

this.$rootScope.reportBusy = false;
this.$rootScope.reportStatus = false;
Expand Down Expand Up @@ -147,20 +147,16 @@ export class ReportingService {
const browserTimezone = moment.tz.guess(true);

const data = {
array: [],
name,
filters: [
type === 'agentConfig' ? { agent: obj.id } : { group: obj.name }
],
time: '',
searchBar: '',
tables: [],
tab: type,
browserTimezone,
components
};

await this.genericReq.request('POST', '/reports', data);
const apiEndpoint = type === 'agentConfig' ? `/reports/agents/${obj.id}` : `/reports/groups/${obj.name}`;
await GenericRequest.request('POST', apiEndpoint, data);

this.$rootScope.reportBusy = false;
this.$rootScope.reportStatus = false;
Expand Down
Loading