mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 09:55:18 +00:00
Using temporal file to use the right version
This commit is contained in:
parent
cf2c13616a
commit
80c49b4a4a
@ -5,21 +5,27 @@ module.exports = function (server, options) {
|
||||
const path = require('path');
|
||||
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 = {};
|
||||
|
||||
// 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;
|
||||
|
||||
fs.open(wazuh_temp_file, 'r', function (err, file) {
|
||||
if (err){
|
||||
try {
|
||||
wazuh_config = JSON.parse(fs.readFileSync(path.resolve(__dirname, wazuh_config_file), 'utf8'));
|
||||
const wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
} 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);
|
||||
};
|
||||
}
|
||||
else{
|
||||
const wazuh_api_version = "v2.0.0";
|
||||
}
|
||||
});
|
||||
|
||||
// Elastic JS Client
|
||||
const serverConfig = server.config();
|
||||
|
@ -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,18 @@ 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);
|
||||
};
|
||||
|
||||
const wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
if(fs.existsSync(path.resolve(__dirname, wazuh_temp_file))){
|
||||
wazuh_api_version = "v2.0.0";
|
||||
} else{
|
||||
try {
|
||||
wazuh_config = JSON.parse(fs.readFileSync(path.resolve(__dirname, wazuh_config_file), 'utf8'));
|
||||
wazuh_api_version = wazuh_config.wazuhapi.version;
|
||||
} 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);
|
||||
};
|
||||
}
|
||||
|
||||
// Load Wazuh API credentials from Elasticsearch document
|
||||
var loadCredentials = function (apiEntries) {
|
||||
@ -92,7 +96,6 @@ module.exports = function (server, options) {
|
||||
|
||||
if (!error && !response.error && response.body.data && response.body.data.totalItems) {
|
||||
checkStatus(apiEntry, response.body.data.totalItems);
|
||||
|
||||
} else {
|
||||
needle.request('get', apiEntry.url + ':' + apiEntry.port +'/version', payload, options, function (error, response) {
|
||||
if (!error && !response.error && response.body.data) {
|
||||
@ -108,18 +111,13 @@ module.exports = function (server, options) {
|
||||
}
|
||||
needle.request('get', apiEntry.url + ':' + apiEntry.port +'/version', payload, options, function (error, response) {
|
||||
if (!error && !response.error && response.body.data) {
|
||||
var newConfigFile = {
|
||||
wazuhapi : {
|
||||
requests: { timeout : 5000 },
|
||||
version: "v2.0.0",
|
||||
version_patched: wazuh_api_version
|
||||
}
|
||||
};
|
||||
try {
|
||||
fs.writeFileSync(path.resolve(__dirname, wazuh_config_file), JSON.stringify(newConfigFile, null, 4));
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Wazuh API config file is broken.');
|
||||
}
|
||||
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.');
|
||||
}
|
||||
@ -323,7 +321,7 @@ module.exports = function (server, options) {
|
||||
checkElasticStatus();
|
||||
|
||||
// Cron tab for getting agent status.
|
||||
cron.schedule('0 */10 * * * *', function () {
|
||||
cron.schedule('* */10 * * * *', function () {
|
||||
agentsArray.length = 0;
|
||||
getConfig(loadCredentials);
|
||||
}, true);
|
||||
|
Loading…
Reference in New Issue
Block a user