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

Checking the internal tab when changing agent on FIM > Inventory > Windows registry #6880

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 @@ -58,6 +58,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed styles in small height viewports [#6747](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6747)
- Fixed behavior in Configuration Assessment when changing API [#6770](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6770)
- Fixed the fixed maximum width of the clear session button in the ruleset test view [#6871](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6871)
- Fixed redirection to FIM > Inventory > Files from FIM > Inventory > Windows Registry when switching to non-Windows agent. [#6880](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6880)

### Removed

Expand Down
192 changes: 119 additions & 73 deletions plugins/main/public/components/agents/fim/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
EuiSpacer,
EuiTab,
EuiTabs,
EuiTitle,
} from '@elastic/eui';
import { InventoryTable, RegistryTable } from './inventory/';
import { WzRequest } from '../../../react-services/wz-request';
Expand Down Expand Up @@ -65,8 +64,8 @@ export class Inventory extends Component {
totalItemsRegistry: 0,
isLoading: true,
customBadges: [],
isConfigured: false
}
isConfigured: false,
};
this.onFiltersChange.bind(this);
}

Expand All @@ -76,8 +75,15 @@ export class Inventory extends Component {
}

componentDidUpdate(prevProps) {
if (JSON.stringify(this.props.agent) !== JSON.stringify(prevProps.agent)){
this.setState({isLoading: true}, this.loadAgent)
if (JSON.stringify(this.props.agent) !== JSON.stringify(prevProps.agent)) {
if (this.props?.agent?.os?.platform !== 'windows') {
this.setState(
{ isLoading: true, selectedTabId: 'files' },
this.loadAgent,
);
return;
}
this.setState({ isLoading: true }, this.loadAgent);
}
}

Expand All @@ -86,73 +92,90 @@ export class Inventory extends Component {
}

async loadAgent() {
const agentPlatform = ((this.props.agent || {}).os || {}).platform;
const {totalItemsFile, syscheck} = await this.getItemNumber('file');
const totalItemsRegistry = agentPlatform === 'windows' ? await this.getItemNumber('registry') : 0;
const agentPlatform = this.props.agent?.os?.platform;
const { totalItemsFile, syscheck } = await this.getItemNumber('file');
const totalItemsRegistry =
agentPlatform === 'windows' ? await this.getItemNumber('registry') : 0;
const isConfigured = await this.isConfigured();
if (this._isMount){
this.setState({ totalItemsFile, totalItemsRegistry, syscheck, isLoading: false, isConfigured });
if (this._isMount) {
this.setState({
totalItemsFile,
totalItemsRegistry,
syscheck,
isLoading: false,
isConfigured,
});
}
}

// Do not load the localStorage filters when changing tabs
// componentDidUpdate(prevProps, prevState) {
// const { selectedTabId } = this.state;
// if (selectedTabId !== prevState.selectedTabId) {
// const filters = this.getStoreFilters(this.props);
// this.setState({ filters });
// }
// }

tabs() {
let auxTabs = [
const auxTabs = [
{
id: 'files',
name: `Files ${this.state.isLoading === true ? '' : '(' + this.state.totalItemsFile + ')'}`,
disabled: false,
},
]
const platform = (this.props.agent.os || {}).platform || "other";
platform === 'windows' ? auxTabs.push(
{
id: 'registry',
name: `Windows Registry ${this.state.isLoading === true ? '' : '(' + this.state.totalItemsRegistry + ')'}`,
name: `Files ${
this.state.isLoading === true
? ''
: '(' + this.state.totalItemsFile + ')'
}`,
disabled: false,
},
) : null;
return (auxTabs);
];
const registryTab = {
id: 'registry',
name: `Windows Registry ${
this.state.isLoading === true
? ''
: '(' + this.state.totalItemsRegistry + ')'
}`,
disabled: false,
};

const platform = this.props.agent.os?.platform || 'other';
platform === 'windows' ? auxTabs.push(registryTab) : null;
return auxTabs;
}

getStoreFilters(props) {
const { section, selectView, agent } = props;
const filters = JSON.parse(window.localStorage.getItem(`wazuh-${section}-${selectView}-${((this.state || {}).selectedTabId || 'files')}-${agent['id']}`) || '{}');
const filters = JSON.parse(
window.localStorage.getItem(
`wazuh-${section}-${selectView}-${
this.state?.selectedTabId || 'files'
}-${agent['id']}`,
) || '{}',
);
return filters;
}

setStoreFilters(filters) {
const { section, selectView, agent } = this.props;
window.localStorage.setItem(`wazuh-${section}-${selectView}-${(this.state || {}).selectedTabId || 'files'}-${agent['id']}`, JSON.stringify(filters))
window.localStorage.setItem(
`wazuh-${section}-${selectView}-${this.state?.selectedTabId || 'files'}-${
agent['id']
}`,
JSON.stringify(filters),
);
}

onFiltersChange = (filters) => {
onFiltersChange = filters => {
this.setState({ filters });
}
};

onTotalItemsChange = (totalItems: number) => {
this.setState({ totalItemsFile: totalItems });
}
};

onSelectedTabChanged = id => {
this.setState({ selectedTabId: id });
}
};

buildFilter(type) {
const filters = filtersToObject(this.state.filters);
const filter = {
...filters,
limit: type === 'file' ? '15' : '1',
...(type === 'registry' ? {q: 'type=registry_key'} : {type}),
...(type === 'file' && {sort: '+file'})
...(type === 'registry' ? { q: 'type=registry_key' } : { type }),
...(type === 'file' && { sort: '+file' }),
};
return filter;
}
Expand All @@ -165,11 +188,11 @@ export class Inventory extends Component {
});
if (type === 'file') {
return {
totalItemsFile: ((response.data || {}).data || {}).total_affected_items || 0,
syscheck: ((response.data || {}).data || {}).affected_items || [],
totalItemsFile: response.data?.data?.total_affected_items || 0,
syscheck: response.data?.data?.affected_items || [],
};
}
return ((response.data || {}).data || {}).total_affected_items || 0;
return response.data?.data?.total_affected_items || 0;
} catch (error) {
this.setState({ isLoading: false });

Expand Down Expand Up @@ -198,13 +221,15 @@ export class Inventory extends Component {
onClick={() => this.onSelectedTabChanged(tab.id)}
isSelected={tab.id === this.state.selectedTabId}
disabled={tab.disabled}
key={index}>
{tab.name}&nbsp;{isLoading === true && <EuiLoadingSpinner size="s" />}
key={index}
>
{tab.name}&nbsp;
{isLoading === true && <EuiLoadingSpinner size='s' />}
</EuiTab>
))}
</EuiTabs>
);
};
}
return null;
}

Expand All @@ -217,67 +242,80 @@ export class Inventory extends Component {
};

renderTable() {
const { filters, syscheck, selectedTabId, customBadges, totalItemsRegistry, totalItemsFile } = this.state;
const {
filters,
syscheck,
selectedTabId,
totalItemsRegistry,
totalItemsFile,
} = this.state;
return (
<>
{selectedTabId === 'files' &&
{selectedTabId === 'files' && (
<InventoryTable
{...this.props}
filters={filters}
items={syscheck}
totalItems={totalItemsFile}
onFiltersChange={this.onFiltersChange}
onTotalItemsChange={this.onTotalItemsChange}/>
}
{selectedTabId === 'registry' &&
onTotalItemsChange={this.onTotalItemsChange}
/>
)}
{selectedTabId === 'registry' && (
<RegistryTable
{...this.props}
filters={filters}
totalItems={totalItemsRegistry}
onFiltersChange={this.onFiltersChange} />
}
onFiltersChange={this.onFiltersChange}
/>
)}
</>
);
}

noConfiguredMonitoring() {
return (
<EuiEmptyPrompt
iconType="filebeatApp"
iconType='filebeatApp'
title={<h2>Integrity monitoring is not configured for this agent</h2>}
body={
<EuiLink
href={webDocumentationLink('user-manual/capabilities/file-integrity/index.html')}
target="_blank"
href={webDocumentationLink(
'user-manual/capabilities/file-integrity/index.html',
)}
target='_blank'
external
style={{ textAlign: "center" }}
rel="noopener noreferrer"
style={{ textAlign: 'center' }}
rel='noopener noreferrer'
>
How to configure the module
</EuiLink>
}
/>);
/>
);
}

loadingInventory() {
return <EuiPage>
<EuiFlexGroup>
<EuiFlexItem>
<EuiProgress size="xs" color="primary" />
</EuiFlexItem>
</EuiFlexGroup>
</EuiPage>;
return (
<EuiPage>
<EuiFlexGroup>
<EuiFlexItem>
<EuiProgress size='xs' color='primary' />
</EuiFlexItem>
</EuiFlexGroup>
</EuiPage>
);
}

async isConfigured() {
try {
const response = await WzRequest.apiReq(
'GET',
`/agents/${this.props.agent.id}/config/syscheck/syscheck`,
{}
{},
);

return (((response.data || {}).data).syscheck || {}).disabled === 'no';
return response.data?.data?.syscheck?.disabled === 'no';
} catch (error) {
const options: UIErrorLog = {
context: `${Inventory.name}.isConfigured`,
Expand All @@ -297,19 +335,27 @@ export class Inventory extends Component {
render() {
const { isLoading, isConfigured } = this.state;
if (isLoading) {
return this.loadingInventory()
return this.loadingInventory();
}
const table = this.renderTable();
const tabs = this.renderTabs();

return isConfigured
? (<EuiPage>
return isConfigured ? (
<EuiPage>
<EuiPanel>
{tabs}
<EuiSpacer size={(((this.props.agent || {}).os || {}).platform || false) === 'windows' ? 's' : 'm'} />
<EuiSpacer
size={
(this.props.agent?.os?.platform || false) === 'windows'
? 's'
: 'm'
}
/>
{table}
</EuiPanel>
</EuiPage>)
: this.noConfiguredMonitoring()
</EuiPage>
) : (
this.noConfiguredMonitoring()
);
}
}
Loading