diff --git a/CHANGELOG.md b/CHANGELOG.md index a617d8db67..19fe194d4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Removed a logged error that appeared when the `statistics` tasks tried to create an index with the same name, causing the second task to fail on the creation of the index because it already exists [#4235](https://github.com/wazuh/wazuh-kibana-app/pull/4235) - Fixed a UI crash due to a query with syntax errors in `Modules/Security events` [#4237](https://github.com/wazuh/wazuh-kibana-app/pull/4237) - Fixed an error when generating a module report after changing the selected agent [#4240](https://github.com/wazuh/wazuh-kibana-app/pull/4240) +- Fixed an error related to `API not available` when saving the manager configuration and restarting the manager from `Management/Configuration/Edit configuration` on manager mode [#4264](https://github.com/wazuh/wazuh-kibana-app/pull/4264) - Fixed a UI problem that required scrolling to see the logs in Management/Logs and Settings/Logs [#4253](https://github.com/wazuh/wazuh-kibana-app/pull/4253) ## Wazuh v4.3.4 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4305 diff --git a/public/components/security/policies/create-policy.tsx b/public/components/security/policies/create-policy.tsx index a6f4f3bfc6..9ffc15c692 100644 --- a/public/components/security/policies/create-policy.tsx +++ b/public/components/security/policies/create-policy.tsx @@ -165,7 +165,6 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => { const result = await WzRequest.apiReq( 'POST', '/security/policies', - { name: policyName, policy: { diff --git a/public/components/visualize/components/sample-data-warning.js b/public/components/visualize/components/sample-data-warning.js index 5fa23dfd4e..c125a2d229 100644 --- a/public/components/visualize/components/sample-data-warning.js +++ b/public/components/visualize/components/sample-data-warning.js @@ -22,7 +22,7 @@ export const SampleDataWarning = ({ ...props }) => { useEffect(() => { (async () => { try { - const result = (await WzRequest.genericReq('GET', '/elastic/samplealerts', {})).data + const result = (await WzRequest.genericReq('GET', '/elastic/samplealerts')).data .sampleAlertsInstalled; setIsSampleData(result); } catch (error) { diff --git a/public/controllers/management/components/management/configuration/edit-configuration/edit-configuration.js b/public/controllers/management/components/management/configuration/edit-configuration/edit-configuration.js index ca4d2dc39f..6bd807fe20 100644 --- a/public/controllers/management/components/management/configuration/edit-configuration/edit-configuration.js +++ b/public/controllers/management/components/management/configuration/edit-configuration/edit-configuration.js @@ -177,6 +177,12 @@ class WzEditConfiguration extends Component { color: 'success', }); } + if(!this.props.clusterNodeSelected){ + this.addToast({ + title: 'Manager was restarted', + color: 'success', + }); + } } catch (error) { this.props.updateWazuhNotReadyYet(''); this.setState({ restart: false, saving: false, restarting: false }); diff --git a/public/controllers/management/components/management/configuration/utils/wz-fetch.js b/public/controllers/management/components/management/configuration/utils/wz-fetch.js index f246ad8bb9..e13bd3d9f3 100644 --- a/public/controllers/management/components/management/configuration/utils/wz-fetch.js +++ b/public/controllers/management/components/management/configuration/utils/wz-fetch.js @@ -157,7 +157,7 @@ export const handleError = async (error, location, updateWazuhNotReadyYet, isClu */ export const checkDaemons = async (isCluster) => { try { - const response = await WzRequest.apiReq('GET', '/manager/status', {}); + const response = await WzRequest.apiReq('GET', '/manager/status', {}, { checkCurrentApiIsUp: false }); const daemons = ((((response || {}).data || {}).data || {}).affected_items || [])[0] || {}; const wazuhdbExists = typeof daemons['wazuh-db'] !== 'undefined'; @@ -267,18 +267,12 @@ export const fetchFile = async selectedNode => { * @param {} selectedNode Cluster Node * @param updateWazuhNotReadyYet */ -export const restartNodeSelected = async ( - selectedNode, - updateWazuhNotReadyYet -) => { +export const restartNodeSelected = async (selectedNode, updateWazuhNotReadyYet) => { try { const clusterStatus = (((await clusterReq()) || {}).data || {}).data || {}; - const isCluster = clusterStatus.enabled === 'yes' && clusterStatus.running === 'yes'; // Dispatch a Redux action - updateWazuhNotReadyYet( - `Restarting ${isCluster ? selectedNode : 'Manager'}, please wait.` - ); //FIXME: if it enables/disables cluster, this will show Manager instead node name + updateWazuhNotReadyYet(`Restarting ${isCluster ? selectedNode : 'Manager'}, please wait.`); //FIXME: if it enables/disables cluster, this will show Manager instead node name isCluster ? await restartNode(selectedNode) : await restartManager(); return await makePing(updateWazuhNotReadyYet, isCluster); } catch (error) { @@ -511,8 +505,7 @@ export const checkCurrentSecurityPlatform = async () => { try { const result = await WzRequest.genericReq( 'GET', - '/elastic/security/current-platform', - {} + '/elastic/security/current-platform' ); const platform = (result.data || {}).platform; @@ -526,24 +519,22 @@ export const checkCurrentSecurityPlatform = async () => { * Restart cluster or Manager */ export const restartClusterOrManager = async (updateWazuhNotReadyYet) => { - try{ + try { const clusterStatus = (((await clusterReq()) || {}).data || {}).data || {}; - const isCluster = - clusterStatus.enabled === 'yes' && clusterStatus.running === 'yes'; - getToasts().add({ - color:'success', - title:isCluster ?'Restarting cluster, it will take up to 30 seconds.': 'Manager was restarted', - toastLifeTimeMs: 3000 - }); + const isCluster = clusterStatus.enabled === 'yes' && clusterStatus.running === 'yes'; + getToasts().add({ + color: 'success', + title: isCluster + ? 'Restarting cluster, it will take up to 30 seconds.' + : 'The manager is being restarted', + toastLifeTimeMs: 3000, + }); isCluster ? await restartCluster() : await restartManager(); // Dispatch a Redux action - updateWazuhNotReadyYet( - `Restarting ${isCluster ? 'Cluster' : 'Manager'}, please wait.` - ); - await delayAsPromise(15000); + updateWazuhNotReadyYet(`Restarting ${isCluster ? 'Cluster' : 'Manager'}, please wait.`); await makePing(updateWazuhNotReadyYet, isCluster); - return { restarted: isCluster ? 'Cluster' : 'Manager'} - }catch (error){ + return { restarted: isCluster ? 'Cluster' : 'Manager' }; + } catch (error) { throw error; - }; + } }; diff --git a/public/controllers/management/components/management/reporting/utils/reporting-handler.js b/public/controllers/management/components/management/reporting/utils/reporting-handler.js index 9b0d274d16..e728fd9066 100644 --- a/public/controllers/management/components/management/reporting/utils/reporting-handler.js +++ b/public/controllers/management/components/management/reporting/utils/reporting-handler.js @@ -19,7 +19,7 @@ export default class ReportingHandler { */ static async listReports() { try { - const result = await WzRequest.genericReq('GET', '/reports', {}); + const result = await WzRequest.genericReq('GET', '/reports'); return result; } catch (error) { throw error; @@ -34,8 +34,7 @@ export default class ReportingHandler { try { const result = await WzRequest.genericReq( 'DELETE', - `/reports/${name}`, - {} + `/reports/${name}` ); return result; } catch (error) { diff --git a/public/react-services/wz-request.ts b/public/react-services/wz-request.ts index a435736180..39819ddd21 100644 --- a/public/react-services/wz-request.ts +++ b/public/react-services/wz-request.ts @@ -32,9 +32,13 @@ export class WzRequest { method, path, payload: any = null, - customTimeout = false, - shouldRetry = true + extraOptions: { shouldRetry?: boolean, checkCurrentApiIsUp?: boolean } = { + shouldRetry: true, + checkCurrentApiIsUp: true + } ) { + const shouldRetry = typeof extraOptions.shouldRetry === 'boolean' ? extraOptions.shouldRetry : true; + const checkCurrentApiIsUp = typeof extraOptions.checkCurrentApiIsUp === 'boolean' ? extraOptions.checkCurrentApiIsUp : true; try { if (!method || !path) { throw new Error('Missing parameters'); @@ -49,7 +53,7 @@ export class WzRequest { headers: { ...PLUGIN_PLATFORM_REQUEST_HEADERS, 'content-type': 'application/json' }, url: url, data: payload, - timeout: customTimeout || timeout, + timeout: timeout, }; const data = await axios(options); @@ -62,17 +66,19 @@ export class WzRequest { } catch (error) { OdfeUtils.checkOdfeSessionExpired(error); //if the requests fails, we need to check if the API is down - const currentApi = JSON.parse(AppState.getCurrentAPI() || '{}'); - if (currentApi && currentApi.id) { - try { - await ApiCheck.checkStored(currentApi.id); - } catch (error) { - const wzMisc = new WzMisc(); - wzMisc.setApiIsDown(true); - if (!window.location.hash.includes('#/settings')) { - window.location.href = getHttp().basePath.prepend('/app/wazuh#/health-check'); + if(checkCurrentApiIsUp){ + const currentApi = JSON.parse(AppState.getCurrentAPI() || '{}'); + if (currentApi && currentApi.id) { + try { + await ApiCheck.checkStored(currentApi.id); + } catch (error) { + const wzMisc = new WzMisc(); + wzMisc.setApiIsDown(true); + if (!window.location.hash.includes('#/settings')) { + window.location.href = getHttp().basePath.prepend('/app/wazuh#/health-check'); + } + throw new Error(error); } - throw new Error(error); } } const errorMessage = @@ -85,7 +91,7 @@ export class WzRequest { ) { try { await WzAuthentication.refresh(true); - return this.genericReq(method, path, payload, customTimeout, false); + return this.genericReq(method, path, payload, { shouldRetry: false }); } catch (error) { return ((error || {}).data || {}).message || false ? Promise.reject(this.returnErrorInstance(error, error.data.message)) @@ -104,14 +110,19 @@ export class WzRequest { * @param {String} path API route * @param {Object} body Request body */ - static async apiReq(method, path, body, shouldRetry = true): Promise> { + static async apiReq( + method, + path, + body, + options: { checkCurrentApiIsUp?: boolean } = { checkCurrentApiIsUp: true } + ): Promise> { try { if (!method || !path || !body) { throw new Error('Missing parameters'); } const id = JSON.parse(AppState.getCurrentAPI()).id; const requestData = { method, path, body, id }; - const response = await this.genericReq('POST', '/api/request', requestData); + const response = await this.genericReq('POST', '/api/request', requestData, options); const hasFailed = (((response || {}).data || {}).data || {}).total_failed_items || 0; @@ -144,7 +155,7 @@ export class WzRequest { } const id = JSON.parse(AppState.getCurrentAPI()).id; const requestData = { path, id, filters }; - const data = await this.genericReq('POST', '/api/csv', requestData, false); + const data = await this.genericReq('POST', '/api/csv', requestData); return Promise.resolve(data); } catch (error) { return ((error || {}).data || {}).message || false