Skip to content

Commit

Permalink
Add error management to actions of the Rules/Decoders/CDB Lists' tabl…
Browse files Browse the repository at this point in the history
…es (#4307)

* fix: add error management to the actions buttons of tables in rules/decoders/cdb lists

* changelog: add PR entry

* fix: unified error management in the actions of buttons of Rules/Decoders/CDB Lists's table

Co-authored-by: Álex <[email protected]>
(cherry picked from commit 0a1a9d0)
  • Loading branch information
Desvelao authored and github-actions[bot] committed Jul 8, 2022
1 parent 772dec8 commit 17720f3
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ All notable changes to the Wazuh app project will be documented in this file.
## Wazuh v4.3.6 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4307

### Added

- Added a new documentation link to the Docker Listener module [#4301](https://github.com/wazuh/wazuh-kibana-app/pull/4301)

### Changed

- The links to the web documentation now points to the plugin short version instead of `current` [#4301](https://github.com/wazuh/wazuh-kibana-app/pull/4301)
Expand All @@ -15,6 +17,7 @@ All notable changes to the Wazuh app project will be documented in this file.
# Fixed

- Fixed some links to web documentation that didn't work [#4301](https://github.com/wazuh/wazuh-kibana-app/pull/4301)
- Display errors on the action buttons of `Rules/Decoders/CDB Lists`'s tables [#4307](https://github.com/wazuh/wazuh-kibana-app/pull/4307)

## Wazuh v4.3.5 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4306

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { EuiToolTip, EuiButtonIcon, EuiLink, EuiBadge } from '@elastic/eui';
import { resourceDictionary, RulesetHandler, RulesetResources } from './ruleset-handler';
import exportCsv from '../../../../../../react-services/wz-csv';
import { WzButtonPermissions } from '../../../../../../components/common/permissions/button';
import { getErrorOrchestrator } from '../../../../../../react-services/common-services';
import { UIErrorLog, UILogLevel, UIErrorSeverity, UI_ERROR_SEVERITIES } from '../../../../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../../../../common/constants';

export default class RulesetColumns {
constructor(tableProps) {
Expand Down Expand Up @@ -82,11 +85,19 @@ export default class RulesetColumns {
permissions={getReadButtonPermissions(item)}
tooltip={{position:'top', content: `Show ${value} content`}}
onClick={async (ev) => {
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(RulesetResources.RULES);
const result = await rulesetHandler.getFileContent(value);
const file = { name: value, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
try{
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(RulesetResources.RULES);
const result = await rulesetHandler.getFileContent(value);
const file = { name: value, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Rules.readFileContent'
);
getErrorOrchestrator().handleError(options);
}
}}>
{value}
</WzButtonPermissions>
Expand Down Expand Up @@ -132,11 +143,19 @@ export default class RulesetColumns {
permissions={getReadButtonPermissions(item)}
tooltip={{position:'top', content: `Show ${value} content`}}
onClick={async (ev) => {
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(RulesetResources.DECODERS);
const result = await rulesetHandler.getFileContent(value);
const file = { name: value, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
try{
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(RulesetResources.DECODERS);
const result = await rulesetHandler.getFileContent(value);
const file = { name: value, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Decoders.readFileContent'
);
getErrorOrchestrator().handleError(options);
}
}}>
{value}
</WzButtonPermissions>
Expand Down Expand Up @@ -172,8 +191,16 @@ export default class RulesetColumns {
aria-label="Export list"
iconType="exportAction"
onClick={async ev => {
ev.stopPropagation();
await exportCsv(`/lists?path=${item.relative_dirname}/${item.filename}`, [{_isCDBList: true, name: 'path', value: `${item.relative_dirname}/${item.filename}`}], item.filename)
try{
ev.stopPropagation();
await exportCsv(`/lists?path=${item.relative_dirname}/${item.filename}`, [{_isCDBList: true, name: 'path', value: `${item.relative_dirname}/${item.filename}`}], item.filename)
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Lists.exportFile'
);
getErrorOrchestrator().handleError(options);
}
}}
color="primary"
/>
Expand Down Expand Up @@ -201,11 +228,19 @@ export default class RulesetColumns {
iconType="eye"
tooltip={{position: 'top', content:`View the content of ${item.filename}`}}
onClick={async ev => {
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(this.tableProps.state.section);
const result = await rulesetHandler.getFileContent(item.filename);
const file = { name: item.filename, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
try{
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(this.tableProps.state.section);
const result = await rulesetHandler.getFileContent(item.filename);
const file = { name: item.filename, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Files.readFileContent'
);
getErrorOrchestrator().handleError(options);
}
}}
color="primary"
/>
Expand All @@ -220,11 +255,19 @@ export default class RulesetColumns {
iconType="pencil"
tooltip={{position: 'top', content:`Edit ${item.filename} content`}}
onClick={async ev => {
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(this.tableProps.state.section);
const result = await rulesetHandler.getFileContent(item.filename);
const file = { name: item.filename, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
try{
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(this.tableProps.state.section);
const result = await rulesetHandler.getFileContent(item.filename);
const file = { name: item.filename, content: result, path: item.relative_dirname };
this.tableProps.updateFileContent(file);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Files.editFileContent'
);
getErrorOrchestrator().handleError(options);
}
}}
color="primary"
/>
Expand All @@ -235,9 +278,17 @@ export default class RulesetColumns {
iconType="trash"
tooltip={{position: 'top', content:`Remove ${item.filename} file`}}
onClick={ev => {
ev.stopPropagation();
this.tableProps.updateListItemsForRemove([item]);
this.tableProps.updateShowModal(true);
try{
ev.stopPropagation();
this.tableProps.updateListItemsForRemove([item]);
this.tableProps.updateShowModal(true);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Files.deleteFile'
);
getErrorOrchestrator().handleError(options);
}
}}
color="danger"
/>
Expand Down Expand Up @@ -298,11 +349,19 @@ export default class RulesetColumns {
iconType="pencil"
tooltip={{position: 'top', content: `Edit ${item.filename} content`}}
onClick={async (ev) => {
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(this.tableProps.state.section);
const result = await rulesetHandler.getFileContent(item.filename);
const file = { name: item.filename, content: result, path: item.relative_dirname };
this.tableProps.updateListContent(file);
try{
ev.stopPropagation();
const rulesetHandler = new RulesetHandler(this.tableProps.state.section);
const result = await rulesetHandler.getFileContent(item.filename);
const file = { name: item.filename, content: result, path: item.relative_dirname };
this.tableProps.updateListContent(file);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Lists.editFileContent'
);
getErrorOrchestrator().handleError(options);
}
}}
color="primary"
/>
Expand All @@ -313,9 +372,17 @@ export default class RulesetColumns {
iconType="trash"
tooltip={{position: 'top', content:(defaultItems.indexOf(`${item.relative_dirname}`) === -1) ? `Delete ${item.filename}` : `The ${item.filename} list cannot be deleted`}}
onClick={async (ev) => {
ev.stopPropagation();
this.tableProps.updateListItemsForRemove([item]);
this.tableProps.updateShowModal(true);
try{
ev.stopPropagation();
this.tableProps.updateListItemsForRemove([item]);
this.tableProps.updateShowModal(true);
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Lists.deleteFile'
);
getErrorOrchestrator().handleError(options);
}
}}
color="danger"
isDisabled={defaultItems.indexOf(`${item.relative_dirname}`) !== -1}
Expand All @@ -327,8 +394,16 @@ export default class RulesetColumns {
iconType="exportAction"
tooltip={{position: 'top', content: `Export ${item.filename} content`}}
onClick={async (ev) => {
ev.stopPropagation();
await exportCsv(`/lists`, [{_isCDBList: true, name: 'filename', value: `${item.filename}`}], item.filename)
try{
ev.stopPropagation();
await exportCsv(`/lists`, [{_isCDBList: true, name: 'filename', value: `${item.filename}`}], item.filename)
}catch(error){
const options: UIErrorLog = this.getErrorOptions(
error,
'Lists.exportFile'
);
getErrorOrchestrator().handleError(options);
}
}}
color="primary"
/>
Expand All @@ -342,6 +417,26 @@ export default class RulesetColumns {
this.buildColumns();
}

/**
* Build and return a new error options object, based on the actual error
* and the context
* @param error raised error
* @param context context of the error
* @returns a dictionary with the error details for the ErrorOrchestator
*/
private getErrorOptions(error: unknown, context: string): UIErrorLog {
return {
context: context,
level: UI_LOGGER_LEVELS.ERROR as UILogLevel,
severity: UI_ERROR_SEVERITIES.BUSINESS as UIErrorSeverity,
error: {
error: error,
message: error.message || error,
title: error.name,
},
};
}

buildComplianceBadges(item) {
const badgeList = [];
const fields = ['pci_dss', 'gpg13', 'hipaa', 'gdpr', 'nist_800_53', 'tsc', 'mitre'];
Expand Down

0 comments on commit 17720f3

Please sign in to comment.