mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-07 10:18:57 +00:00
Fixes on init function, removed configureKibana function
This commit is contained in:
parent
a25d69bee2
commit
d5d3c1d9a7
@ -199,23 +199,24 @@ module.exports = (server, options) => {
|
|||||||
if(indexPatternList && indexPatternList.hits && indexPatternList.hits.hits){
|
if(indexPatternList && indexPatternList.hits && indexPatternList.hits.hits){
|
||||||
const minimum = ["@timestamp", "full_log", "manager.name", "agent.id"];
|
const minimum = ["@timestamp", "full_log", "manager.name", "agent.id"];
|
||||||
|
|
||||||
if(indexPatternList.hits.hits.length === 0) throw new Error('There is no index pattern');
|
if(indexPatternList.hits.hits.length > 0) {
|
||||||
for(const index of indexPatternList.hits.hits){
|
for(const index of indexPatternList.hits.hits){
|
||||||
let valid, parsed;
|
let valid, parsed;
|
||||||
try{
|
try{
|
||||||
parsed = JSON.parse(index._source['index-pattern'].fields)
|
parsed = JSON.parse(index._source['index-pattern'].fields)
|
||||||
} catch (error){
|
} catch (error){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
valid = parsed.filter(item => minimum.includes(item.name));
|
valid = parsed.filter(item => minimum.includes(item.name));
|
||||||
if(valid.length === 4){
|
if(valid.length === 4){
|
||||||
list.push({
|
list.push({
|
||||||
id : index._id.split('index-pattern:')[1],
|
id : index._id.split('index-pattern:')[1],
|
||||||
title: index._source['index-pattern'].title
|
title: index._source['index-pattern'].title
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log('initialize.js checkKnownFields', `Found ${list.length} valid index patterns for Wazuh alerts`,'info')
|
log('initialize.js checkKnownFields', `Found ${list.length} valid index patterns for Wazuh alerts`,'info')
|
||||||
@ -230,9 +231,10 @@ module.exports = (server, options) => {
|
|||||||
log('initialize.js checkKnownFields', 'Waiting for default index pattern creation to complete...','info')
|
log('initialize.js checkKnownFields', 'Waiting for default index pattern creation to complete...','info')
|
||||||
server.log([blueWazuh, 'initialize', 'info'], 'Waiting for default index pattern creation to complete...');
|
server.log([blueWazuh, 'initialize', 'info'], 'Waiting for default index pattern creation to complete...');
|
||||||
let waitTill = new Date(new Date().getTime() + 0.5 * 1000);
|
let waitTill = new Date(new Date().getTime() + 0.5 * 1000);
|
||||||
|
let tmplist = null;
|
||||||
while(waitTill > new Date()){
|
while(waitTill > new Date()){
|
||||||
indexPatternList = await searchIndexPatternById(defaultIndexPattern);
|
tmplist = await searchIndexPatternById(defaultIndexPattern);
|
||||||
if(indexPatternList.hits.total >= 1) break;
|
if(tmplist.hits.total >= 1) break;
|
||||||
else waitTill = new Date(new Date().getTime() + 0.5 * 1000);
|
else waitTill = new Date(new Date().getTime() + 0.5 * 1000);
|
||||||
}
|
}
|
||||||
server.log([blueWazuh, 'initialize', 'info'], 'Index pattern created...');
|
server.log([blueWazuh, 'initialize', 'info'], 'Index pattern created...');
|
||||||
@ -285,29 +287,7 @@ module.exports = (server, options) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Configure Kibana status: Index pattern, default index pattern, default time, import dashboards.
|
|
||||||
const configureKibana = async type => {
|
|
||||||
try{
|
|
||||||
if (type === 'install') {
|
|
||||||
const data = await elasticRequest.callWithInternalUser('search', {
|
|
||||||
index: '.kibana',
|
|
||||||
type: 'doc',
|
|
||||||
q: `index-pattern.title:"${defaultIndexPattern}"`
|
|
||||||
})
|
|
||||||
|
|
||||||
if (data.hits.total >= 1) {
|
|
||||||
log('initialize.js configureKibana', 'Skipping index-pattern creation. Already exists.','info')
|
|
||||||
server.log([blueWazuh, 'initialize', 'info'], 'Skipping index-pattern creation. Already exists.');
|
|
||||||
} else {
|
|
||||||
return createIndexPattern();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} catch(error) {
|
|
||||||
log('initialize.js configureKibana', error.message || error);
|
|
||||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not reach elasticsearch.');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Save Wazuh App setup
|
// Save Wazuh App setup
|
||||||
const saveConfiguration = async () => {
|
const saveConfiguration = async () => {
|
||||||
@ -437,7 +417,6 @@ module.exports = (server, options) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -457,7 +436,6 @@ module.exports = (server, options) => {
|
|||||||
|
|
||||||
// Save Setup Info
|
// Save Setup Info
|
||||||
await saveConfiguration(defaultIndexPattern);
|
await saveConfiguration(defaultIndexPattern);
|
||||||
await configureKibana("install");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server.log([blueWazuh, 'initialize', 'info'], '.wazuh-version document already exists. Updating version information...');
|
server.log([blueWazuh, 'initialize', 'info'], '.wazuh-version document already exists. Updating version information...');
|
||||||
|
Loading…
Reference in New Issue
Block a user