Skip to content

Commit

Permalink
Timeout change in the restart manager in the configuration (#4264)
Browse files Browse the repository at this point in the history
* fix: timeout change

* add changelog

* parmeters refractor and format

* changelog: replaced PR entry

Co-authored-by: Antonio David Gutiérrez <[email protected]>
Co-authored-by: Álex <[email protected]>
(cherry picked from commit 2f83a43)
  • Loading branch information
yenienserrano authored and github-actions[bot] committed Jun 17, 2022
1 parent 176d68e commit de7dd34
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion public/components/security/policies/create-policy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export const CreatePolicyFlyout = ({ closeFlyout }) => {
const result = await WzRequest.apiReq(
'POST',
'/security/policies',

{
name: policyName,
policy: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,8 +34,7 @@ export default class ReportingHandler {
try {
const result = await WzRequest.genericReq(
'DELETE',
`/reports/${name}`,
{}
`/reports/${name}`
);
return result;
} catch (error) {
Expand Down
45 changes: 28 additions & 17 deletions public/react-services/wz-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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 =
Expand All @@ -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))
Expand All @@ -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<IApiResponse<any>> {
static async apiReq(
method,
path,
body,
options: { checkCurrentApiIsUp?: boolean } = { checkCurrentApiIsUp: true }
): Promise<IApiResponse<any>> {
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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de7dd34

Please sign in to comment.