mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-08 02:38:51 +00:00
Merge pull request #113 from wazuh/3.0-fix-initialize
Using only the elasticsearch client for initialization tasks
This commit is contained in:
commit
93342a9ad9
@ -159,27 +159,24 @@ module.exports = (server, options) => {
|
|||||||
server.log([blueWazuh, 'initialize', 'info'],
|
server.log([blueWazuh, 'initialize', 'info'],
|
||||||
'Setting Kibana default values: Index pattern, time picker and metaFields...');
|
'Setting Kibana default values: Index pattern, time picker and metaFields...');
|
||||||
|
|
||||||
// Call the internal API and wait for the response
|
elasticRequest.callWithInternalUser('update', {
|
||||||
let options = {
|
index: '.kibana',
|
||||||
headers: {
|
type: 'doc',
|
||||||
'kbn-version': packageJSON.kibana.version
|
id: 'config:6.0.0',
|
||||||
},
|
body: {
|
||||||
json: true
|
'doc': {
|
||||||
};
|
"type": 'config',
|
||||||
|
"config": {
|
||||||
let body = {
|
"defaultIndex": id
|
||||||
"value": id
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
let requestUrl = `${server.info.uri}/api/kibana/settings/defaultIndex`;
|
|
||||||
|
|
||||||
needle('post', requestUrl, body, options)
|
|
||||||
.then((resp) => {
|
|
||||||
server.log([blueWazuh, 'initialize', 'info'],
|
|
||||||
'Wazuh index-pattern successfully set to default.');
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.then((resp) => {
|
||||||
server.log([blueWazuh, 'error'], 'Could not default Wazuh index-pattern.');
|
server.log([blueWazuh, 'initialize', 'info'], 'Successfully set to default index: ' + index_pattern);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
server.log([blueWazuh, 'initialize', 'error'], 'Could not default the index.');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -187,30 +184,25 @@ module.exports = (server, options) => {
|
|||||||
const createIndexPattern = () => {
|
const createIndexPattern = () => {
|
||||||
server.log([blueWazuh, 'initialize', 'info'], `Creating index pattern: ${index_pattern}`);
|
server.log([blueWazuh, 'initialize', 'info'], `Creating index pattern: ${index_pattern}`);
|
||||||
|
|
||||||
// Call the internal API and wait for the response
|
elasticRequest.callWithInternalUser('create', {
|
||||||
let options = {
|
index: '.kibana',
|
||||||
headers: {
|
type: 'doc',
|
||||||
'kbn-version': packageJSON.kibana.version
|
id: 'index-pattern:f1175040-d5c5-11e7-8ef5-a5944cf52264',
|
||||||
},
|
body: {
|
||||||
json: true
|
"type": 'index-pattern',
|
||||||
};
|
"index-pattern": {
|
||||||
|
"title": index_pattern,
|
||||||
let body = {
|
"timeFieldName": '@timestamp'
|
||||||
attributes: {
|
}
|
||||||
title: index_pattern,
|
}
|
||||||
timeFieldName: '@timestamp'
|
})
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let requestUrl = `${server.info.uri}/api/saved_objects/index-pattern`;
|
|
||||||
needle('post', requestUrl, body, options)
|
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
server.log([blueWazuh, 'initialize', 'info'], 'Successfully created index-pattern.');
|
server.log([blueWazuh, 'initialize', 'info'], 'Created index pattern: ' + index_pattern);
|
||||||
// Set the index-pattern as default in the Kibana configuration
|
// Set the index-pattern as default in the Kibana configuration
|
||||||
setDefaultKibanaSettings(resp.body.id);
|
setDefaultKibanaSettings('f1175040-d5c5-11e7-8ef5-a5944cf52264');
|
||||||
// Import objects (dashboards and visualizations)
|
// Import objects (dashboards and visualizations)
|
||||||
importObjects(resp.body.id);
|
importObjects('f1175040-d5c5-11e7-8ef5-a5944cf52264');
|
||||||
importAppObjects(resp.body.id);
|
importAppObjects('f1175040-d5c5-11e7-8ef5-a5944cf52264');
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
server.log([blueWazuh, 'initialize', 'error'], 'Error creating index-pattern.');
|
server.log([blueWazuh, 'initialize', 'error'], 'Error creating index-pattern.');
|
||||||
@ -285,47 +277,23 @@ module.exports = (server, options) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check Kibana server status
|
|
||||||
const checkKibanaServer = () => {
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
|
|
||||||
let requestUrl = `${server.info.uri}/api/saved_objects/index-pattern`;
|
|
||||||
needle('get', requestUrl)
|
|
||||||
.then((resp) => {
|
|
||||||
if (resp.statusCode == "200")
|
|
||||||
resolve(resp)
|
|
||||||
else
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
reject(err)
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Elasticsearch Server status and .kibana index presence
|
// Check Elasticsearch Server status and .kibana index presence
|
||||||
const checkElasticsearchServer = () => {
|
const checkElasticsearchServer = () => {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
elasticRequest
|
elasticRequest.callWithInternalUser('indices.exists', {
|
||||||
.callWithInternalUser('exists', {
|
index: ".kibana"
|
||||||
index: ".kibana",
|
|
||||||
id: packageJSON.kibana.version,
|
|
||||||
type: "config"
|
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
checkKibanaServer().then((data) => {
|
if (data) {
|
||||||
if (data.statusCode == "200"){
|
server.plugins.elasticsearch.waitUntilReady().then((data) => {
|
||||||
resolve(data)
|
resolve(data);
|
||||||
}else{
|
});
|
||||||
reject(data)
|
} else {
|
||||||
}
|
reject(data);
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
|
||||||
reject(err)
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
reject(error)
|
reject(error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -199,31 +199,25 @@ module.exports = (server, options) => {
|
|||||||
server.log([blueWazuh, 'monitoring', 'info'],
|
server.log([blueWazuh, 'monitoring', 'info'],
|
||||||
`Creating index pattern: ${index_pattern}`);
|
`Creating index pattern: ${index_pattern}`);
|
||||||
|
|
||||||
// Call the internal API and wait for the response
|
elasticRequest.callWithInternalUser('create', {
|
||||||
let options = {
|
index: '.kibana',
|
||||||
headers: {
|
type: 'doc',
|
||||||
'kbn-version': packageJSON.kibana.version
|
id: 'index-pattern:f1185040-d5c5-11e7-8ef5-a5944cf52264',
|
||||||
},
|
body: {
|
||||||
json: true
|
"type": 'index-pattern',
|
||||||
};
|
"index-pattern": {
|
||||||
|
"title": index_pattern,
|
||||||
let body = {
|
"timeFieldName": '@timestamp'
|
||||||
attributes: {
|
}
|
||||||
title: index_pattern,
|
}
|
||||||
timeFieldName: '@timestamp'
|
})
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let requestUrl = `${server.info.uri}/api/saved_objects/index-pattern`;
|
|
||||||
needle('post', requestUrl, body, options)
|
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
server.log([blueWazuh, 'monitoring', 'info'], 'Successfully created index-pattern.');
|
server.log([blueWazuh, 'monitoring', 'info'], 'Created index pattern: ' + index_pattern);
|
||||||
// Import objects (dashboards and visualizations)
|
importAppObjects('f1185040-d5c5-11e7-8ef5-a5944cf52264');
|
||||||
importAppObjects(resp.body.id);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
server.log([blueWazuh, 'monitoring', 'error'], 'Error creating index-pattern.');
|
server.log([blueWazuh, 'monitoring', 'error'], 'Error creating index-pattern.');
|
||||||
});
|
});;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Creating wazuh-monitoring index
|
// Creating wazuh-monitoring index
|
||||||
@ -322,47 +316,23 @@ module.exports = (server, options) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check Kibana server status
|
|
||||||
const checkKibanaServer = () => {
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
|
|
||||||
let requestUrl = `${server.info.uri}/api/saved_objects/index-pattern`;
|
|
||||||
needle('get', requestUrl)
|
|
||||||
.then((resp) => {
|
|
||||||
if (resp.statusCode == "200")
|
|
||||||
resolve(resp)
|
|
||||||
else
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
reject(err)
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Elasticsearch Server status and .kibana index presence
|
// Check Elasticsearch Server status and .kibana index presence
|
||||||
const checkElasticsearchServer = () => {
|
const checkElasticsearchServer = () => {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
elasticRequest
|
elasticRequest.callWithInternalUser('indices.exists', {
|
||||||
.callWithInternalUser('exists', {
|
index: ".kibana"
|
||||||
index: ".kibana",
|
|
||||||
id: packageJSON.kibana.version,
|
|
||||||
type: "config"
|
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
checkKibanaServer().then((data) => {
|
if (data) {
|
||||||
if (data.statusCode == "200"){
|
server.plugins.elasticsearch.waitUntilReady().then((data) => {
|
||||||
resolve(data)
|
resolve(data);
|
||||||
}else{
|
});
|
||||||
reject(data)
|
} else {
|
||||||
}
|
reject(data);
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
|
||||||
reject(err)
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
reject(error)
|
reject(error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user