Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration for Wazuh monitoring shards and replicas #809

Merged
merged 5 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@
# Default: 3600 (s)
#wazuh.monitoring.frequency: 3600
#
# Configure wazuh-monitoring-3.x-* indices shards and replicas.
#wazuh.monitoring.shards: 5
#wazuh.monitoring.replicas: 1
8 changes: 5 additions & 3 deletions public/services/resolves/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export default async ($q, genericReq, errorHandler, wazuhConfig) => {
timeout : 8000,
'wazuh.shards' : 1,
'wazuh.replicas' : 1,
'wazuh-version.shards' : 1,
'wazuh-version.replicas': 1,
'ip.selector' : true,
'xpack.rbac.enabled' : true,
'wazuh.wazuh-version.shards' : 1,
'wazuh.wazuh-version.shards.replicas': 1,
'wazuh.monitoring.enabled' : true,
'wazuh.monitoring.frequency': 3600
'wazuh.monitoring.frequency': 3600,
'wazuh.monitoring.shards' : 5,
'wazuh.monitoring.replicas': 1
};

try {
Expand Down
11 changes: 9 additions & 2 deletions server/lib/elastic-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,18 @@ export default class ElasticWrapper {
}
}

async createIndexByName(name) {
async createIndexByName(name, configuration = null) {
try {
if(!name) return Promise.reject(new Error('No valid name given'));

const raw = {
index: name,
body: configuration
}

if(!configuration) delete raw.body;

const data = await this.elasticRequest.callWithInternalUser('indices.create', { index: name });
const data = await this.elasticRequest.callWithInternalUser('indices.create', raw);

return data;

Expand Down
20 changes: 19 additions & 1 deletion server/monitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,25 @@ export default (server, options) => {
const createIndex = async (todayIndex,clusterName) => {
try {
if(!ENABLED) return;
await wzWrapper.createIndexByName(todayIndex);
const configFile = getConfiguration();

const shards = configFile && typeof configFile['wazuh.monitoring.shards'] !== 'undefined' ?
configFile['wazuh.monitoring.shards'] : 5;

const replicas = configFile && typeof configFile['wazuh.monitoring.replicas'] !== 'undefined' ?
configFile['wazuh.monitoring.replicas'] : 1;

const configuration = {
settings: {
index: {
number_of_shards: shards,
number_of_replicas: replicas
}
}
};

await wzWrapper.createIndexByName(todayIndex, configuration);

log('[monitoring][createIndex]', 'Successfully created today index.', 'info');
server.log([blueWazuh, 'monitoring', 'info'], 'Successfully created today index.');
await insertDocument(todayIndex,clusterName);
Expand Down