From 53fffcb382aba17e320b6995b5a57c665c9259f2 Mon Sep 17 00:00:00 2001 From: yenienserrano Date: Fri, 10 Jun 2022 17:01:41 +0200 Subject: [PATCH 1/5] 2 proposals --- .../wz-logtest/components/logtest.tsx | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/public/directives/wz-logtest/components/logtest.tsx b/public/directives/wz-logtest/components/logtest.tsx index 6e20a31f11..48ae7e9a07 100644 --- a/public/directives/wz-logtest/components/logtest.tsx +++ b/public/directives/wz-logtest/components/logtest.tsx @@ -47,6 +47,7 @@ import { UI_LOGGER_LEVELS } from '../../../../common/constants'; import { getErrorOrchestrator } from '../../../react-services/common-services'; import { WzFlyout } from '../../../components/common/flyouts'; import _ from 'lodash'; +import { getToasts } from '../../../kibana-services'; type LogstestProps = { openCloseFlyout: () => {}; @@ -71,7 +72,7 @@ export const Logtest = compose( }; // Format the result of the Wazuh API response to an output similar one to the `wazuh-logtest` utility - const formatResult = (result, alert) => { + const formatResult = (result, alert, messages) => { // How to the `wazuh-logtest` utility logs the output: // https://github.com/wazuh/wazuh/blob/master/framework/scripts/wazuh-logtest.py#L359-L397 @@ -100,6 +101,20 @@ export const Logtest = compose( }); } + // Output messages + if(messages){ + logging.push('**Messages:') + + let message = '' + + messages.map((msg) => { + message += '\t' + msg + '\n' + return message + }) + + logging.push(message) + } + // Pre-decoding phase logging.push('**Phase 1: Completed pre-decoding.'); // Check in case rule has no_full_log attribute @@ -148,12 +163,22 @@ export const Logtest = compose( return logging.join('\n'); }; + // const showToast = (color, title, text, time = 5000) => { + // getToasts().add({ + // color: color, + // title: title, + // text: text, + // toastLifeTimeMs: time + // }); + // } + const runAllTests = async () => { setTestResult(''); setTesting(true); let token = sessionToken; const responses = []; let gotToken = Boolean(token); + // let messages = [] try { for (let event of events) { @@ -165,13 +190,33 @@ export const Logtest = compose( }); token = response.data.data.token; + // messages.push(response.data.data.messages) !sessionToken && !gotToken && token && dispatch(updateLogtestToken(token)); token && (gotToken = true); responses.push(response); + + + // messages && showToast( + // 'primary', + // 'Messages', + // + //
{response.data.data.output.full_log}
+ // + //
+ // ); } const testResults = responses.map((response) => { return response.data.data.output || '' - ? formatResult(response.data.data.output, response.data.data.alert) + ? formatResult(response.data.data.output, response.data.data.alert, response.data.data.messages) : `No result found for: ${response.data.data.output.full_log}`; }).join('\n\n'); setTestResult(testResults); From 54f4431c9596ff06ba9cbfb8b40cfb3f1034a7cc Mon Sep 17 00:00:00 2001 From: yenienserrano Date: Mon, 13 Jun 2022 10:58:53 +0200 Subject: [PATCH 2/5] cleaning --- .../wz-logtest/components/logtest.tsx | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/public/directives/wz-logtest/components/logtest.tsx b/public/directives/wz-logtest/components/logtest.tsx index 48ae7e9a07..6765fe0641 100644 --- a/public/directives/wz-logtest/components/logtest.tsx +++ b/public/directives/wz-logtest/components/logtest.tsx @@ -107,9 +107,8 @@ export const Logtest = compose( let message = '' - messages.map((msg) => { + messages.forEach((msg) => { message += '\t' + msg + '\n' - return message }) logging.push(message) @@ -163,22 +162,12 @@ export const Logtest = compose( return logging.join('\n'); }; - // const showToast = (color, title, text, time = 5000) => { - // getToasts().add({ - // color: color, - // title: title, - // text: text, - // toastLifeTimeMs: time - // }); - // } - const runAllTests = async () => { setTestResult(''); setTesting(true); let token = sessionToken; const responses = []; let gotToken = Boolean(token); - // let messages = [] try { for (let event of events) { @@ -190,29 +179,9 @@ export const Logtest = compose( }); token = response.data.data.token; - // messages.push(response.data.data.messages) !sessionToken && !gotToken && token && dispatch(updateLogtestToken(token)); token && (gotToken = true); responses.push(response); - - - // messages && showToast( - // 'primary', - // 'Messages', - // - //
{response.data.data.output.full_log}
- //
    - // {messages.map((message) => ( - //
  • - // {message} - //
  • - // ))} - //
- //
- // ); } const testResults = responses.map((response) => { return response.data.data.output || '' From e3a57e198eb24cb9e10792f8f0a7d32933790a22 Mon Sep 17 00:00:00 2001 From: yenienserrano Date: Mon, 13 Jun 2022 11:37:00 +0200 Subject: [PATCH 3/5] add changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fc71d4d94..cb06e50b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the Wazuh app project will be documented in this file. +## Wazuh v4.3.5 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4306 + +### Added + +- Added to the interface API messages in the Ruleset test module [#4244](https://github.com/wazuh/wazuh-kibana-app/pull/4244) + ## Wazuh v4.3.4 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4305 ### Added From c7bffa57922c2eb3b5ae57b84dc908c82d9e94d1 Mon Sep 17 00:00:00 2001 From: yenienserrano Date: Mon, 13 Jun 2022 12:45:03 +0200 Subject: [PATCH 4/5] suggested changes --- .../wz-logtest/components/logtest.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/public/directives/wz-logtest/components/logtest.tsx b/public/directives/wz-logtest/components/logtest.tsx index 6765fe0641..417a00d91c 100644 --- a/public/directives/wz-logtest/components/logtest.tsx +++ b/public/directives/wz-logtest/components/logtest.tsx @@ -47,7 +47,6 @@ import { UI_LOGGER_LEVELS } from '../../../../common/constants'; import { getErrorOrchestrator } from '../../../react-services/common-services'; import { WzFlyout } from '../../../components/common/flyouts'; import _ from 'lodash'; -import { getToasts } from '../../../kibana-services'; type LogstestProps = { openCloseFlyout: () => {}; @@ -102,16 +101,16 @@ export const Logtest = compose( } // Output messages - if(messages){ - logging.push('**Messages:') + if (messages) { + logging.push('**Messages:'); - let message = '' + const initialValue = "" + const message = messages.reduce( + (previousValue, currentValue) => previousValue + '\t' + currentValue + '\n', + initialValue + ); - messages.forEach((msg) => { - message += '\t' + msg + '\n' - }) - - logging.push(message) + logging.push(message); } // Pre-decoding phase From 1bce8dddbeff9d5f384a634ca004c1254b45e41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20David=20Guti=C3=A9rrez?= Date: Tue, 14 Jun 2022 09:10:31 +0200 Subject: [PATCH 5/5] fix(logtest): changed Array.prototype.reduce by Array.prototype.forEach to display the messages --- public/directives/wz-logtest/components/logtest.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/public/directives/wz-logtest/components/logtest.tsx b/public/directives/wz-logtest/components/logtest.tsx index 417a00d91c..eb376f1bbb 100644 --- a/public/directives/wz-logtest/components/logtest.tsx +++ b/public/directives/wz-logtest/components/logtest.tsx @@ -103,14 +103,8 @@ export const Logtest = compose( // Output messages if (messages) { logging.push('**Messages:'); - - const initialValue = "" - const message = messages.reduce( - (previousValue, currentValue) => previousValue + '\t' + currentValue + '\n', - initialValue - ); - - logging.push(message); + messages.forEach(message => logging.push(`\t${message}`)); + logging.push(''); } // Pre-decoding phase