mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 09:55:18 +00:00
Adding shard and replica configuration for .wazuh and .wazuh-version
This commit is contained in:
parent
b4d1f9b744
commit
0702a2a9bb
10
config.yml
10
config.yml
@ -46,3 +46,13 @@
|
|||||||
# Default value is 8000. It will be ignored if it is bellow 1500.
|
# Default value is 8000. It will be ignored if it is bellow 1500.
|
||||||
# It means milliseconds before we consider a request as failed.
|
# It means milliseconds before we consider a request as failed.
|
||||||
#timeout: 4000
|
#timeout: 4000
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#--------------------- Indices configuration ------------------------------------
|
||||||
|
#
|
||||||
|
# Configure .wazuh and .wazuh-version indices shards and replicas
|
||||||
|
#wazuh.shards : 3
|
||||||
|
#wazuh.replicas : 7
|
||||||
|
#wazuh-version.shards : 9
|
||||||
|
#wazuh-version.replicas : 6
|
||||||
|
#
|
@ -15,15 +15,16 @@ module.exports = (server, options) => {
|
|||||||
// Elastic JS Client
|
// Elastic JS Client
|
||||||
const elasticRequest = server.plugins.elasticsearch.getCluster('data');
|
const elasticRequest = server.plugins.elasticsearch.getCluster('data');
|
||||||
|
|
||||||
let objects = {};
|
let objects = {};
|
||||||
let app_objects = {};
|
let app_objects = {};
|
||||||
let kibana_template = {};
|
let kibana_template = {};
|
||||||
let packageJSON = {};
|
let packageJSON = {};
|
||||||
let pattern = null;
|
let configurationFile = {};
|
||||||
|
let pattern = null;
|
||||||
|
|
||||||
// Read config from package.json and config.yml
|
// Read config from package.json and config.yml
|
||||||
try {
|
try {
|
||||||
const configurationFile = yml.load(fs.readFileSync(path.join(__dirname,'../config.yml'), {encoding: 'utf-8'}));
|
configurationFile = yml.load(fs.readFileSync(path.join(__dirname,'../config.yml'), {encoding: 'utf-8'}));
|
||||||
|
|
||||||
global.loginEnabled = (configurationFile && typeof configurationFile['login.enabled'] !== 'undefined') ? configurationFile['login.enabled'] : false;
|
global.loginEnabled = (configurationFile && typeof configurationFile['login.enabled'] !== 'undefined') ? configurationFile['login.enabled'] : false;
|
||||||
pattern = (configurationFile && typeof configurationFile.pattern !== 'undefined') ? configurationFile.pattern : 'wazuh-alerts-3.x-*';
|
pattern = (configurationFile && typeof configurationFile.pattern !== 'undefined') ? configurationFile.pattern : 'wazuh-alerts-3.x-*';
|
||||||
@ -192,24 +193,56 @@ module.exports = (server, options) => {
|
|||||||
|
|
||||||
// Save Wazuh App setup
|
// Save Wazuh App setup
|
||||||
const saveConfiguration = () => {
|
const saveConfiguration = () => {
|
||||||
let configuration = {
|
|
||||||
"name": "Wazuh App",
|
let shards = 1;
|
||||||
"app-version": packageJSON.version,
|
let replicas = 1;
|
||||||
"revision": packageJSON.revision,
|
|
||||||
"installationDate": new Date().toISOString()
|
if (configurationFile) {
|
||||||
|
if (configurationFile["wazuh-version.shards"]) {
|
||||||
|
shards = configurationFile["wazuh-version.shards"];
|
||||||
|
}
|
||||||
|
if (configurationFile["wazuh-version.replicas"]) {
|
||||||
|
replicas = configurationFile["wazuh-version.replicas"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let shard_configuration = {
|
||||||
|
"settings" : {
|
||||||
|
"index" : {
|
||||||
|
"number_of_shards" : shards,
|
||||||
|
"number_of_replicas" : replicas
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
elasticRequest.callWithInternalUser('create', {
|
elasticRequest.callWithInternalUser('indices.create', {
|
||||||
index: ".wazuh-version",
|
index: '.wazuh-version',
|
||||||
type: 'wazuh-version',
|
body: shard_configuration
|
||||||
id: 1,
|
|
||||||
body: configuration
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
server.log([blueWazuh, 'initialize', 'info'], 'Wazuh configuration inserted');
|
|
||||||
|
let configuration = {
|
||||||
|
"name": "Wazuh App",
|
||||||
|
"app-version": packageJSON.version,
|
||||||
|
"revision": packageJSON.revision,
|
||||||
|
"installationDate": new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
elasticRequest.callWithInternalUser('create', {
|
||||||
|
index: ".wazuh-version",
|
||||||
|
type: 'wazuh-version',
|
||||||
|
id: 1,
|
||||||
|
body: configuration
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
server.log([blueWazuh, 'initialize', 'info'], 'Wazuh configuration inserted');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
server.log([blueWazuh, 'initialize', 'error'], 'Could not insert Wazuh configuration');
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not insert Wazuh configuration');
|
server.log([blueWazuh, 'initialize', 'error'], 'Error creating index .wazuh-version.');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -220,8 +253,31 @@ module.exports = (server, options) => {
|
|||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
||||||
|
let shards = 1;
|
||||||
|
let replicas = 1;
|
||||||
|
|
||||||
|
if (configurationFile) {
|
||||||
|
if (configurationFile["wazuh.shards"]) {
|
||||||
|
shards = configurationFile["wazuh.shards"];
|
||||||
|
}
|
||||||
|
if (configurationFile["wazuh.replicas"]) {
|
||||||
|
replicas = configurationFile["wazuh.replicas"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let configuration = {
|
||||||
|
"settings" : {
|
||||||
|
"index" : {
|
||||||
|
"number_of_shards" : shards,
|
||||||
|
"number_of_replicas" : replicas
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
elasticRequest.callWithInternalUser('indices.create', {
|
elasticRequest.callWithInternalUser('indices.create', {
|
||||||
index: '.wazuh'
|
index: '.wazuh',
|
||||||
|
body: configuration
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
server.log([blueWazuh, 'initialize', 'info'], 'Index .wazuh created.');
|
server.log([blueWazuh, 'initialize', 'info'], 'Index .wazuh created.');
|
||||||
|
Loading…
Reference in New Issue
Block a user