Skip to content

Commit

Permalink
[BUG][Reports] Generate reports not manage the Wazuh API token expira…
Browse files Browse the repository at this point in the history
…tion (#3881)

* fix: Fixed the generating PDF reports doesn't manage the refreshing of token when it expires
  - Replaced the method to do the request from `GenericRequest.request` to `WzRequest.genericReq` that handles the refreshing of token
  - Adapted request payload and endpoint expected parameters for ApiID and the index pattern title
  - Removed not used params of some reports endpoints
  - Remove message of generating pdf report when the process fails

* changelog: Add PR to changelog

* changelog: Moved entry
  • Loading branch information
Desvelao authored Apr 6, 2022
1 parent 08a1111 commit 1d03c23
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed agents details card style [#3845](https://github.com/wazuh/wazuh-kibana-app/pull/3845) [#3860](https://github.com/wazuh/wazuh-kibana-app/pull/3860)
- Fixed routing redirection in events documents discover links [#3866](https://github.com/wazuh/wazuh-kibana-app/pull/3866)
- Fixed health-check [#3868](https://github.com/wazuh/wazuh-kibana-app/pull/3868)
- Fixed an error when generating PDF reports due to Wazuh API token expiration [#3881](https://github.com/wazuh/wazuh-kibana-app/pull/3881)
- Fixed the table of Vulnerabilities/Inventory doesn't reload when changing the selected agent [#3901](https://github.com/wazuh/wazuh-kibana-app/pull/3901)
- Fixed backslash breaking exported JSON result [#3909](https://github.com/wazuh/wazuh-kibana-app/pull/3909)
- Fixed the Events view multiple "The index pattern was refreshed successfully" toast [#3937](https://github.com/wazuh/wazuh-kibana-app/pull/3937)
Expand Down
15 changes: 10 additions & 5 deletions public/react-services/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import $ from 'jquery';
import moment from 'moment';
import { WazuhConfig } from '../react-services/wazuh-config';
import { GenericRequest } from '../react-services/generic-request';
import { AppState } from './app-state';
import { WzRequest } from './wz-request';
import { Vis2PNG } from '../factories/vis2png';
import { RawVisualizations } from '../factories/raw-visualizations';
import { VisHandlers } from '../factories/vis-handlers';
import { getToasts } from '../kibana-services';
import { getAngularModule } from '../kibana-services';
import { getAngularModule, getDataPlugin, getToasts } from '../kibana-services';
import { UI_LOGGER_LEVELS } from '../../common/constants';
import { UI_ERROR_SEVERITIES } from './error-orchestrator/types';
import { getErrorOrchestrator } from './common-services';
Expand Down Expand Up @@ -109,11 +109,13 @@ export class ReportingService {
section: agents ? 'agents' : 'overview',
agents,
browserTimezone,
indexPatternTitle: (await getDataPlugin().indexPatterns.get(AppState.getCurrentPattern())).title,
apiId: JSON.parse(AppState.getCurrentAPI()).id
};

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

this.$rootScope.reportBusy = false;
this.$rootScope.reportStatus = false;
Expand All @@ -128,6 +130,7 @@ export class ReportingService {
} catch (error) {
this.$rootScope.reportBusy = false;
this.$rootScope.reportStatus = false;
this.$rootScope.$applyAsync();
const options = {
context: `${ReportingService.name}.startVis2Png`,
level: UI_LOGGER_LEVELS.ERROR,
Expand Down Expand Up @@ -160,10 +163,11 @@ export class ReportingService {
tab: type,
browserTimezone,
components,
apiId: JSON.parse(AppState.getCurrentAPI()).id
};
const apiEndpoint =
type === 'agentConfig' ? `/reports/agents/${obj.id}` : `/reports/groups/${obj.name}`;
await GenericRequest.request('POST', apiEndpoint, data);
await WzRequest.genericReq('POST', apiEndpoint, data);

this.$rootScope.reportBusy = false;
this.$rootScope.reportStatus = false;
Expand All @@ -178,6 +182,7 @@ export class ReportingService {
} catch (error) {
this.$rootScope.reportBusy = false;
this.$rootScope.reportStatus = false;
this.$rootScope.$applyAsync();
const options = {
context: `${ReportingService.name}.startConfigReport`,
level: UI_LOGGER_LEVELS.ERROR,
Expand Down
18 changes: 7 additions & 11 deletions server/controllers/wazuh-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,10 @@ export class WazuhReportingCtrl {
tables,
name,
section,
indexPatternTitle,
apiId
} = request.body;
const { moduleID } = request.params;
const { id: apiId, pattern: indexPattern } = request.headers;
const { from, to } = time || {};
// Init
const printer = new ReportPrinter();
Expand Down Expand Up @@ -1176,7 +1177,7 @@ export class WazuhReportingCtrl {
new Date(from).getTime(),
new Date(to).getTime(),
sanitizedFilters,
indexPattern,
indexPatternTitle,
agents
);
}
Expand Down Expand Up @@ -1219,10 +1220,8 @@ export class WazuhReportingCtrl {
) {
try {
log('reporting:createReportsGroups', `Report started`, 'info');
const { browserTimezone, searchBar, filters, time, name, components } = request.body;
const { name, components, apiId } = request.body;
const { groupID } = request.params;
const { id: apiId, pattern: indexPattern } = request.headers;
const { from, to } = time || {};
// Init
const printer = new ReportPrinter();

Expand Down Expand Up @@ -1493,10 +1492,8 @@ export class WazuhReportingCtrl {
) {
try {
log('reporting:createReportsAgents', `Report started`, 'info');
const { browserTimezone, searchBar, filters, time, name, components } = request.body;
const { name, components, apiId } = request.body;
const { agentID } = request.params;
const { id: apiId } = request.headers;
const { from, to } = time || {};

const printer = new ReportPrinter();

Expand Down Expand Up @@ -1744,9 +1741,8 @@ export class WazuhReportingCtrl {
) {
try {
log('reporting:createReportsAgentsInventory', `Report started`, 'info');
const { browserTimezone, searchBar, filters, time, name } = request.body;
const { searchBar, filters, time, name, indexPatternTitle, apiId } = request.body;
const { agentID } = request.params;
const { id: apiId, pattern: indexPattern } = request.headers;
const { from, to } = time || {};
// Init
const printer = new ReportPrinter();
Expand Down Expand Up @@ -1940,7 +1936,7 @@ export class WazuhReportingCtrl {
from,
to,
sanitizedFilters + ' AND rule.groups: "vulnerability-detector"',
indexPattern,
indexPatternTitle,
agentID
);
}
Expand Down
10 changes: 8 additions & 2 deletions server/routes/wazuh-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export function WazuhReportingRoutes(router: IRouter) {
from: schema.string(),
to: schema.string()
}), schema.string()]),
title: schema.maybe(schema.string())
title: schema.maybe(schema.string()),
indexPatternTitle: schema.string(),
apiId: schema.string()
}),
params: schema.object({
moduleID: schema.string()
Expand All @@ -54,6 +56,7 @@ export function WazuhReportingRoutes(router: IRouter) {
name: schema.string(),
section: schema.maybe(schema.string()),
tab: schema.string(),
apiId: schema.string()
}),
params: schema.object({
groupID: schema.string()
Expand All @@ -73,6 +76,7 @@ export function WazuhReportingRoutes(router: IRouter) {
name: schema.string(),
section: schema.maybe(schema.string()),
tab: schema.string(),
apiId: schema.string()
}),
params: schema.object({
agentID: schema.string()
Expand Down Expand Up @@ -100,7 +104,9 @@ export function WazuhReportingRoutes(router: IRouter) {
from: schema.string(),
to: schema.string()
}), schema.string()]),
title: schema.maybe(schema.string())
title: schema.maybe(schema.string()),
indexPatternTitle: schema.string(),
apiId: schema.string()
}),
params: schema.object({
agentID: schema.string()
Expand Down

0 comments on commit 1d03c23

Please sign in to comment.