mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 09:55:18 +00:00
Patching API version within the App
This commit is contained in:
commit
30cb219a80
@ -3,23 +3,29 @@ module.exports = function (server, options) {
|
||||
const pciRequirementsFile = '';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const needle = require('needle');
|
||||
var fetchAgentsExternal = require(path.resolve(__dirname, "../wazuh-monitoring.js"));
|
||||
const wazuh_config_file = '../../configuration/config.json';
|
||||
const wazuh_temp_file = '../../configuration/.patch_version';
|
||||
var colors = require('ansicolors');
|
||||
var blueWazuh = colors.blue('wazuh');
|
||||
var wazuh_config = {};
|
||||
|
||||
var wazuh_api_version;
|
||||
|
||||
// Read Wazuh App configuration file
|
||||
try {
|
||||
wazuh_config = JSON.parse(fs.readFileSync(path.resolve(__dirname, wazuh_config_file), 'utf8'));
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh configuration file file.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + wazuh_config_file);
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
|
||||
};
|
||||
|
||||
const wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
try {
|
||||
wazuh_config = JSON.parse(fs.readFileSync(path.resolve(__dirname, wazuh_config_file), 'utf8'));
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh configuration file file.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + wazuh_config_file);
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
|
||||
};
|
||||
|
||||
if(fs.existsSync(path.resolve(__dirname, wazuh_temp_file))){
|
||||
wazuh_api_version = "v2.0.0";
|
||||
} else{
|
||||
wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
}
|
||||
|
||||
// Elastic JS Client
|
||||
const serverConfig = server.config();
|
||||
@ -313,6 +319,38 @@ module.exports = function (server, options) {
|
||||
reply({ 'statusCode': 400, 'error': 7, 'message': 'Missing data' }).code(400);
|
||||
return;
|
||||
}
|
||||
|
||||
var options = {
|
||||
headers: { 'api-version': wazuh_api_version },
|
||||
username: req.payload.user,
|
||||
password: req.payload.password,
|
||||
rejectUnauthorized: !req.payload.insecure
|
||||
};
|
||||
|
||||
needle.request('get', req.payload.url + ':' + req.payload.port +'/version', {}, options, function (error, response) {
|
||||
if (error || response.error || !response.body.data) {
|
||||
options = {
|
||||
headers: { 'api-version': 'v2.0.0' },
|
||||
username: req.payload.user,
|
||||
password: req.payload.password,
|
||||
rejectUnauthorized: !req.payload.insecure
|
||||
}
|
||||
needle.request('get', req.payload.url + ':' + req.payload.port +'/version', {}, options, function (error, response) {
|
||||
if (!error && !response.error && response.body.data) {
|
||||
fs.writeFile(path.resolve(__dirname, wazuh_temp_file), "#Temporal file to avoid inconsistences when using App 2.0.1 with API 2.0.0",function(err){
|
||||
if(err) server.log([blueWazuh, 'initialize', 'error'], err);
|
||||
else{
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Temporal file created to use the API 2.0.0');
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Wazuh API credentials not found or are not correct. Open the app in your browser and configure it for start monitoring agents.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var settings = { 'api_user': req.payload.user, 'api_password': req.payload.password, 'url': req.payload.url, 'api_port': req.payload.port , 'insecure': req.payload.insecure, 'component' : 'API', 'active' : req.payload.active, 'manager' : req.payload.manager, 'extensions' : req.payload.extensions};
|
||||
|
||||
elasticRequest.callWithRequest(req, 'index', { index: '.kibana', type: 'wazuh-configuration', body: settings, refresh: true })
|
||||
|
@ -28,7 +28,8 @@ module.exports = function (server, options) {
|
||||
const TEMPLATE_FILE = 'startup/integration_files/template_file.json';
|
||||
const MONITORING_SAMPLE_FILE = 'startup/integration_files/monitoring_sample.json';
|
||||
const wazuh_config_file = '../configuration/config.json';
|
||||
|
||||
const wazuh_temp_file = '../configuration/.patch_version';
|
||||
var wazuh_api_version;
|
||||
var monitoring_sample = {};
|
||||
var kibana_fields_data = {};
|
||||
var map_jsondata = {};
|
||||
@ -39,15 +40,19 @@ module.exports = function (server, options) {
|
||||
var todayIndex = index_prefix + fDate;
|
||||
|
||||
// Read Wazuh App configuration file
|
||||
try {
|
||||
wazuh_config = JSON.parse(fs.readFileSync(path.resolve(__dirname, wazuh_config_file), 'utf8'));
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh configuration file file.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + wazuh_config_file);
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
|
||||
};
|
||||
try {
|
||||
wazuh_config = JSON.parse(fs.readFileSync(path.resolve(__dirname, wazuh_config_file), 'utf8'));
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh configuration file file.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + wazuh_config_file);
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
|
||||
};
|
||||
|
||||
const wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
if(fs.existsSync(path.resolve(__dirname, wazuh_temp_file))){
|
||||
wazuh_api_version = "v2.0.0";
|
||||
} else{
|
||||
wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
}
|
||||
|
||||
// Load Wazuh API credentials from Elasticsearch document
|
||||
var loadCredentials = function (apiEntries) {
|
||||
@ -92,10 +97,34 @@ module.exports = function (server, options) {
|
||||
|
||||
if (!error && !response.error && response.body.data && response.body.data.totalItems) {
|
||||
checkStatus(apiEntry, response.body.data.totalItems);
|
||||
|
||||
} else {
|
||||
server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'Wazuh API credentials not found or are not correct. Open the app in your browser and configure it for start monitoring agents.');
|
||||
return;
|
||||
needle.request('get', apiEntry.url + ':' + apiEntry.port +'/version', payload, options, function (error, response) {
|
||||
if (!error && !response.error && response.body.data) {
|
||||
server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'Wazuh API credentials not found or are not correct. Open the app in your browser and configure it for start monitoring agents.');
|
||||
return;
|
||||
}
|
||||
else{
|
||||
options = {
|
||||
headers: { 'api-version': 'v2.0.0' },
|
||||
username: apiEntry.user,
|
||||
password: apiEntry.password,
|
||||
rejectUnauthorized: !apiEntry.insecure
|
||||
}
|
||||
needle.request('get', apiEntry.url + ':' + apiEntry.port +'/version', payload, options, function (error, response) {
|
||||
if (!error && !response.error && response.body.data) {
|
||||
fs.writeFile(path.resolve(__dirname, wazuh_temp_file), "#Temporal file to avoid inconsistences when using App 2.0.1 with API 2.0.0",function(err){
|
||||
if(err) server.log([blueWazuh, 'initialize', 'error'], err);
|
||||
else{
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Temporal file created to use the API 2.0.0');
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Wazuh API credentials not found or are not correct. Open the app in your browser and configure it for start monitoring agents.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user