mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-07 02:15:24 +00:00
Decoupling setup creation from pattern's existence
This commit is contained in:
parent
9aeac3f0a6
commit
a74e0a521c
@ -44,7 +44,7 @@ app.directive('dynamic', function($compile) {
|
||||
$scope.currentPattern = data.title;
|
||||
})
|
||||
.catch((error) => {
|
||||
notify.error("Error getting patterns from Kibana...");
|
||||
notify.error("Pattern applied to visualizations does NOT exist...");
|
||||
$scope.theresPattern = false;
|
||||
});
|
||||
|
||||
|
@ -17,7 +17,7 @@ app.controller('managerLogController', function ($scope, Logs, apiReq,Notifier)
|
||||
return;
|
||||
} catch (error) {
|
||||
if(error.data && error.data.errorData && error.data.errorData.error === 1000){
|
||||
console.log(error.data.errorData.message);
|
||||
//console.log(error.data.errorData.message);
|
||||
} else {
|
||||
notify.error(error.message);
|
||||
}
|
||||
|
@ -445,13 +445,15 @@ let app = require('ui/modules').get('app/wazuh', []).controller('settingsControl
|
||||
$scope.appInfo["app-version"] = data.data.data["app-version"];
|
||||
$scope.appInfo["installationDate"] = data.data.data["installationDate"];
|
||||
$scope.appInfo["revision"] = data.data.data["revision"];
|
||||
$scope.appInfo["index-pattern"] = data.data.data["index-pattern"];
|
||||
$scope.load = false;
|
||||
|
||||
if (appState.getCurrentPattern() !== undefined && appState.getCurrentPattern() !== null) { // There's a pattern in the cookies
|
||||
$scope.selectedIndexPattern = appState.getCurrentPattern();
|
||||
} else { // There's no pattern in the cookies, pick the one in the settings
|
||||
$scope.selectedIndexPattern = data.data.data["index-pattern"];
|
||||
genericReq.request('GET', '/api/wazuh-api/configuration', {})
|
||||
.then(config => {
|
||||
$scope.selectedIndexPattern = config.data.data["pattern"];
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -4,10 +4,8 @@ require('ui/modules').get('app/wazuh', [])
|
||||
return {
|
||||
check_stored: data => {
|
||||
const headers = {headers:{ "Content-Type": 'application/json' },timeout: 4000};
|
||||
console.log(appState.getUserCode())
|
||||
if(appState.getUserCode()) headers.headers.code = appState.getUserCode();
|
||||
let defered = $q.defer();
|
||||
console.log(data);
|
||||
$http
|
||||
.post(chrome.addBasePath('/api/wazuh-api/checkStoredAPI'), data,headers)
|
||||
.then(response => {
|
||||
|
@ -46,10 +46,6 @@
|
||||
</md-list>
|
||||
<p>If the API is <code>active (running)</code> please check its configuration below.</p>
|
||||
</md-card>
|
||||
<md-card layout-padding layout-align="start stretch" ng-if="!currentAPI">
|
||||
<h1 class="wazuh-h1"><i class="fa fa-warning ng-scope font-size-25" aria-hidden="true"></i> Please select an API from the list as default</h1>
|
||||
<p>The Wazuh app needs an API connection for it to work. Please click the API's star (<i class="fa fa-star font-size-18" aria-hidden="true"></i>) icon of your choice to select that one.</p>
|
||||
</md-card>
|
||||
|
||||
<md-card layout-padding layout-align="start stretch" ng-if="submenuNavItem == 'api'">
|
||||
|
||||
|
@ -12,8 +12,6 @@ const yml = require('js-yaml');
|
||||
const path = require('path');
|
||||
module.exports = (server, options) => {
|
||||
|
||||
|
||||
|
||||
// Elastic JS Client
|
||||
const elasticRequest = server.plugins.elasticsearch.getCluster('data');
|
||||
|
||||
@ -22,19 +20,21 @@ module.exports = (server, options) => {
|
||||
let kibana_template = {};
|
||||
let packageJSON = {};
|
||||
let pattern = null;
|
||||
// Read config from package JSON
|
||||
|
||||
// Read config from package.json and config.yml
|
||||
try {
|
||||
const configurationFile = yml.load(fs.readFileSync(path.join(__dirname,'../config.yml'), {encoding: 'utf-8'}));
|
||||
global.loginEnabled = configurationFile.login.enabled;
|
||||
pattern = configurationFile.pattern;
|
||||
packageJSON = require('../package.json');
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Something went wrong.' + e.message);
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Something went wrong while reading the configuration.' + e.message);
|
||||
}
|
||||
|
||||
if(typeof global.sessions === 'undefined') {
|
||||
global.sessions = { };
|
||||
}
|
||||
|
||||
global.protectedRoute = req => {
|
||||
if(typeof loginEnabled !== 'undefined' && !loginEnabled) return true;
|
||||
const session = (req.headers && req.headers.code) ? sessions[req.headers.code] : null;
|
||||
@ -49,30 +49,6 @@ module.exports = (server, options) => {
|
||||
|
||||
let index_pattern = pattern || "wazuh-alerts-3.x-*";
|
||||
|
||||
// Save Wazuh App first set up for future executions
|
||||
const saveConfiguration = (id) => {
|
||||
let configuration = {
|
||||
"name": "Wazuh App",
|
||||
"app-version": packageJSON.version,
|
||||
"revision": packageJSON.revision,
|
||||
"installationDate": new Date().toISOString(),
|
||||
"index-pattern": id
|
||||
};
|
||||
|
||||
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');
|
||||
});
|
||||
};
|
||||
|
||||
// Importing Wazuh built-in visualizations and dashboards
|
||||
const importObjects = (id) => {
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Importing objects (Searches, visualizations and dashboards) into Elasticsearch...');
|
||||
@ -187,9 +163,6 @@ module.exports = (server, options) => {
|
||||
// Import objects (dashboards and visualizations)
|
||||
importObjects(index_pattern);
|
||||
importAppObjects(index_pattern);
|
||||
|
||||
// Save Setup Info
|
||||
saveConfiguration(index_pattern);
|
||||
})
|
||||
.catch((err) => {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Error creating index-pattern.');
|
||||
@ -214,6 +187,29 @@ module.exports = (server, options) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Save Wazuh App setup
|
||||
const saveConfiguration = () => {
|
||||
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');
|
||||
});
|
||||
};
|
||||
|
||||
// Init function. Check for "wazuh-version" document existance.
|
||||
const init = () => {
|
||||
elasticRequest.callWithInternalUser('indices.exists', {
|
||||
@ -246,7 +242,7 @@ module.exports = (server, options) => {
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not check if the index .wazuh exists.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not check if .wazuh index exists due to ' + error);
|
||||
});
|
||||
|
||||
elasticRequest.callWithInternalUser('get', {
|
||||
@ -255,9 +251,8 @@ module.exports = (server, options) => {
|
||||
id: "1"
|
||||
})
|
||||
.then((data) => {
|
||||
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 and visualizations...');
|
||||
|
||||
// We filled data for the API, let's insert it now
|
||||
elasticRequest.callWithInternalUser('update', {
|
||||
index: '.wazuh-version',
|
||||
type: 'wazuh-version',
|
||||
@ -317,7 +312,10 @@ module.exports = (server, options) => {
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Wazuh-version document does not exist. Initializating configuration...');
|
||||
server.log([blueWazuh, 'initialize', 'info'], '.wazuh-version document does not exist. Initializating configuration...');
|
||||
|
||||
// Save Setup Info
|
||||
saveConfiguration(index_pattern);
|
||||
configureKibana("install");
|
||||
});
|
||||
};
|
||||
@ -328,7 +326,7 @@ module.exports = (server, options) => {
|
||||
try {
|
||||
kibana_template = require(KIBANA_TEMPLATE);
|
||||
} catch (e) {
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the kibana template.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the .kibana template file.');
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + KIBANA_TEMPLATE);
|
||||
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
|
||||
}
|
||||
@ -373,7 +371,7 @@ module.exports = (server, options) => {
|
||||
.catch((error) => {
|
||||
createKibanaTemplate()
|
||||
.then((data) => {
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Successfully created template .kibana.');
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Successfully created .kibana template.');
|
||||
|
||||
elasticRequest.callWithInternalUser('indices.create', { index: '.kibana' })
|
||||
.then((data) => {
|
||||
@ -398,7 +396,7 @@ module.exports = (server, options) => {
|
||||
const checkStatus = () => {
|
||||
server.plugins.elasticsearch.waitUntilReady().then((data) => { checkKibanaStatus() })
|
||||
.catch((error) => {
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Waiting for Elasticsearch servers to be ready...');
|
||||
server.log([blueWazuh, 'initialize', 'info'], 'Waiting for elasticsearch plugin to be ready...');
|
||||
setTimeout(() => checkStatus(), 3000);
|
||||
});
|
||||
};
|
||||
@ -513,7 +511,7 @@ module.exports = (server, options) => {
|
||||
server.log([blueWazuh, 'reindex', 'info'], 'Successfully updated sample cluster information for ' + wapi_config.manager);
|
||||
})
|
||||
.catch((err) => {
|
||||
server.log([blueWazuh, 'reindex', 'error'], 'Could not update sample cluster information ' + wapi_config.manager + 'due to ' + err);
|
||||
server.log([blueWazuh, 'reindex', 'error'], 'Could not update sample cluster information for ' + wapi_config.manager + 'due to ' + err);
|
||||
});
|
||||
});
|
||||
} else { // 3.x version
|
||||
|
@ -297,7 +297,7 @@ module.exports = (server, options) => {
|
||||
server.log([blueWazuh, 'monitoring', 'info'], "Successfully deleted old wazuh-monitoring pattern.");
|
||||
})
|
||||
.catch((error) => {
|
||||
server.log([blueWazuh, 'monitoring', 'error'], "Didn't find old wazuh-monitoring pattern. Skipping deletion.");
|
||||
server.log([blueWazuh, 'monitoring', 'info'], "Didn't find old wazuh-monitoring pattern. Skipping deletion.");
|
||||
});
|
||||
configureKibana();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user