Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure optimize/wazuh folder #2116

Merged
merged 8 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/controllers/settings/components/add-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>kibana/optimize/wazuh/config/wazuh.yml</EuiCode> to set the
connection information.
</EuiText>
<EuiSpacer />
Expand Down
2 changes: 1 addition & 1 deletion public/controllers/settings/components/api-is-down.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ hosts:
<div>
<EuiText>
Review the settings in the{' '}
<EuiCode>kibana/plugins/wazuh/wazuh.yml</EuiCode> file.
<EuiCode>kibana/optimize/wazuh/config/wazuh.yml</EuiCode> file.
</EuiText>
<EuiSpacer />
<EuiCodeBlock language="yaml">{apiExample}</EuiCodeBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion public/controllers/settings/components/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
juankaromo marked this conversation as resolved.
Show resolved Hide resolved
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
12 changes: 9 additions & 3 deletions server/controllers/wazuh-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {

import { log } from '../logger';

const REPORTING_PATH = '../../../../optimize/wazuh-reporting';
const REPORTING_PATH = '../../../../optimize/wazuh/downloads/reports';

export class WazuhReportingCtrl {
/**
Expand Down Expand Up @@ -1810,8 +1810,14 @@ export class WazuhReportingCtrl {
// Init
this.printer = new PdfPrinter(this.fonts);
this.dd.content = [];
if (!fs.existsSync(path.join(__dirname, REPORTING_PATH))) {
fs.mkdirSync(path.join(__dirname, REPORTING_PATH));
if (!fs.existsSync(path.join(__dirname, '../../../../optimize/wazuh'))) {
fs.mkdirSync(path.join(__dirname, '../../../../optimize/wazuh'));
}
if (!fs.existsSync(path.join(__dirname, '../../../../optimize/wazuh/downloads'))) {
fs.mkdirSync(path.join(__dirname, '../../../../optimize/wazuh/downloads'));
}
if (!fs.existsSync(path.join(__dirname, '../../../../optimize/wazuh/downloads/reports'))) {
fs.mkdirSync(path.join(__dirname, '../../../../optimize/wazuh/downloads/reports'));
}

if (req.payload && req.payload.array) {
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/wazuh-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion server/lib/get-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
140 changes: 140 additions & 0 deletions server/lib/initial-wazuh-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* 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.
#
# 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.
#
# ======================== Wazuh app configuration file ========================
#
# Please check the documentation for more information on configuration options:
# https://documentation.wazuh.com/current/installation-guide/index.html
#
# Also, you can check our repository:
# https://github.com/wazuh/wazuh-kibana-app
#
# ------------------------------- Index patterns -------------------------------
#
# Default index pattern to use.
#pattern: wazuh-alerts-3.x-*
#
# ----------------------------------- Checks -----------------------------------
#
# Defines which checks must to be consider by the healthcheck
# step once the Wazuh app starts. Values must to be true or false.
#checks.pattern : true
#checks.template: true
#checks.api : true
#checks.setup : true
#
# --------------------------------- Extensions ---------------------------------
#
# Defines which extensions should be activated when you add a new API entry.
# You can change them after Wazuh app starts.
# Values must to be true or false.
#extensions.pci : true
#extensions.gdpr : true
#extensions.hipaa : true
#extensions.nist : true
#extensions.audit : true
#extensions.oscap : false
#extensions.ciscat : false
#extensions.aws : false
#extensions.virustotal: false
#extensions.osquery : false
#extensions.docker : false
#
# ---------------------------------- Time out ----------------------------------
#
# Defines maximum timeout to be used on the Wazuh app requests.
# It will be ignored if it is bellow 1500.
# It means milliseconds before we consider a request as failed.
# Default: 20000
#timeout: 20000
#
# --------------------------- Index pattern selector ---------------------------
#
# Defines if the user is allowed to change the selected
# index pattern directly from the Wazuh app top menu.
# Default: true
#ip.selector: true
#
# List of index patterns to be ignored
#ip.ignore: []
#
# -------------------------------- X-Pack RBAC ---------------------------------
#
# Custom setting to enable/disable built-in X-Pack RBAC security capabilities.
# Default: enabled
#xpack.rbac.enabled: true
#
# ------------------------------ wazuh-monitoring ------------------------------
#
# Custom setting to enable/disable wazuh-monitoring indices.
# Values: true, false, worker
# If worker is given as value, the app will show the Agents status
# visualization but won't insert data on wazuh-monitoring indices.
# Default: true
#wazuh.monitoring.enabled: true
#
# Custom setting to set the frequency for wazuh-monitoring indices cron task.
# Default: 900 (s)
#wazuh.monitoring.frequency: 900
#
# Configure wazuh-monitoring-3.x-* indices shards and replicas.
#wazuh.monitoring.shards: 2
#wazuh.monitoring.replicas: 0
#
# Configure wazuh-monitoring-3.x-* indices custom creation interval.
# Values: h (hourly), d (daily), w (weekly), m (monthly)
# Default: d
#wazuh.monitoring.creation: d
#
# Default index pattern to use for Wazuh monitoring
#wazuh.monitoring.pattern: wazuh-monitoring-3.x-*
#
#
# ------------------------------- App privileges --------------------------------
#admin: true
#
# ------------------------------- App logging level -----------------------------
# Set the logging level for the Wazuh App log files.
# Default value: info
# Allowed values: info, debug
#logs.level: info
#
#-------------------------------- API entries -----------------------------------
#The following configuration is the default structure to define an API entry.
#
#hosts:
# - <id>:
# url: http(s)://<url>
# port: <port>
# user: <user>
# password: <password>

hosts:
- default:
url: https://localhost
port: 55000
user: foo
password: bar

`
13 changes: 12 additions & 1 deletion server/lib/manage-hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import yml from 'js-yaml';
import path from 'path';
import { log } from '../logger';
import { UpdateRegistry } from './update-registry';
import { initialWazuhConfig } from './initial-wazuh-config'

export class ManageHosts {
constructor() {
this.busy = false;
this.file = path.join(__dirname, '../../wazuh.yml');
this.file = path.join(__dirname, '../../../../optimize/wazuh/config/wazuh.yml');
this.updateRegistry = new UpdateRegistry();
this.initialConfig = initialWazuhConfig;
}

/**
Expand Down Expand Up @@ -64,6 +66,15 @@ export class ManageHosts {
try {
this.checkBusy();
this.busy = true;
if (!fs.existsSync(path.join(__dirname, '../../../../optimize/wazuh'))) {
fs.mkdirSync(path.join(__dirname, '../../../../optimize/wazuh'));
}
if (!fs.existsSync(path.join(__dirname, '../../../../optimize/wazuh/config'))) {
fs.mkdirSync(path.join(__dirname, '../../../../optimize/wazuh/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);
Expand Down
2 changes: 1 addition & 1 deletion server/lib/update-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
28 changes: 16 additions & 12 deletions server/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const initLogger = () => {
new winston.transports.File({
filename: path.join(
__dirname,
'../../../optimize/wazuh-logs/wazuhapp.log'
'../../../optimize/wazuh/logs/wazuhapp.log'
juankaromo marked this conversation as resolved.
Show resolved Hide resolved
)
})
]
Expand All @@ -54,7 +54,7 @@ const initLogger = () => {
new winston.transports.File({
filename: path.join(
__dirname,
'../../../optimize/wazuh-logs/wazuhapp-plain.log'
'../../../optimize/wazuh/logs/wazuhapp-plain.log'
)
})
]
Expand All @@ -65,12 +65,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, '../../../optimize/wazuh/logs'))) {
fs.mkdirSync(path.join(__dirname, '../../../optimize/wazuh/logs'));
}
if (
typeof wazuhlogger === 'undefined' ||
Expand Down Expand Up @@ -109,18 +113,18 @@ const checkFiles = () => {
if (allowed) {
if (
getFilesizeInMegaBytes(
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp.log')
path.join(__dirname, '../../../optimize/wazuh/logs/wazuhapp.log')
) >= 100
) {
fs.renameSync(
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp.log'),
path.join(__dirname, '../../../optimize/wazuh/logs/wazuhapp.log'),
path.join(
__dirname,
`../../../optimize/wazuh-logs/wazuhapp.${new Date().getTime()}.log`
`../../../optimize/wazuh/logs/wazuhapp.${new Date().getTime()}.log`
)
);
fs.writeFileSync(
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp.log'),
path.join(__dirname, '../../../optimize/wazuh/logs/wazuhapp.log'),
JSON.stringify({
date: new Date(),
level: 'info',
Expand All @@ -131,14 +135,14 @@ const checkFiles = () => {
}
if (
getFilesizeInMegaBytes(
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp-plain.log')
path.join(__dirname, '../../../optimize/wazuh/logs/wazuhapp-plain.log')
) >= 100
) {
fs.renameSync(
path.join(__dirname, '../../../optimize/wazuh-logs/wazuhapp-plain.log'),
path.join(__dirname, '../../../optimize/wazuh/logs/wazuhapp-plain.log'),
path.join(
__dirname,
`../../../optimize/wazuh-logs/wazuhapp-plain.${new Date().getTime()}.log`
`../../../optimize/wazuh/logs/wazuhapp-plain.${new Date().getTime()}.log`
)
);
}
Expand Down