mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-06 09:55:18 +00:00
Restructure optimize/wazuh folder (#2116)
* Restructure optimize/wazuh folder * Update protocol of initial config example * Replace path with a constant * Remove wazuh.yml file * Update README upgrade guide * Fix plugin helper error Co-authored-by: Pablo Torres <pablotr9@correo.ugr.es>
This commit is contained in:
parent
6376e2b771
commit
824e427896
@ -3,7 +3,6 @@
|
||||
"package.json",
|
||||
"LICENSE",
|
||||
"tsconfig.json",
|
||||
"wazuh.yml",
|
||||
"index.js",
|
||||
"init.js",
|
||||
"server/**/*",
|
||||
@ -11,4 +10,4 @@
|
||||
"public/**/*",
|
||||
"util/**/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
23
README.md
23
README.md
@ -60,7 +60,7 @@ service kibana restart
|
||||
|
||||
## Upgrade
|
||||
|
||||
Note: For updates from Wazuh 3.11.x to 3.11.y (regardless of the version of the Elastic Stack) it is recommended to make a backup of the Wazuh app configuration file in order not to lose the modified parameters or the configured APIs.
|
||||
Note: For updates from Wazuh 3.11.x to 3.12.y (regardless of the version of the Elastic Stack) the location of the wazuh.yml has been moved from `/usr/share/kibana/plugins/wazuh/wazuh.yml` to `/usr/share/kibana/optimize/wazuh/config/wazuh.yml`.
|
||||
|
||||
Stop Kibana
|
||||
|
||||
@ -76,10 +76,11 @@ systemctl stop kibana
|
||||
service kibana stop
|
||||
```
|
||||
|
||||
Make a backup of the configuration file.
|
||||
Copy the wazuh.yml to its new location. (Only needed for upgrades from 3.11.x to 3.12.y)
|
||||
|
||||
```
|
||||
cp /usr/share/kibana/plugins/wazuh/wazuh.yml /tmp/wazuh-backup.yml
|
||||
mkdir -p /usr/share/kibana/optimize/wazuh/config
|
||||
cp /usr/share/kibana/plugins/wazuh/wazuh.yml /usr/share/kibana/optimize/wazuh/config/wazuh.yml
|
||||
```
|
||||
|
||||
Remove the app using kibana-plugin tool
|
||||
@ -109,19 +110,6 @@ cd /usr/share/kibana
|
||||
sudo -u kibana bin/kibana-plugin install https://packages.wazuh.com/wazuhapp/wazuhapp-3.12.0_7.6.0.zip
|
||||
```
|
||||
|
||||
Restore the configuration file backup.
|
||||
|
||||
```
|
||||
sudo cp /tmp/wazuh-backup.yml /usr/share/kibana/plugins/wazuh/wazuh.yml
|
||||
```
|
||||
|
||||
Update configuration file permissions.
|
||||
|
||||
```
|
||||
sudo chown kibana:kibana /usr/share/kibana/plugins/wazuh/wazuh.yml
|
||||
sudo chmod 600 /usr/share/kibana/plugins/wazuh/wazuh.yml
|
||||
```
|
||||
|
||||
Restart Kibana
|
||||
|
||||
- Systemd:
|
||||
@ -134,7 +122,8 @@ systemctl restart kibana
|
||||
|
||||
```
|
||||
service kibana restart
|
||||
```
|
||||
```
|
||||
|
||||
|
||||
## Wazuh - Kibana compatibility matrix
|
||||
|
||||
|
@ -137,7 +137,7 @@ export class AddApi extends Component {
|
||||
const editConfigChildren = (
|
||||
<div>
|
||||
<EuiText>
|
||||
Modify <EuiCode>kibana/plugins/wazuh/wazuh.yml</EuiCode> to set the
|
||||
Modify <EuiCode>/usr/share/kibana/optimize/wazuh/config/wazuh.yml</EuiCode> to set the
|
||||
connection information.
|
||||
</EuiText>
|
||||
<EuiSpacer />
|
||||
|
@ -224,7 +224,7 @@ hosts:
|
||||
<div>
|
||||
<EuiText>
|
||||
Review the settings in the{' '}
|
||||
<EuiCode>kibana/plugins/wazuh/wazuh.yml</EuiCode> file.
|
||||
<EuiCode>/usr/share/kibana/optimize/wazuh/config/wazuh.yml</EuiCode> file.
|
||||
</EuiText>
|
||||
<EuiSpacer />
|
||||
<EuiCodeBlock language="yaml">{apiExample}</EuiCodeBlock>
|
||||
|
@ -65,7 +65,7 @@ export class WzConfigurationSettings extends Component {
|
||||
<EuiFlexGroup>
|
||||
<EuiFlexItem>
|
||||
<EuiText color="subdued" style={{ paddingBottom: '15px' }}>
|
||||
Configuration file located at /usr/share/kibana/plugins/wazuh/wazuh.yml
|
||||
Configuration file located at /usr/share/kibana/optimize/wazuh/config/wazuh.yml
|
||||
</EuiText>
|
||||
</EuiFlexItem>
|
||||
</EuiFlexGroup>
|
||||
|
@ -98,7 +98,7 @@ export default class SettingsLogs extends Component {
|
||||
<EuiFlexGroup>
|
||||
<EuiFlexItem>
|
||||
<EuiText color="subdued" style={{ paddingBottom: '15px' }}>
|
||||
Log file located at /usr/share/kibana/optimize/wazuh-logs/wazuhapp.log
|
||||
Log file located at /usr/share/kibana/optimize/wazuh/logs/wazuhapp.log
|
||||
</EuiText>
|
||||
</EuiFlexItem>
|
||||
</EuiFlexGroup>
|
||||
|
@ -39,7 +39,8 @@ import {
|
||||
|
||||
import { log } from '../logger';
|
||||
|
||||
const REPORTING_PATH = '../../../../optimize/wazuh-reporting';
|
||||
const BASE_OPTIMIZE_PATH = '../../../../optimize';
|
||||
const REPORTING_PATH = `${BASE_OPTIMIZE_PATH}/wazuh/downloads/reports`;
|
||||
|
||||
export class WazuhReportingCtrl {
|
||||
/**
|
||||
@ -1810,6 +1811,12 @@ export class WazuhReportingCtrl {
|
||||
// Init
|
||||
this.printer = new PdfPrinter(this.fonts);
|
||||
this.dd.content = [];
|
||||
if (!fs.existsSync(path.join(__dirname, `${BASE_OPTIMIZE_PATH}/wazuh`))) {
|
||||
fs.mkdirSync(path.join(__dirname, `${BASE_OPTIMIZE_PATH}/wazuh`));
|
||||
}
|
||||
if (!fs.existsSync(path.join(__dirname, `${BASE_OPTIMIZE_PATH}/wazuh/downloads`))) {
|
||||
fs.mkdirSync(path.join(__dirname, `${BASE_OPTIMIZE_PATH}/wazuh/downloads`));
|
||||
}
|
||||
if (!fs.existsSync(path.join(__dirname, REPORTING_PATH))) {
|
||||
fs.mkdirSync(path.join(__dirname, REPORTING_PATH));
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ export class WazuhUtilsCtrl {
|
||||
async getAppLogs(req, reply) {
|
||||
try {
|
||||
const lastLogs = await simpleTail(
|
||||
path.join(__dirname, '../../../../optimize/wazuh-logs/wazuhapp.log'),
|
||||
path.join(__dirname, '../../../../optimize/wazuh/logs/wazuhapp.log'),
|
||||
50
|
||||
);
|
||||
return lastLogs && Array.isArray(lastLogs)
|
||||
|
@ -19,7 +19,7 @@ export function getConfiguration(isUpdating=false) {
|
||||
const now = new Date().getTime();
|
||||
const dateDiffer = now - lastAssign;
|
||||
if (!cachedConfiguration || dateDiffer >= 10000 || isUpdating) {
|
||||
const customPath = path.join(__dirname, '../../wazuh.yml');
|
||||
const customPath = path.join(__dirname, '../../../../optimize/wazuh/config/wazuh.yml');
|
||||
const raw = fs.readFileSync(customPath, { encoding: 'utf-8' });
|
||||
const file = yml.load(raw);
|
||||
cachedConfiguration = { ...file };
|
||||
|
@ -1,4 +1,16 @@
|
||||
---
|
||||
/*
|
||||
* Wazuh app - Initial basic configuration file
|
||||
* Copyright (C) 2015-2020 Wazuh, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Find more information about this on the LICENSE file.
|
||||
*/
|
||||
|
||||
export const initialWazuhConfig = `---
|
||||
#
|
||||
# Wazuh app - App configuration file
|
||||
# Copyright (C) 2015-2020 Wazuh, Inc.
|
||||
@ -128,3 +140,5 @@ hosts:
|
||||
port: 55000
|
||||
user: foo
|
||||
password: bar
|
||||
|
||||
`
|
@ -14,12 +14,16 @@ import yml from 'js-yaml';
|
||||
import path from 'path';
|
||||
import { log } from '../logger';
|
||||
import { UpdateRegistry } from './update-registry';
|
||||
import { initialWazuhConfig } from './initial-wazuh-config'
|
||||
|
||||
const BASE_LOGS_PATH = '../../../../optimize/wazuh';
|
||||
|
||||
export class ManageHosts {
|
||||
constructor() {
|
||||
this.busy = false;
|
||||
this.file = path.join(__dirname, '../../wazuh.yml');
|
||||
this.file = path.join(__dirname, `${BASE_LOGS_PATH}/config/wazuh.yml`);
|
||||
this.updateRegistry = new UpdateRegistry();
|
||||
this.initialConfig = initialWazuhConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,6 +68,15 @@ export class ManageHosts {
|
||||
try {
|
||||
this.checkBusy();
|
||||
this.busy = true;
|
||||
if (!fs.existsSync(path.join(__dirname, BASE_LOGS_PATH))) {
|
||||
fs.mkdirSync(path.join(__dirname, BASE_LOGS_PATH));
|
||||
}
|
||||
if (!fs.existsSync(path.join(__dirname, `${BASE_LOGS_PATH}/config`))) {
|
||||
fs.mkdirSync(path.join(__dirname, `${BASE_LOGS_PATH}/config`));
|
||||
}
|
||||
if (!fs.existsSync(path.join(__dirname, '../../../../optimize/wazuh/config/wazuh.yml'))) {
|
||||
await fs.writeFileSync(this.file, this.initialConfig, 'utf8');
|
||||
}
|
||||
const raw = fs.readFileSync(this.file, { encoding: 'utf-8' });
|
||||
this.busy = false;
|
||||
const content = yml.load(raw);
|
||||
|
@ -27,7 +27,7 @@ const needRestartFields = [
|
||||
export class UpdateConfigurationFile {
|
||||
constructor() {
|
||||
this.busy = false;
|
||||
this.file = path.join(__dirname, '../../wazuh.yml');
|
||||
this.file = path.join(__dirname, '../../../../optimize/wazuh/config/wazuh.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,9 @@ import { getConfiguration } from './lib/get-configuration';
|
||||
let allowed = false;
|
||||
let wazuhlogger = undefined;
|
||||
let wazuhPlainLogger = undefined;
|
||||
const logsBasePath = '../../../optimize/wazuh/logs'
|
||||
const plainLogFilePath = `${logsBasePath}/wazuhapp-plain.log`
|
||||
const rawLogFilePath = `${logsBasePath}/wazuhapp.log`
|
||||
|
||||
/**
|
||||
* Here we create the loggers
|
||||
@ -37,7 +40,7 @@ const initLogger = () => {
|
||||
new winston.transports.File({
|
||||
filename: path.join(
|
||||
__dirname,
|
||||
'../../../optimize/wazuh-logs/wazuhapp.log'
|
||||
rawLogFilePath
|
||||
)
|
||||
})
|
||||
]
|
||||
@ -54,7 +57,7 @@ const initLogger = () => {
|
||||
new winston.transports.File({
|
||||
filename: path.join(
|
||||
__dirname,
|
||||
'../../../optimize/wazuh-logs/wazuhapp-plain.log'
|
||||
plainLogFilePath
|
||||
)
|
||||
})
|
||||
]
|
||||
@ -65,12 +68,16 @@ const initLogger = () => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if wazuh-logs exists. If it doesn't exist, it will be created.
|
||||
* Checks if wazuh/logs exists. If it doesn't exist, it will be created.
|
||||
*/
|
||||
const initDirectory = async () => {
|
||||
try {
|
||||
if (!fs.existsSync(path.join(__dirname, '../../../optimize/wazuh-logs'))) {
|
||||
fs.mkdirSync(path.join(__dirname, '../../../optimize/wazuh-logs'));
|
||||
|
||||
if (!fs.existsSync(path.join(__dirname, '../../../optimize/wazuh'))) {
|
||||
fs.mkdirSync(path.join(__dirname, '../../../optimize/wazuh'));
|
||||
}
|
||||
if (!fs.existsSync(path.join(__dirname, logsBasePath))) {
|
||||
fs.mkdirSync(path.join(__dirname, logsBasePath));
|
||||
}
|
||||
if (
|
||||
typeof wazuhlogger === 'undefined' ||
|
||||
@ -109,18 +116,18 @@ const checkFiles = () => {
|
||||
if (allowed) {
|
||||
if (
|
||||
getFilesizeInMegaBytes(
|
||||
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp.log')
|
||||
path.join(__dirname, rawLogFilePath)
|
||||
) >= 100
|
||||
) {
|
||||
fs.renameSync(
|
||||
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp.log'),
|
||||
path.join(__dirname, rawLogFilePath),
|
||||
path.join(
|
||||
__dirname,
|
||||
`../../../optimize/wazuh-logs/wazuhapp.${new Date().getTime()}.log`
|
||||
`${logsBasePath}/wazuhapp.${new Date().getTime()}.log`
|
||||
)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp.log'),
|
||||
path.join(__dirname, rawLogFilePath),
|
||||
JSON.stringify({
|
||||
date: new Date(),
|
||||
level: 'info',
|
||||
@ -131,14 +138,14 @@ const checkFiles = () => {
|
||||
}
|
||||
if (
|
||||
getFilesizeInMegaBytes(
|
||||
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp-plain.log')
|
||||
path.join(__dirname, plainLogFilePath)
|
||||
) >= 100
|
||||
) {
|
||||
fs.renameSync(
|
||||
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp-plain.log'),
|
||||
path.join(__dirname, plainLogFilePath),
|
||||
path.join(
|
||||
__dirname,
|
||||
`../../../optimize/wazuh-logs/wazuhapp-plain.${new Date().getTime()}.log`
|
||||
`${plainLogFilePath}.${new Date().getTime()}.log`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user