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

Add filter for outdated agents #6529

Merged
merged 33 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dbfffb5
Add upgrade agents global action
lucianogorza Mar 11, 2024
23d9bba
Add Upgrade result modal
lucianogorza Mar 12, 2024
ada67c2
Update CHANGELOG
lucianogorza Mar 13, 2024
adbadbe
Minor fixes
lucianogorza Mar 13, 2024
1b13ab9
Add unit tests
lucianogorza Mar 13, 2024
07e822c
Improve upgrade progress message
lucianogorza Mar 13, 2024
5211603
Remove wazuh-endpoints plugin
lucianogorza Mar 13, 2024
8fcaa4f
Fix file name
lucianogorza Mar 13, 2024
562c16b
Fix import
lucianogorza Mar 13, 2024
9f505c9
Fix get tasks status for readonly user
lucianogorza Mar 14, 2024
6c40834
Improve return condition
lucianogorza Mar 14, 2024
b2f0275
Improve error message for Timeout status
lucianogorza Mar 14, 2024
10f17f3
Add tooltipo to timeout status
lucianogorza Mar 15, 2024
01e8307
Modularize get status functions
lucianogorza Mar 15, 2024
1afefd1
Fix status name and key values
lucianogorza Mar 15, 2024
e1ddf49
Separate upgrade service in two services
lucianogorza Mar 15, 2024
f46f0da
Add filter for outdated agents
lucianogorza Mar 18, 2024
e7ddd15
Update CHANGELOG
lucianogorza Mar 18, 2024
9902222
Update unit tests
lucianogorza Mar 18, 2024
0d8baf9
Update agents-table unit tests
lucianogorza Mar 18, 2024
bbbf582
Minor fixes
lucianogorza Mar 18, 2024
7399515
Fix unit test snapshot
lucianogorza Mar 18, 2024
21d7450
Change unknown with N/A for groups and os charts
lucianogorza Mar 18, 2024
85f91bc
Change unknown with N/A for groups and os charts
lucianogorza Mar 18, 2024
90c6e0f
Add tooltip when there are no selected agents
lucianogorza Mar 19, 2024
d133a65
Fix IDs field name
lucianogorza Mar 19, 2024
0613bac
Fix result paginations
lucianogorza Mar 19, 2024
3012807
Fix IDs labels
lucianogorza Mar 19, 2024
4fc0be0
Merge branch '4.9.0' into enhancement/6512-add-filter-for-outdated-ag…
lucianogorza Mar 19, 2024
8920072
Merge branch '4.9.0' into enhancement/6512-add-filter-for-outdated-ag…
asteriscos Mar 21, 2024
fc1ac7f
Fix agents table global actions
lucianogorza Mar 21, 2024
16662a4
Add tooltip to filter switch when there are no outdated agents
lucianogorza Mar 22, 2024
5be9aba
Implement WzButton instead EuiSwitch plus EuiToolTip
lucianogorza Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -10,7 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added AngularJS dependencies [#6145](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6145)
- Added a migration task to setup the configuration using a configuration file [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337)
- Added the ability to manage the API hosts from the Server APIs [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) [#6519](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6519)
- Added edit agent groups and upgrade agents actions to Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) [#6476](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6476) [#6274](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6274) [#6501](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6501)
- Improve fleet management by adding 'Edit Agent Groups' and 'Upgrade Agents' actions, as well as a filter to show only outdated agents [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) [#6476](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6476) [#6274](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6274) [#6501](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6501) [#6529](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6529)
- Added propagation of updates from the table to dashboard visualizations in Endpoints summary [#6460](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6460)
- Handle index pattern selector on new discover [#6499](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6499)

Expand Down
Expand Up @@ -141,7 +141,7 @@ exports[`Inventory component A Apple agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -544,7 +544,7 @@ exports[`Inventory component A Apple agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -897,7 +897,7 @@ exports[`Inventory component A Apple agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -1303,7 +1303,7 @@ exports[`Inventory component A Apple agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -1711,7 +1711,7 @@ exports[`Inventory component A Apple agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -2289,7 +2289,7 @@ exports[`Inventory component A Linux agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -2691,7 +2691,7 @@ exports[`Inventory component A Linux agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -3075,7 +3075,7 @@ exports[`Inventory component A Linux agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -3480,7 +3480,7 @@ exports[`Inventory component A Linux agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -3888,7 +3888,7 @@ exports[`Inventory component A Linux agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -4587,7 +4587,7 @@ exports[`Inventory component A Windows agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -4990,7 +4990,7 @@ exports[`Inventory component A Windows agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -5367,7 +5367,7 @@ exports[`Inventory component A Windows agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -5770,7 +5770,7 @@ exports[`Inventory component A Windows agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -6080,7 +6080,7 @@ exports[`Inventory component A Windows agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down Expand Up @@ -6464,7 +6464,7 @@ exports[`Inventory component A Windows agent should be well rendered. 1`] = `
class="euiFlexItem"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero wz-flex-basis-auto"
Expand Down
Expand Up @@ -62,9 +62,10 @@ exports[`Table WZ API component renders correctly to match the snapshot 1`] = `
<EuiFlexGroup
alignItems="center"
responsive={false}
wrap={true}
>
<div
className="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow"
className="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--wrap"
>
<EuiFlexItem
className="wz-flex-basis-auto"
Expand Down
Expand Up @@ -197,7 +197,7 @@ export function TableWzAPI({
<>
<EuiFlexGroup wrap alignItems='center' responsive={false}>
<EuiFlexItem>
<EuiFlexGroup alignItems='center' responsive={false}>
<EuiFlexGroup wrap alignItems='center' responsive={false}>
<EuiFlexItem className='wz-flex-basis-auto' grow={false}>
{rest.title && (
<EuiTitle size='s'>
Expand Down
Expand Up @@ -18,102 +18,102 @@ describe('OutdatedAgentsCard', () => {
wrapper.update();
});
};

const mockLoading = false;
const mockDataNoOutdatedAgents = [];
const useServiceMockNoOutdatedAgent = jest.fn(() => ({data: mockDataNoOutdatedAgents, isLoading: mockLoading}));
const mockDataOutdatedAgents = [
{
version: "Wazuh v3.0.0",
id: "003",
name: "main_database"
},
{
version: "Wazuh v3.0.0",
id: "004",
name: "dmz002"
}
];
const useServiceMockOutdatedAgent = jest.fn(() => ({data: mockDataOutdatedAgents, isLoading: mockLoading}));

const handleClick = jest.fn();
const filterByOutdatedAgent = jest.fn();

it('renders with not outdated agents', async () => {
require('../../../common/hooks/use-service').useService = useServiceMockNoOutdatedAgent;

await act(async () => {
const { getByTestId } = render(
<OutdatedAgentsCard onClick={handleClick} />
<OutdatedAgentsCard
isLoading={false}
outdatedAgents={0}
filterByOutdatedAgent={filterByOutdatedAgent}
/>,
);

const outdatedAgentsNumberElement = getByTestId('wazuh-endpoints-summary-outdated-agents-number')
expect(outdatedAgentsNumberElement).toHaveClass('euiTextColor euiTextColor--success');
expect(outdatedAgentsNumberElement.textContent).toBe(`${mockDataNoOutdatedAgents.length}`);
const outdatedAgentsNumberElement = getByTestId(
'wazuh-endpoints-summary-outdated-agents-number',
);
expect(outdatedAgentsNumberElement).toHaveClass(
'euiTextColor euiTextColor--success',
);
expect(outdatedAgentsNumberElement.textContent).toBe('0');
});
});

it('renders with outdated agents', async () => {
require('../../../common/hooks/use-service').useService = useServiceMockOutdatedAgent;

await act(async () => {
const { getByTestId } = render(
<OutdatedAgentsCard onClick={handleClick} />
<OutdatedAgentsCard
isLoading={false}
outdatedAgents={2}
filterByOutdatedAgent={filterByOutdatedAgent}
/>,
);

const outdatedAgentsNumberElement = getByTestId('wazuh-endpoints-summary-outdated-agents-number')
expect(outdatedAgentsNumberElement).toHaveClass('euiTextColor euiTextColor--warning');
expect(outdatedAgentsNumberElement.textContent).toBe(`${mockDataOutdatedAgents.length}`);
const outdatedAgentsNumberElement = getByTestId(
'wazuh-endpoints-summary-outdated-agents-number',
);
expect(outdatedAgentsNumberElement).toHaveClass(
'euiTextColor euiTextColor--warning',
);
expect(outdatedAgentsNumberElement.textContent).toBe('2');
});
});

it('renders popover on click with outdated agents', async () => {
require('../../../common/hooks/use-service').useService = useServiceMockOutdatedAgent;

const wrapper = await mount(
<OutdatedAgentsCard onClick={handleClick} />,
<OutdatedAgentsCard
isLoading={false}
outdatedAgents={2}
filterByOutdatedAgent={filterByOutdatedAgent}
/>,
);

await awaitForMyComponent(wrapper);

expect(wrapper.find('.wazuh-outdated-agents-panel').exists()).toBeTruthy();
expect(wrapper.find(EuiButtonEmpty).exists()).not.toBeTruthy();

wrapper.find('.wazuh-outdated-agents-panel').simulate('click');
expect(wrapper.find(EuiButtonEmpty).exists()).toBeTruthy();
});

it('handles click with correct data', async () => {
require('../../../common/hooks/use-service').useService = useServiceMockOutdatedAgent;

const wrapper = await mount(
<OutdatedAgentsCard onClick={handleClick} />,
<OutdatedAgentsCard
isLoading={false}
outdatedAgents={2}
filterByOutdatedAgent={filterByOutdatedAgent}
/>,
);

await awaitForMyComponent(wrapper);

expect(wrapper.find('.wazuh-outdated-agents-panel').exists()).toBeTruthy();
expect(wrapper.find(EuiButtonEmpty).exists()).not.toBeTruthy();

wrapper.find('.wazuh-outdated-agents-panel').simulate('click');
expect(wrapper.find(EuiButtonEmpty).exists()).toBeTruthy();

wrapper.find(EuiButtonEmpty).simulate('click');
expect(handleClick).toHaveBeenCalledTimes(1);
expect(handleClick).toHaveBeenCalledWith(mockDataOutdatedAgents);
expect(filterByOutdatedAgent).toHaveBeenCalledTimes(1);
expect(filterByOutdatedAgent).toHaveBeenCalledWith(true);
});

it('EuiButtonEmpty filter must be disabled when no data', async () => {
require('../../../common/hooks/use-service').useService = useServiceMockNoOutdatedAgent;

const wrapper = await mount(
<OutdatedAgentsCard onClick={handleClick} />,
<OutdatedAgentsCard
isLoading={false}
outdatedAgents={0}
filterByOutdatedAgent={filterByOutdatedAgent}
/>,
);

await awaitForMyComponent(wrapper);

expect(wrapper.find('.wazuh-outdated-agents-panel').exists()).toBeTruthy();
expect(wrapper.find(EuiButtonEmpty).exists()).not.toBeTruthy();

wrapper.find('.wazuh-outdated-agents-panel').simulate('click');
expect(wrapper.find(EuiButtonEmpty).exists()).toBeTruthy();
expect(wrapper.find(EuiButtonEmpty).prop('isDisabled')).toBe(true);
Expand All @@ -123,20 +123,21 @@ describe('OutdatedAgentsCard', () => {
const documentationLink = webDocumentationLink(
'upgrade-guide/wazuh-agent/index.html',
);
require('../../../common/hooks/use-service').useService = useServiceMockNoOutdatedAgent;

const wrapper = await mount(
<OutdatedAgentsCard onClick={handleClick} />,
<OutdatedAgentsCard
isLoading={false}
outdatedAgents={0}
filterByOutdatedAgent={filterByOutdatedAgent}
/>,
);

await awaitForMyComponent(wrapper);

expect(wrapper.find('.wazuh-outdated-agents-panel').exists()).toBeTruthy();
expect(wrapper.find(EuiButtonEmpty).exists()).not.toBeTruthy();

wrapper.find('.wazuh-outdated-agents-panel').simulate('click');
expect(wrapper.find(EuiLink).exists()).toBeTruthy();
expect(wrapper.find(EuiLink).prop('href')).toBe(documentationLink);
});

});