Added new GET route to check

total RAM
This commit is contained in:
Jesús Ángel González 2018-05-28 11:06:09 +02:00 committed by Javier Castro
parent 5caeff0f25
commit 1458b35bf5
2 changed files with 15 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import monitoring from '../monitoring'
import ErrorResponse from './error-response'
import { Parser } from 'json2csv';
import getConfiguration from '../lib/get-configuration'
import { totalmem } from 'os'
const blueWazuh = colors.blue('wazuh');
@ -386,7 +387,7 @@ export default class WazuhApi {
if(req.payload.method !== 'GET' && req.payload.body && req.payload.body.devTools){
const configuration = getConfiguration();
if(!configuration || (configuration && !configuration['devtools.allowall'])){
return ErrorResponse('Allowed method: [GET]', 3023, 400, reply);
return ErrorResponse('Allowed method: [GET]', 3029, 400, reply);
}
}
if(req.payload.body.devTools) {
@ -528,4 +529,14 @@ export default class WazuhApi {
return res({ error: error.message || error }).code(500)
}
}
async totalRam(req,reply) {
try{
// RAM in MB
const ram = Math.ceil(totalmem()/1024/1024);
return reply({ statusCode: 200, error: 0, ram });
} catch (error) {
return ErrorResponse(error.message || error, 3030, 500, reply);
}
}
}

View File

@ -41,4 +41,7 @@ export default (server, options) => {
// Returns data from the Wazuh API on CSV readable format
server.route({ method: 'POST', path: '/api/wazuh-api/csv', handler: (req,res) => ctrl.csv(req,res)})
// Returns total RAM available from the current machine where Kibana is being executed
server.route({ method: 'GET', path: '/api/wazuh-api/ram', handler: (req,res) => ctrl.totalRam(req,res)})
};