Skip to content

Commit

Permalink
Change wazuh registry
Browse files Browse the repository at this point in the history
  • Loading branch information
adri9valle committed Jul 30, 2019
1 parent 99563d9 commit c24cef7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
1 change: 0 additions & 1 deletion .yarnignore

This file was deleted.

6 changes: 3 additions & 3 deletions server/controllers/wazuh-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class WazuhApiCtrl {
this.queue = Queue;
this.wzWrapper = new ElasticWrapper(server);
this.monitoringInstance = new Monitoring(server, true);
this.wazuhVersion = path.join(__dirname, '../wazuh-version.json');
this.wazuhRegistry = path.join(__dirname, '../../../../optimize/wazuh-registry.json'); ///home/vagrant/kibana/plugins/wazuh/server
this.configurationFile = new UpdateConfigurationFile();
}

Expand Down Expand Up @@ -1394,7 +1394,7 @@ export class WazuhApiCtrl {
*/
async getTimeStamp(req, reply) {
try {
const source = JSON.parse(fs.readFileSync(this.wazuhVersion, 'utf8'));
const source = JSON.parse(fs.readFileSync(this.wazuhRegistry, 'utf8'));
if (source.installationDate && source.lastRestart) {
log(
'wazuh-api:getTimeStamp',
Expand Down Expand Up @@ -1429,7 +1429,7 @@ export class WazuhApiCtrl {
*/
async getSetupInfo(req, reply) {
try {
const source = JSON.parse(fs.readFileSync(this.wazuhVersion, 'utf8'));
const source = JSON.parse(fs.readFileSync(this.wazuhRegistry, 'utf8'));
return !Object.values(source).length
? { statusCode: 200, data: '' }
: { statusCode: 200, data: source };
Expand Down
24 changes: 12 additions & 12 deletions server/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { UpdateConfigurationFile } from './lib/update-configuration';
const updateConfigurationFile = new UpdateConfigurationFile();

export function Initialize(server) {
const wazuhVersion = path.join(__dirname, '/wazuh-version.json');
const wazuhRegistry = path.join(__dirname, '../../../optimize/wazuh-registry.json');
const blueWazuh = '\u001b[34mwazuh\u001b[39m';
// Elastic JS Client
const wzWrapper = new ElasticWrapper(server);
Expand Down Expand Up @@ -81,7 +81,7 @@ export function Initialize(server) {
};

try {
fs.writeFileSync(wazuhVersion, JSON.stringify(configuration), (err) => {
fs.writeFileSync(wazuhRegistry, JSON.stringify(configuration), (err) => {
if (err) {
throw new Error(err);
}
Expand Down Expand Up @@ -236,35 +236,35 @@ export function Initialize(server) {
return apisIndexKeys;
}

const checkWazuhVersionRegistry = async () => {
const checkWazuhRegistry = async () => {
try {
log(
'initialize[checkWazuhVersionRegistry]',
'initialize[checkWazuhRegistry]',
'Checking wazuh-version registry.',
'debug'
);
try {
await wzWrapper.deleteWazuhVersionIndex();
await wzWrapper.deletewazuhRegistryIndex();
log(
'initialize[checkWazuhVersionRegistry]',
'initialize[checkWazuhRegistry]',
'Successfully deleted old .wazuh-version index.',
'debug'
);
} catch (error) {
log(
'initialize[checkWazuhVersionRegistry]',
'initialize[checkWazuhRegistry]',
'No need to delete old .wazuh-version index',
'debug'
);
}

try {
if (!fs.existsSync(wazuhVersion)) {
if (!fs.existsSync(wazuhRegistry)) {
throw new Error;
}
} catch (error) {
log(
'initialize[checkWazuhVersionRegistry]',
'initialize[checkWazuhRegistry]',
'wazuh-version registry does not exist. Initializating configuration...',
'debug'
);
Expand All @@ -273,12 +273,12 @@ export function Initialize(server) {
await saveConfiguration();
}

let source = JSON.parse(fs.readFileSync(wazuhVersion, 'utf8'));
let source = JSON.parse(fs.readFileSync(wazuhRegistry, 'utf8'));
source['app-version'] = packageJSON.version;
source.revision = packageJSON.revision;
source.lastRestart = new Date().toISOString(); // Registry exists so we update the lastRestarted date only

/* fs.writeFileSync(wazuhVersion, JSON.stringify(source), (err) => {
/* fs.writeFileSync(wazuhRegistry, JSON.stringify(source), (err) => {
if (err) {
throw new Error(err);
}
Expand All @@ -293,7 +293,7 @@ export function Initialize(server) {
try {
await Promise.all([
checkWazuhIndex(),
checkWazuhVersionRegistry(),
checkWazuhRegistry(),
checkKnownFields(wzWrapper, log, server, defaultIndexPattern)
]);
const reindexResult = await wzWrapper.reindexAppIndices();
Expand Down

0 comments on commit c24cef7

Please sign in to comment.