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

Adapt log collector socket configuration response controller component #6660

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -36,6 +36,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Remove some branding references across the application. [#6155](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6155)
- Move AngularJS controller for the agent view to ReactJS [#6618](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6618)
- Implement new data source feature on MITRE ATT&CK module [#6482](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6482)
- Changed agent log collector socket API response controller component [#6660](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6660)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"data": {
"target": [
"socket": [
{
"name": "custom_socket",
"location": "/var/run/custom.sock",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import React, { Component, Fragment } from 'react';
import WzNoConfig from '../util-components/no-config';
import WzConfigurationSettingsHeader from '../util-components/configuration-settings-header';
import WzConfigurationListSelector from '../util-components/configuration-settings-list-selector';
import { isString, isArray, renderValueOrDefault, renderValueOrNoValue } from '../utils/utils';
import {
isString,
isArray,
renderValueOrDefault,
renderValueOrNoValue,
} from '../utils/utils';
import { settingsListBuilder } from '../utils/builders';
import { LOGCOLLECTOR_SOCKET_PROP } from './types';
import { webDocumentationLink } from '../../../../../../../common/services/web_documentation';
Expand All @@ -24,7 +29,7 @@ const helpLinks = [
{
text: 'Using multiple outputs',
href: webDocumentationLink(
'user-manual/capabilities/log-data-collection/log-data-configuration.html#using-multiple-outputs'
'user-manual/capabilities/log-data-collection/log-data-configuration.html#using-multiple-outputs',
),
},
{
Expand Down Expand Up @@ -55,25 +60,39 @@ class WzConfigurationLogCollectionSockets extends Component {
render() {
const { currentConfig } = this.props;
const items = isArray(currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]?.target)
? settingsListBuilder(currentConfig[LOGCOLLECTOR_SOCKET_PROP].target, 'name')
? settingsListBuilder(
currentConfig[LOGCOLLECTOR_SOCKET_PROP].target,
'name',
)
: isArray(currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]?.socket)
? settingsListBuilder(
currentConfig[LOGCOLLECTOR_SOCKET_PROP].socket,
'name',
)
: [];
return (
<Fragment>
{isString(currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]) && (
<WzNoConfig error={currentConfig[LOGCOLLECTOR_SOCKET_PROP]} help={helpLinks} />
<WzNoConfig
error={currentConfig[LOGCOLLECTOR_SOCKET_PROP]}
help={helpLinks}
/>
)}
{!isString(currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]) &&
!currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]?.target?.length ? (
<WzNoConfig error="not-present" help={helpLinks} />
!items.length ? (
<WzNoConfig error='not-present' help={helpLinks} />
) : null}
{!isString(currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]) &&
currentConfig?.[LOGCOLLECTOR_SOCKET_PROP]?.target?.length ? (
items.length ? (
<WzConfigurationSettingsHeader
title="Output sockets"
description="Define custom outputs to send log data"
title='Output sockets'
description='Define custom outputs to send log data'
help={helpLinks}
>
<WzConfigurationListSelector items={items} settings={mainSettings} />
<WzConfigurationListSelector
items={items}
settings={mainSettings}
/>
</WzConfigurationSettingsHeader>
) : null}
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,17 @@ export const getCurrentConfig = async (
? partialResult.data.data.affected_items[0]
: {};
} else {
/*
* I need to check the amount of properties and use the first one in case there's only one
* because the /agents/{agent_id}/config/logcollector/socket response has property named "target" instead of "socket" in versions before Wazuh 4.9.0
* this allows to interprete any property name in the response
*/
const configKeys = Object.keys(partialResult.data.data);
const configPropertyName =
configKeys.length === 1 ? configKeys[0] : configuration;

result[`${component}-${configuration}`] = partialResult.data.data[
configuration
configPropertyName
]
? partialResult.data.data
: {};
Expand Down
Loading