Skip to content

Commit

Permalink
Migrate API entries from .wazuh index to wazuh.yml (#1811)
Browse files Browse the repository at this point in the history
* Removed "Pattern" and "First use" sections from Settings

* Simplified API entries table in Settings

* Started "API is down" guide

* Started "Add API" guide

* Loading new components for Settings

* Adapt Settings views for using new components

* Migrate hosts and remove .wazuh index

* Prevent duplicate hosts

* Improve regex

* Cleaning settings.js controller (in progress)

* Prevent try to add again if .wazuh was not deleted

* Add function to check if is busy

* Migrate the cluster_info and extensions to the wazuh-registry

* Replace wazuh-version by wazuh-registry

* Add endpoint to get the host from wazuh-hosts.yml

* Get the APIs from the wazuh-hosts.yml

* Updates the cluster info in the registry when checking connection

* Remove console.error

* Check api connection from wazuh-host data

* Try to connect to another API in case the default fails

* Adapt settings-wizard and api-count

* Adapt wazuh-api.js controller for using wazuh-hosts.yml

* Prevent undefined results

* Clean initialize

* Remove wazuh-api-elastic routes and controllers

* Remove addApiProps

* Change config.yml by wazuh.yml

* Replace config.yml in the kibana plugin helper

* Delete wazuh-api-elastic tests

* Check for orphan registry entries

* Check manager connection before setting as default

* Prevent error toaster when there is any api entry

* Prevent errors when any api is reachable

* Check for new apis and their connection

* Prevent error when update registry of undefined

* Prevent error when no cluster_info

* Remove console.log

* Change state by props

* Fix settings-wizard

* Fix when joinning hosts and registry

* Check for new API entries

* Close add api component

* Remove await

* Improve checks for new apis

* Test if API is down in wazuh-api

* Check down APIs

* Api is down component finish

* Transform hosts in the backend

* Fix key

* Adapt removeOrphanentries

* Adapt settings-wizard

* Improve api-is-down component

* Change  the way to display the helpers components

* Check APIs status when get them

* Remove console.log

* Check manager sets the status to the API entry

* Prevent create wazuh-registry.json without hosts

* FIx extensions

* Add panel

* Change style for wazuh hosts

* Show add api component from the table

* Refresh API entries

* Update wazuh-hosts

* Api is down table loading effect

* Show API is down when accessing to settings if any API is up

* Update cluster info in the settings wizard

* Change color

* Remove wazuh-hosts.yml

* Remove hosts from configuration

* Fix \n in the migration

* Fix api-count

* Fix typo

* Fix API wizard

* Fix example in getting started guide

* Fix typos

* Refresh hosts in api-is-down component

* Set default in props

* Fix API count

* Iterates the api entries to set one as default

* Fix component unmount

* Fix flick

* Fix when refresh and all entries and the yml is corrupt

* Improve handler error when getting error in the yml parser

* Adapt monitoring

* Allow unsigned certs

* Fix when there is not stored api - health check

* Fix when any api entry could be select

* Warning when set an API as default

* Send to settings when achieve connect with an API when trying set as default

* Try to set others API entries

* Preven duplicate hosts: in wazuh.yml

* Improve when stored api is not reachable handler

* Fix typo

* Added ID and the capability to search in the table

* Fix input style

* Fix typo

* Do pararell requests

* Fix when checking entry

* Add cheking spinner while checking api connection

* Spinner while checking in api-is-down component

* Use for instead of forEach

* Change spinner by message while refreshing entries

* Add a spinner by each entry while checking it

* Show the reason why wazuh is down

* Improve message from error 3099

* Add capability to copy to the clipboard the error
  • Loading branch information
adri9valle authored and juankaromo committed Oct 9, 2019
1 parent 15a0ef4 commit 5f34eff
Show file tree
Hide file tree
Showing 41 changed files with 1,904 additions and 1,620 deletions.
2 changes: 1 addition & 1 deletion .kibana-plugin-helpers.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"package.json",
"LICENSE",
"tsconfig.json",
"config.yml",
"wazuh.yml",
"index.js",
"init.js",
"server/**/*",
Expand Down
4 changes: 2 additions & 2 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// Imports all server modules
import { Initialize } from './server/initialize';
import { WazuhElasticRouter } from './server/routes/wazuh-elastic';
import { WazuhApiElasticRoutes } from './server/routes/wazuh-api-elastic';
import { Monitoring } from './server/monitoring';
import { WazuhApiRoutes } from './server/routes/wazuh-api';
import { WazuhHostsRoutes } from './server/routes/wazuh-hosts'
import { WazuhReportingRoutes } from './server/routes/wazuh-reporting';
import { WazuhUtilsRoutes } from './server/routes/wazuh-utils';
import { IndexPatternCronJob } from './server/index-pattern-cron-job';
Expand All @@ -37,11 +37,11 @@ export function initApp(server) {
);
Initialize(server);
WazuhElasticRouter(server);
WazuhApiElasticRoutes(server);
monitoringInstance.run();
indexPatternCronJobInstance.run();
Queue.launchCronJob();
WazuhApiRoutes(server);
WazuhHostsRoutes(server);
WazuhReportingRoutes(server);
WazuhUtilsRoutes(server);
})
Expand Down
12 changes: 4 additions & 8 deletions public/components/eui-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ import {
EuiButtonEmpty,
EuiHealth,
EuiCallOut,
EuiSwitch
EuiSwitch,
EuiSpacer
} from '@elastic/eui';

import { BasicTable } from '../directives/wz-table-eui/components/table';
import { Tabs } from '../directives/wz-tabs-eui/components/tabs';
import { Logtest } from '../directives/wz-logtest/components/logtest';
import { ToolsWelcomeCards } from '../controllers/dev-tools/components/tools-welcome-cards';
import { TestConfiguration } from '../controllers/dev-tools/components/test-configuration';

const app = uiModules.get('app/wazuh', ['react']);

Expand All @@ -46,7 +44,5 @@ app
.value('EuiCallOut', EuiCallOut)
.value('BasicTable', BasicTable)
.value('Tabs', Tabs)
.value('Logtest', Logtest)
.value('ToolsWelcomeCards', ToolsWelcomeCards)
.value('TestConfiguration', TestConfiguration)
.value('EuiSwitch', EuiSwitch);
.value('EuiSwitch', EuiSwitch)
.value('EuiSpacer',EuiSpacer);
15 changes: 9 additions & 6 deletions public/controllers/misc/health-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ export class HealthCheck {
*/
async checkApiConnection() {
try {
if (this.checks.api) {
const data = await this.testAPI.checkStored(
JSON.parse(this.appState.getCurrentAPI()).id
);
const currentApi = JSON.parse(this.appState.getCurrentAPI() || '{}');
if (this.checks.api && currentApi && currentApi.id) {
const data = await this.testAPI.checkStored(currentApi.id);

if (((data || {}).data || {}).idChanged) {
const apiRaw = JSON.parse(this.appState.getCurrentAPI());
Expand Down Expand Up @@ -204,7 +203,11 @@ export class HealthCheck {
this.$scope.$applyAsync();
return;
} catch (error) {
this.handleError(error);
if (error && error.data && error.data.code && error.data.code === 3002) {
return error;
} else {
this.handleError(error);
}
}
}

Expand All @@ -214,7 +217,7 @@ export class HealthCheck {
async load() {
try {
const configuration = this.wazuhConfig.getConfig();

this.appState.setPatternSelector(configuration['ip.selector']);

this.checks.pattern = configuration['checks.pattern'];
Expand Down
227 changes: 162 additions & 65 deletions public/controllers/settings/components/add-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,88 +15,185 @@ import PropTypes from 'prop-types';
import {
EuiFlexGroup,
EuiFlexItem,
EuiFormRow,
EuiFieldText,
EuiFieldPassword,
EuiFieldNumber,
EuiCodeBlock,
EuiText,
EuiSpacer,
EuiCode,
EuiButton,
EuiPanel
EuiButtonEmpty,
EuiSteps,
EuiCallOut
} from '@elastic/eui';

export class AddApi extends Component {
constructor(props) {
super(props);

this.state = {
user: '',
password: '',
url: '',
port: 55000
status: 'incomplete',
fetchingData: false,
blockClose: false
};
}

onChangeEdit(e, field) {
this.setState({
[field]: e.target.value
});

componentDidMount() {
this.setState({enableClose: this.props.enableClose});
this.checkErrorsAtInit();
}

/**
* Checks if the component was initialized with some error in order to show it
*/
checkErrorsAtInit() {
if (this.props.errorsAtInit) {
const error = this.props.errorsAtInit;
this.setState({
status: error.type || 'danger',
blockClose: true,
message: (error.data || error).message || 'Wazuh API not reachable, please review your configuration',
fetchingData: false
});
}
}

/**
* Check the APIs connections
*/
async checkConnection() {
//TODO handle this
try {
this.setState({
status: 'incomplete',
fetchingData: true,
blockClose: false,
});

await this.props.checkForNewApis();

this.setState({
status: 'complete',
fetchingData: false,
closedEnabled: true
});
} catch (error) {
const close = (error.data && error.data.code && error.data.code === 2001) ? false : (error.closedEnabled || false);
this.setState({
status: error.type || 'danger',
closedEnabled: close,
blockClose: !close,
enableClose: false,
message: (error.data || error).message || 'Wazuh API not reachable, please review your configuration',
fetchingData: false
});
}
}

render() {
return (
<EuiPanel>
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow label="Username">
<EuiFieldText
onChange={e => this.onChangeEdit(e, 'user')}
placeholder="foo"
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow label="Password">
<EuiFieldPassword
onChange={e => this.onChangeEdit(e, 'password')}
placeholder="bar"
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow label="Host">
<EuiFieldText
onChange={e => this.onChangeEdit(e, 'url')}
placeholder="http://localhost"
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow label="Port">
<EuiFieldNumber
max={99999}
onChange={e => this.onChangeEdit(e, 'port')}
placeholder={55000}
/>
</EuiFormRow>
</EuiFlexItem>
const apiExample = `hosts:
- <id>:
url: <api_url>
port: <api_port>
user: <api_user>
password: <api_password>`;

const checkConnectionChildren = (
<div>
{(this.state.status === 'warning' || this.state.status === 'danger') && (
<EuiCallOut
color={this.state.status}
iconType="help"
title={this.state.message}
/>
)}
{(this.state.status === 'warning' || this.state.status === 'danger') && <EuiSpacer />}
<EuiText>
Check that the Kibana server can reach the configured Wazuh API(s).
</EuiText>
<EuiSpacer />
<EuiButton
onClick={async () => await this.checkConnection()}
isLoading={this.state.fetchingData}
>
Check connection
</EuiButton>
{((this.state.closedEnabled || this.state.enableClose) && !this.state.blockClose) && (
<EuiButtonEmpty
onClick={() => this.props.closeAddApi()}
>
Close
</EuiButtonEmpty>
)}
</div>
);

<EuiFlexItem grow={false}>
<EuiFormRow label="Actions">
<EuiButton
aria-label="Save"
iconType="save"
color="primary"
onClick={() => this.props.saveSettings({ ...this.state })}
>
Save
</EuiButton>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
const editConfigChildren = (
<div>
<EuiText>
Modify <EuiCode>kibana/plugins/wazuh/wazuh.yml</EuiCode> to set the
connection information.
</EuiText>
<EuiSpacer />
<EuiCodeBlock language="yaml">{apiExample}</EuiCodeBlock>
<EuiSpacer />
<EuiText>
Where <EuiCode>{'<id>'}</EuiCode> is an arbitrary ID,{' '}
<EuiCode>{'<api_url>'}</EuiCode> is the URL of the Wazuh API,{' '}
<EuiCode>{'<api_port>'}</EuiCode> is the port,{' '}
<EuiCode>{'<api_user>'}</EuiCode> and{' '}
<EuiCode>{'<api_password>'}</EuiCode> are the credentials to
authenticate.
</EuiText>
</div>
);

const steps = [
{
title: 'Edit the configuration',
children: editConfigChildren
},
{
title: 'Test the configuration',
children: checkConnectionChildren,
status: this.state.status
}
];

const view = (
<EuiFlexGroup>
<EuiFlexItem />
<EuiFlexItem>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiText>
<h2>Getting started</h2>
</EuiText>
</EuiFlexItem>
<EuiFlexItem />
<EuiFlexItem grow={false}>
{(this.state.enableClose && !this.state.blockClose) && (
<EuiButtonEmpty
size="s"
onClick={() => this.props.closeAddApi()}
iconType="cross"
>
close
</EuiButtonEmpty>
)}
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer />
<EuiSteps firstStepNumber={1} steps={steps} />
</EuiFlexItem>
<EuiFlexItem />
</EuiFlexGroup>
);

return view;
}
}

AddApi.propTypes = {
saveSettings: PropTypes.func
checkForNewApis: PropTypes.func,
closeAddApi: PropTypes.func,
enableClose: PropTypes.bool
};
Loading

0 comments on commit 5f34eff

Please sign in to comment.