Skip to content

Commit

Permalink
Minor changes to server.log
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Ángel committed Aug 20, 2019
1 parent cdda9a8 commit eb8e000
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 66 deletions.
28 changes: 9 additions & 19 deletions server/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import path from 'path';
export function Initialize(server) {
const wazuhVersion = path.join(__dirname, '/wazuh-version.json');
const blueWazuh = '\u001b[34mwazuh\u001b[39m';
const initializeErrorLogColors = [blueWazuh, 'initialize', 'error'];
// Elastic JS Client
const wzWrapper = new ElasticWrapper(server);
log('initialize', `Kibana index: ${wzWrapper.WZ_KIBANA_INDEX}`, 'info');
Expand All @@ -47,7 +48,7 @@ export function Initialize(server) {
} catch (e) {
log('initialize', e.message || e);
server.log(
[blueWazuh, 'initialize', 'error'],
initializeErrorLogColors,
'Something went wrong while reading the configuration.' + e.message
);
}
Expand Down Expand Up @@ -92,7 +93,7 @@ export function Initialize(server) {
} catch (error) {
log('initialize:saveConfiguration', error.message || error);
server.log(
[blueWazuh, 'initialize', 'error'],
initializeErrorLogColors,
'Could not create Wazuh configuration registry'
);
}
Expand All @@ -101,7 +102,7 @@ export function Initialize(server) {
} catch (error) {
log('initialize:saveConfiguration', error.message || error);
server.log(
[blueWazuh, 'initialize', 'error'],
initializeErrorLogColors,
'Error creating wazuh-version registry'
);
}
Expand Down Expand Up @@ -163,7 +164,7 @@ export function Initialize(server) {
} due to ${error.message || error}`
);
server.log(
[blueWazuh, 'initialize:checkAPIEntriesExtensions', 'error'],
initializeErrorLogColors,
`Error updating API entry extensions with ID: ${
item._id
} due to ${error.message || error}`
Expand Down Expand Up @@ -240,7 +241,6 @@ export function Initialize(server) {

// Create the app registry file for the very first time
saveConfiguration();

} else {
// App registry file exists, just update it
const currentDate = new Date().toISOString();
Expand All @@ -250,7 +250,7 @@ export function Initialize(server) {

// Check if the stored revision differs from the package.json revision
const isNewApp = packageJSON.revision !== source.revision;

// If it's an app with a different revision, it's a new installation
source['installationDate'] = isNewApp
? currentDate
Expand Down Expand Up @@ -286,10 +286,7 @@ export function Initialize(server) {
);
} catch (error) {
log('initialize:init', error.message || error);
server.log(
[blueWazuh, 'initialize:init', 'error'],
error.message || error
);
server.log(initializeErrorLogColors, error.message || error);
return Promise.reject(error);
}
};
Expand All @@ -306,7 +303,7 @@ export function Initialize(server) {
} catch (error) {
log('initialize:createKibanaTemplate', error.message || error);
server.log(
[blueWazuh, 'initialize', 'error'],
initializeErrorLogColors,
'Exception: ' + error.message || error
);
}
Expand Down Expand Up @@ -388,18 +385,11 @@ export function Initialize(server) {
"Didn't find " + wzWrapper.WZ_KIBANA_INDEX + ' index...',
'info'
);
server.log(
[blueWazuh, 'initialize', 'info'],
"Didn't find " + wzWrapper.WZ_KIBANA_INDEX + ' index...'
);
await getTemplateByName();
}
} catch (error) {
log('initialize:checkKibanaStatus', error.message || error);
server.log(
[blueWazuh, 'initialize (checkKibanaStatus)', 'error'],
error.message || error
);
server.log(initializeErrorLogColors, error.message || error);
}
};

Expand Down
8 changes: 4 additions & 4 deletions server/lib/refresh-known-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ export async function checkKnownFields(
}

!quiet && log('initialize', 'App ready to be used.', 'info');
!quiet &&
server.log([blueWazuh, 'initialize', 'info'], 'App ready to be used.');
!quiet && server.log('info', 'Wazuh app ready to be used.');

return;
} catch (error) {
!quiet && log('initialize:checkKnownFields', error.message || error);
!quiet &&
server.log(
[blueWazuh, 'server', 'error'],
'Error importing objects into elasticsearch.' + error.message || error
'error',
'Wazuh app had en error importing objects into Elasticsearch.' +
error.message || error
);
}
}
61 changes: 18 additions & 43 deletions server/monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { BuildBody } from './lib/replicas-shards-helper';
import * as ApiHelper from './lib/api-helper';

const blueWazuh = '\u001b[34mwazuh\u001b[39m';
const monitoringErrorLogColors = [blueWazuh, 'monitoring', 'error'];

export class Monitoring {
/**
Expand Down Expand Up @@ -103,10 +104,7 @@ export class Monitoring {
} catch (error) {
!this.quiet && log('monitoring:configuration', error.message || error);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
error.message || error
);
this.server.log(monitoringErrorLogColors, error.message || error);
}
}

Expand Down Expand Up @@ -151,10 +149,7 @@ export class Monitoring {
this.agentsArray = [];
!this.quiet && log('monitoring:checkStatus', error.message || error);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
error.message || error
);
this.server.log(monitoringErrorLogColors, error.message || error);
}
}

Expand Down Expand Up @@ -212,18 +207,14 @@ export class Monitoring {
'Wazuh API credentials not found or are not correct. Open the app in your browser and configure it to start monitoring agents.';

!this.quiet && log('monitoring:checkAndSaveStatus', extraLog);
!this.quiet &&
this.server.log([blueWazuh, 'monitoring', 'error'], extraLog);
!this.quiet && this.server.log(monitoringErrorLogColors, extraLog);
}
return;
} catch (error) {
!this.quiet &&
log('monitoring:checkAndSaveStatus', error.message || error);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
error.message || error
);
this.server.log(monitoringErrorLogColors, error.message || error);
}
}

Expand Down Expand Up @@ -274,10 +265,7 @@ export class Monitoring {
} catch (error) {
!this.quiet && log('monitoring:loadCredentials', error.message || error);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
error.message || error
);
this.server.log(monitoringErrorLogColors, error.message || error);
}
}

Expand Down Expand Up @@ -349,7 +337,7 @@ export class Monitoring {
!this.quiet && log('monitoring:configureKibana', error.message || error);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
monitoringErrorLogColors,
'Error creating index-pattern due to ' + error
);
}
Expand Down Expand Up @@ -404,7 +392,7 @@ export class Monitoring {
);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
monitoringErrorLogColors,
`Could not create ${datedIndex} index on elasticsearch due to ${error.message ||
error}`
);
Expand Down Expand Up @@ -453,7 +441,7 @@ export class Monitoring {
);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
monitoringErrorLogColors,
`Error inserting agent data into elasticsearch. Bulk request failed due to ${error.message ||
error}`
);
Expand Down Expand Up @@ -499,7 +487,7 @@ export class Monitoring {
);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
monitoringErrorLogColors,
`Could not check if the index ${
this.datedIndex
} exists due to ${error.message || error}`
Expand Down Expand Up @@ -578,7 +566,7 @@ export class Monitoring {
);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
monitoringErrorLogColors,
`Something went wrong updating wazuh-monitoring template... ${error.message ||
error}`
);
Expand Down Expand Up @@ -612,7 +600,7 @@ export class Monitoring {
!this.quiet &&
log(
'monitoring:init',
'Checking if wazuh-monitoring pattern exists...',
'Checking if wazuh-monitoring-3.x-* index pattern exists...',
'debug'
);

Expand All @@ -626,17 +614,10 @@ export class Monitoring {
);
await this.wzWrapper.updateMonitoringIndexPatternKnownFields(patternId);
} catch (error) {
!this.quiet &&
log(
'monitoring:init',
"Didn't find wazuh-monitoring pattern for Kibana v6.x. Proceeding to create it...",
'info'
);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'info'],
"Didn't find wazuh-monitoring pattern for Kibana v6.x. Proceeding to create it..."
);
const didNotFindMsg =
"Didn't find wazuh-monitoring-3.x-* index pattern for Kibana. Proceeding to create it...";
!this.quiet && log('monitoring:init', didNotFindMsg, 'info');
!this.quiet && this.server.log(monitoringErrorLogColors, didNotFindMsg);
return this.createWazuhMonitoring();
}

Expand All @@ -650,10 +631,7 @@ export class Monitoring {
return;
} catch (error) {
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring', 'error'],
error.message || error
);
this.server.log(monitoringErrorLogColors, error.message || error);
!this.quiet && log('monitoring:init', error.message || error);
return;
}
Expand Down Expand Up @@ -758,10 +736,7 @@ export class Monitoring {

!this.quiet && log('monitoring:cronTask', error.message || error);
!this.quiet &&
this.server.log(
[blueWazuh, 'monitoring :cronTask', 'error'],
error.message || error
);
this.server.log(monitoringErrorLogColors, error.message || error);
}
}

Expand Down

0 comments on commit eb8e000

Please sign in to comment.