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

Added server address and wazuh protocol definition in Deploy agent section #5166

Merged
merged 9 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added file saving conditions in File Editor [#4970](https:/wazuh/wazuh-kibana-app/pull/4970)
- Added character validation to avoid invalid agent names in the section 'Deploy new agent'. [#5021](https:/wazuh/wazuh-kibana-app/pull/5021) [#5028](https:/wazuh/wazuh-kibana-app/pull/5028)
- Added default selected options in Deploy Agent page [#5063](https:/wazuh/wazuh-kibana-app/pull/5063)
- Added new Server Address component [#5166](https:/wazuh/wazuh-kibana-app/pull/5166)
Machi3mfl marked this conversation as resolved.
Show resolved Hide resolved

### Changed

Expand Down
12 changes: 12 additions & 0 deletions public/controllers/agent/components/register-agent-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,16 @@ export const getMasterNode = (
return nodeIps.filter(nodeIp => nodeIp.nodetype === 'master');
};

/**
* Get the remote configuration from manager
* This function get the config from manager mode or cluster mode
*/
export const getMasterRemoteConfiguration = async () => {
const nodes = await fetchClusterNodesOptions();
const masterNode = getMasterNode(nodes);
return await getRemoteConfiguration(masterNode[0].label);
}



export { getConnectionConfig, getRemoteConfiguration };
92 changes: 55 additions & 37 deletions public/controllers/agent/components/register-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ import {
versionButtonAlpine,
architectureButtonsWithPPC64LEAlpine,
} from '../wazuh-config';
import ServerAddress from '../register-agent/steps/server-address';
import WzManagerAddressInput from '../register-agent/steps/wz-manager-address';
import {
getConnectionConfig,
fetchClusterNodesOptions,
getMasterRemoteConfiguration
} from './register-agent-service';
import { PrincipalButtonGroup } from './wz-accordion';
import RegisterAgentButtonGroup from '../register-agent/register-agent-button-group';
Expand Down Expand Up @@ -121,13 +120,15 @@ export const RegisterAgent = withErrorBoundary(
};
}


async componentDidMount() {
try {
this.setState({ loading: true });
const wazuhVersion = await this.props.getWazuhVersion();
let wazuhPassword = '';
let hidePasswordInput = false;
this.getEnrollDNSConfig();
await this.getRemoteConfig();
let authInfo = await this.getAuthInfo();
const needsPassword = (authInfo.auth || {}).use_password === 'yes';
if (needsPassword) {
Expand Down Expand Up @@ -193,14 +194,27 @@ export const RegisterAgent = withErrorBoundary(
}

getEnrollDNSConfig = () => {
let serverAddress = this.configuration['enrollment.dns'] || '';
const serverAddress = this.configuration['enrollment.dns'] || '';
this.setState({ defaultServerAddress: serverAddress });
};

getRemoteConfig = async () => {
const remoteConfig = await getMasterRemoteConfiguration();
const serverAddress = this.defaultServerAddress || this.configuration['enrollment.dns'] || '';
if (serverAddress) {
this.setState({ udpProtocol: true });
} else {
this.setState({ udpProtocol: false });
this.setState({
udpProtocol: false,
connectionSecure: true,
serverAddress });
}else{
this.setState({
haveUdpProtocol: remoteConfig.isUdp,
udpProtocol: remoteConfig.isUdp,
connectionSecure: remoteConfig.isSecure,
})
}
};
}


async getAuthInfo() {
try {
Expand Down Expand Up @@ -375,7 +389,6 @@ export const RegisterAgent = withErrorBoundary(
let deployment =
this.state.serverAddress &&
`WAZUH_MANAGER='${this.state.serverAddress}' `;
const protocol = false;
if (this.state.selectedOS == 'win') {
deployment += `WAZUH_REGISTRATION_SERVER='${this.state.serverAddress}' `;
}
Expand Down Expand Up @@ -1651,41 +1664,47 @@ apk add wazuh-agent=${this.state.wazuhVersion}-r1`,
},
];

const onChangeServerAddress = async selectedNodes => {
if (selectedNodes.length === 0) {
const onChangeServerAddress = async nodeSelected => {
if (!nodeSelected) {
this.setState({
serverAddress: '',
udpProtocol: false,
connectionSecure: null,
});
} else {
const nodeSelected = selectedNodes[0];
try {
const remoteConfig = await getConnectionConfig(nodeSelected);
this.setState({
serverAddress: remoteConfig.serverAddress,
udpProtocol: remoteConfig.udpProtocol,
connectionSecure: remoteConfig.connectionSecure,
});
} catch (error) {
const options = {
context: `${RegisterAgent.name}.onChangeServerAddress`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
display: true,
store: false,
error: {
error: error,
message: error.message || error,
title: error.name || error,
},
};
getErrorOrchestrator().handleError(options);
if (nodeSelected === this.state.defaultServerAddress) {
this.setState({
serverAddress: nodeSelected.label,
serverAddress: nodeSelected,
udpProtocol: false,
connectionSecure: false,
connectionSecure: true,
});
} else {
try {
this.setState({
serverAddress: nodeSelected,
udpProtocol: this.state.haveUdpProtocol,
connectionSecure: this.state.haveUdpProtocol ? false : true
});
} catch (error) {
const options = {
context: `${RegisterAgent.name}.onChangeServerAddress`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
display: true,
store: false,
error: {
error: error,
message: error.message || error,
title: error.name || error,
},
};
getErrorOrchestrator().handleError(options);
this.setState({
serverAddress: nodeSelected,
udpProtocol: false,
connectionSecure: false,
});
}
}
}
};
Expand Down Expand Up @@ -2142,10 +2161,9 @@ apk add wazuh-agent=${this.state.wazuhVersion}-r1`,
title: 'Wazuh server address',
children: (
<Fragment>
<ServerAddress
<WzManagerAddressInput
defaultValue={this.state.defaultServerAddress}
onChange={onChangeServerAddress}
fetchOptions={fetchClusterNodesOptions}
/>
</Fragment>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { memo, useCallback, useEffect, useState } from 'react';
import { EuiText, EuiFieldText } from '@elastic/eui';

type Props = {
onChange: (value: string) => void;
defaultValue?: string;
};

const WzManagerAddressInput = (props: Props) => {
const { onChange, defaultValue } = props;
const [value, setValue] = useState('');

useEffect(() => {
if(defaultValue){
setValue(defaultValue);
onChange(defaultValue);
}else{
setValue('');
onChange('');
}
},[])
/**
* Handles the change of the selected node IP
* @param value
*/
const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;
onChange(value);
setValue(value);
};
return (
<EuiText>
<p>
This is the address the agent uses to communicate with the Wazuh server.
It can be an IP address or a fully qualified domain name (FQDN).
</p>
<EuiFieldText
placeholder='Server Address'
onChange={handleOnChange}
value={value}
/>
</EuiText>
);
};

export default memo(WzManagerAddressInput);
Machi3mfl marked this conversation as resolved.
Show resolved Hide resolved