mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 09:55:18 +00:00
Fix all backend responses
This commit is contained in:
parent
43023224e8
commit
ae442d4f66
@ -66,7 +66,7 @@ export function ErrorResponse(
|
||||
}
|
||||
}
|
||||
|
||||
return reply({
|
||||
return {
|
||||
message: filteredMessage
|
||||
? `${code ? code : 1000} - ${filteredMessage}`
|
||||
: typeof message === 'string'
|
||||
@ -74,5 +74,5 @@ export function ErrorResponse(
|
||||
: `${code ? code : 1000} - Unexpected error`,
|
||||
code: code ? code : 1000,
|
||||
statusCode: statusCode ? statusCode : 500
|
||||
}).code(statusCode ? statusCode : 500);
|
||||
};
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ export class WazuhApiElasticCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
return reply(result);
|
||||
return (result);
|
||||
} catch (error) {
|
||||
log('GET /elastic/apis', error.message || error);
|
||||
return ErrorResponse(error.message || error, 2001, 500, reply);
|
||||
@ -69,7 +69,7 @@ export class WazuhApiElasticCtrl {
|
||||
try {
|
||||
const data = await this.wzWrapper.deleteWazuhAPIEntriesWithRequest(req);
|
||||
|
||||
return reply(data);
|
||||
return (data);
|
||||
} catch (error) {
|
||||
log('DELETE /elastic/apis/{id}', error.message || error);
|
||||
return ErrorResponse(error.message || error, 2002, 500, reply);
|
||||
@ -154,7 +154,7 @@ export class WazuhApiElasticCtrl {
|
||||
settings
|
||||
);
|
||||
|
||||
return reply({ statusCode: 200, message: 'ok', response });
|
||||
return ({ statusCode: 200, message: 'ok', response });
|
||||
} catch (error) {
|
||||
log('PUT /elastic/api', error.message || error);
|
||||
return ErrorResponse(
|
||||
@ -178,7 +178,7 @@ export class WazuhApiElasticCtrl {
|
||||
doc: { cluster_info: req.payload.cluster_info }
|
||||
});
|
||||
|
||||
return reply({ statusCode: 200, message: 'ok' });
|
||||
return ({ statusCode: 200, message: 'ok' });
|
||||
} catch (error) {
|
||||
log('PUT /elastic/api-hostname/{id}', error.message || error);
|
||||
return ErrorResponse(
|
||||
@ -216,7 +216,7 @@ export class WazuhApiElasticCtrl {
|
||||
doc: settings
|
||||
});
|
||||
|
||||
return reply({ statusCode: 200, message: 'ok' });
|
||||
return ({ statusCode: 200, message: 'ok' });
|
||||
} catch (error) {
|
||||
log('PUT /elastic/api-settings', error.message || error);
|
||||
return ErrorResponse(
|
||||
|
@ -111,7 +111,7 @@ export class WazuhApiCtrl {
|
||||
api.cluster_info.node = response.body.data.node;
|
||||
api.cluster_info.cluster = response.body.data.cluster;
|
||||
api.password = '****';
|
||||
return reply({
|
||||
return ({
|
||||
statusCode: 200,
|
||||
data: api,
|
||||
idChanged: req.idChanged || null
|
||||
@ -132,7 +132,7 @@ export class WazuhApiCtrl {
|
||||
api.cluster_info.manager = managerName;
|
||||
api.password = '****';
|
||||
|
||||
return reply({
|
||||
return ({
|
||||
statusCode: 200,
|
||||
data: api,
|
||||
idChanged: req.idChanged || null
|
||||
@ -155,7 +155,7 @@ export class WazuhApiCtrl {
|
||||
} catch (error) {
|
||||
if (error.code === 'ECONNREFUSED') {
|
||||
log('POST /api/check-stored-api', error.message || error);
|
||||
return reply({
|
||||
return ({
|
||||
statusCode: 200,
|
||||
data: { password: '****', apiIsDown: true }
|
||||
});
|
||||
@ -310,7 +310,7 @@ export class WazuhApiCtrl {
|
||||
);
|
||||
|
||||
if (!response.body.error) {
|
||||
return reply({
|
||||
return ({
|
||||
manager: managerName,
|
||||
node: response.body.data.node,
|
||||
cluster: response.body.data.cluster,
|
||||
@ -319,7 +319,7 @@ export class WazuhApiCtrl {
|
||||
}
|
||||
} else {
|
||||
// Cluster mode is not active
|
||||
return reply({
|
||||
return ({
|
||||
manager: managerName,
|
||||
cluster: 'Disabled',
|
||||
status: 'disabled'
|
||||
@ -352,7 +352,7 @@ export class WazuhApiCtrl {
|
||||
|
||||
if (req.params.requirement === 'all') {
|
||||
if (!req.headers.id) {
|
||||
return reply(pciRequirementsFile);
|
||||
return (pciRequirementsFile);
|
||||
}
|
||||
let api = await this.wzWrapper.getWazuhConfigurationById(
|
||||
req.headers.id
|
||||
@ -384,7 +384,7 @@ export class WazuhApiCtrl {
|
||||
if (typeof pciRequirementsFile[item] !== 'undefined')
|
||||
PCIobject[item] = pciRequirementsFile[item];
|
||||
}
|
||||
return reply(PCIobject);
|
||||
return (PCIobject);
|
||||
} else {
|
||||
return ErrorResponse(
|
||||
'An error occurred trying to parse PCI DSS requirements',
|
||||
@ -400,7 +400,7 @@ export class WazuhApiCtrl {
|
||||
pci_description = pciRequirementsFile[req.params.requirement];
|
||||
}
|
||||
|
||||
return reply({
|
||||
return ({
|
||||
pci: {
|
||||
requirement: req.params.requirement,
|
||||
description: pci_description
|
||||
@ -424,7 +424,7 @@ export class WazuhApiCtrl {
|
||||
|
||||
if (req.params.requirement === 'all') {
|
||||
if (!req.headers.id) {
|
||||
return reply(gdprRequirementsFile);
|
||||
return (gdprRequirementsFile);
|
||||
}
|
||||
const api = await this.wzWrapper.getWazuhConfigurationById(
|
||||
req.headers.id
|
||||
@ -454,7 +454,7 @@ export class WazuhApiCtrl {
|
||||
(major >= 3 && minor < 2) ||
|
||||
(major >= 3 && minor >= 2 && patch < 3)
|
||||
) {
|
||||
return reply({});
|
||||
return ({});
|
||||
}
|
||||
|
||||
if (api.error_code > 1) {
|
||||
@ -483,7 +483,7 @@ export class WazuhApiCtrl {
|
||||
if (typeof gdprRequirementsFile[item] !== 'undefined')
|
||||
GDPRobject[item] = gdprRequirementsFile[item];
|
||||
}
|
||||
return reply(GDPRobject);
|
||||
return (GDPRobject);
|
||||
} else {
|
||||
return ErrorResponse(
|
||||
'An error occurred trying to parse GDPR requirements',
|
||||
@ -499,7 +499,7 @@ export class WazuhApiCtrl {
|
||||
gdpr_description = gdprRequirementsFile[req.params.requirement];
|
||||
}
|
||||
|
||||
return reply({
|
||||
return ({
|
||||
gdpr: {
|
||||
requirement: req.params.requirement,
|
||||
description: gdpr_description
|
||||
@ -565,11 +565,11 @@ export class WazuhApiCtrl {
|
||||
((response || {}).body || {}).data
|
||||
) {
|
||||
cleanKeys(response);
|
||||
return reply(response.body);
|
||||
return (response.body);
|
||||
}
|
||||
|
||||
if (((response || {}).body || {}).error && devTools) {
|
||||
return reply(response.body);
|
||||
return (response.body);
|
||||
}
|
||||
|
||||
throw ((response || {}).body || {}).error &&
|
||||
@ -578,7 +578,7 @@ export class WazuhApiCtrl {
|
||||
: new Error('Unexpected error fetching data from the Wazuh API');
|
||||
} catch (error) {
|
||||
if (devTools) {
|
||||
return reply({ error: '3013', message: error.message || error });
|
||||
return ({ error: '3013', message: error.message || error });
|
||||
} else {
|
||||
if ((error || {}).code && ApiErrorEquivalence[error.code]) {
|
||||
error.message = ApiErrorEquivalence[error.code];
|
||||
@ -704,7 +704,7 @@ export class WazuhApiCtrl {
|
||||
async fetchAgents(req, reply) {
|
||||
try {
|
||||
const output = await this.monitoringInstance.fetchAgentsExternal();
|
||||
return reply({
|
||||
return ({
|
||||
statusCode: 200,
|
||||
error: '0',
|
||||
data: '',
|
||||
@ -804,7 +804,7 @@ export class WazuhApiCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
return reply(csv).type('text/csv');
|
||||
return (csv).type('text/csv');
|
||||
} else if (
|
||||
output &&
|
||||
output.body &&
|
||||
@ -953,7 +953,7 @@ export class WazuhApiCtrl {
|
||||
Object.assign(result.lastAgent, lastAgent.items[0]);
|
||||
}
|
||||
|
||||
return reply({ error: 0, result });
|
||||
return ({ error: 0, result });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 3035, 500, reply);
|
||||
}
|
||||
@ -962,6 +962,6 @@ export class WazuhApiCtrl {
|
||||
// Get de list of available requests in the API
|
||||
getRequestList(req, reply) {
|
||||
//Read a static JSON until the api call has implemented
|
||||
return reply(apiRequestList);
|
||||
return (apiRequestList);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ export class WazuhElasticCtrl {
|
||||
((((data || {}).hits || {}).hits || [])[0] || {})._source || {};
|
||||
|
||||
if (source.installationDate && source.lastRestart) {
|
||||
return reply({
|
||||
return ({
|
||||
installationDate: data.hits.hits[0]._source.installationDate,
|
||||
lastRestart: data.hits.hits[0]._source.lastRestart
|
||||
});
|
||||
@ -115,12 +115,12 @@ export class WazuhElasticCtrl {
|
||||
});
|
||||
|
||||
return isIncluded && Array.isArray(isIncluded) && isIncluded.length
|
||||
? reply({
|
||||
? ({
|
||||
statusCode: 200,
|
||||
status: true,
|
||||
data: `Template found for ${req.params.pattern}`
|
||||
})
|
||||
: reply({
|
||||
: ({
|
||||
statusCode: 200,
|
||||
status: false,
|
||||
data: `No template found for ${req.params.pattern}`
|
||||
@ -152,8 +152,8 @@ export class WazuhElasticCtrl {
|
||||
);
|
||||
|
||||
return filtered.length >= 1
|
||||
? reply({ statusCode: 200, status: true, data: 'Index pattern found' })
|
||||
: reply({
|
||||
? ({ statusCode: 200, status: true, data: 'Index pattern found' })
|
||||
: ({
|
||||
statusCode: 500,
|
||||
status: false,
|
||||
error: 10020,
|
||||
@ -218,8 +218,8 @@ export class WazuhElasticCtrl {
|
||||
|
||||
return data.hits.total === 0 ||
|
||||
typeof data.aggregations['2'].buckets[0] === 'undefined'
|
||||
? reply({ statusCode: 200, data: '' })
|
||||
: reply({
|
||||
? ({ statusCode: 200, data: '' })
|
||||
: ({
|
||||
statusCode: 200,
|
||||
data: data.aggregations['2'].buckets[0].key
|
||||
});
|
||||
@ -239,8 +239,8 @@ export class WazuhElasticCtrl {
|
||||
const data = await this.wzWrapper.getWazuhVersionIndexAsSearch();
|
||||
|
||||
return data.hits.total === 0
|
||||
? reply({ statusCode: 200, data: '' })
|
||||
: reply({ statusCode: 200, data: data.hits.hits[0]._source });
|
||||
? ({ statusCode: 200, data: '' })
|
||||
: ({ statusCode: 200, data: data.hits.hits[0]._source });
|
||||
} catch (error) {
|
||||
log('GET /elastic/setup', error.message || error);
|
||||
return ErrorResponse(
|
||||
@ -351,7 +351,7 @@ export class WazuhElasticCtrl {
|
||||
item && item.title && !config['ip.ignore'].includes(item.title)
|
||||
);
|
||||
}
|
||||
return reply({
|
||||
return ({
|
||||
data:
|
||||
isXpackEnabled && !isSuperUser
|
||||
? await this.filterAllowedIndexPatternList(list, req)
|
||||
@ -528,7 +528,7 @@ export class WazuhElasticCtrl {
|
||||
: AgentsVisualizations[tabSufix];
|
||||
|
||||
const raw = await this.buildVisualizationsRaw(file, req.params.pattern);
|
||||
return reply({ acknowledge: true, raw: raw });
|
||||
return ({ acknowledge: true, raw: raw });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 4007, 500, reply);
|
||||
}
|
||||
@ -573,7 +573,7 @@ export class WazuhElasticCtrl {
|
||||
pattern_name
|
||||
);
|
||||
|
||||
return reply({ acknowledge: true, raw: raw });
|
||||
return ({ acknowledge: true, raw: raw });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 4009, 500, reply);
|
||||
}
|
||||
@ -596,7 +596,7 @@ export class WazuhElasticCtrl {
|
||||
req.params.pattern
|
||||
);
|
||||
|
||||
return reply({ acknowledge: true, output: output });
|
||||
return ({ acknowledge: true, output: output });
|
||||
} catch (error) {
|
||||
log('GET /elastic/known-fields/{pattern}', error.message || error);
|
||||
return ErrorResponse(error.message || error, 4008, 500, reply);
|
||||
@ -661,7 +661,7 @@ export class WazuhElasticCtrl {
|
||||
'rule.description'
|
||||
];
|
||||
const data = await this.wzWrapper.searchWazuhAlertsWithPayload(payload);
|
||||
return reply({ alerts: data.hits.hits });
|
||||
return ({ alerts: data.hits.hits });
|
||||
} catch (error) {
|
||||
log('POST /elastic/alerts', error.message || error);
|
||||
return ErrorResponse(error.message || error, 4010, 500, reply);
|
||||
|
@ -1617,7 +1617,7 @@ export class WazuhReportingCtrl {
|
||||
);
|
||||
pdfDoc.end();
|
||||
}
|
||||
return reply({ error: 0, data: null });
|
||||
return ({ error: 0, data: null });
|
||||
} catch (error) {
|
||||
// Delete generated file if an error occurred
|
||||
if (
|
||||
@ -1659,7 +1659,7 @@ export class WazuhReportingCtrl {
|
||||
list.push(file);
|
||||
});
|
||||
TimSort.sort(list, sortFunction);
|
||||
return reply({ list: list });
|
||||
return ({ list: list });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 5031, 500, reply);
|
||||
}
|
||||
@ -1694,7 +1694,7 @@ export class WazuhReportingCtrl {
|
||||
fs.unlinkSync(
|
||||
path.join(__dirname, REPORTING_PATH + '/' + req.params.name)
|
||||
);
|
||||
return reply({ error: 0 });
|
||||
return ({ error: 0 });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 5032, 500, reply);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ export class WazuhUtilsCtrl {
|
||||
try {
|
||||
const configFile = getConfiguration();
|
||||
|
||||
return reply({
|
||||
return ({
|
||||
statusCode: 200,
|
||||
error: 0,
|
||||
data: configFile || {}
|
||||
@ -54,7 +54,7 @@ export class WazuhUtilsCtrl {
|
||||
async updateConfigurationFile(req, reply) {
|
||||
try {
|
||||
const result = updateConfigurationFile.updateConfiguration(req);
|
||||
return reply({
|
||||
return ({
|
||||
statusCode: 200,
|
||||
error: 0,
|
||||
data: result.needRestart
|
||||
@ -74,7 +74,7 @@ export class WazuhUtilsCtrl {
|
||||
try {
|
||||
// RAM in MB
|
||||
const ram = Math.ceil(totalmem() / 1024 / 1024);
|
||||
return reply({ statusCode: 200, error: 0, ram });
|
||||
return ({ statusCode: 200, error: 0, ram });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 3033, 500, reply);
|
||||
}
|
||||
@ -93,13 +93,13 @@ export class WazuhUtilsCtrl {
|
||||
20
|
||||
);
|
||||
return lastLogs && Array.isArray(lastLogs)
|
||||
? reply({
|
||||
? ({
|
||||
error: 0,
|
||||
lastLogs: lastLogs.filter(
|
||||
item => typeof item === 'string' && item.length
|
||||
)
|
||||
})
|
||||
: reply({ error: 0, lastLogs: [] });
|
||||
: ({ error: 0, lastLogs: [] });
|
||||
} catch (error) {
|
||||
return ErrorResponse(error.message || error, 3036, 500, reply);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user