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

Refactoring and redesign endpoints summary charts #6268

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5e6790e
Refactor the agent by status and develop other charts
jbiset Jan 3, 2024
d12282b
Update outdated agents card
jbiset Jan 4, 2024
c23ee4f
Merge branch 'master' into enhancement/6258-refactor-and-redesign-end…
jbiset Jan 4, 2024
a9969e6
Add dynamic colors to graphics and responsive layout
jbiset Jan 8, 2024
a77d62a
Fix responsive layout
jbiset Jan 9, 2024
6c8d90b
Change outdated agents panel max size
jbiset Jan 9, 2024
e44a942
Change agent_distinct imposter endpoint and fix getAgentsByOS service
jbiset Jan 11, 2024
bf3c945
Merge branch '4.9.0' into enhancement/6258-refactor-and-redesign-endp…
jbiset Feb 21, 2024
9de564f
Changed agent-by-group and agent-by-OS endpoints to filter agent 000.
jbiset Feb 21, 2024
9e0a031
The getAgentsByGroup and getAgentsByOs methods are improved. Unit tes…
jbiset Feb 21, 2024
e097730
fix query when filtering by group and when filtering by outdated agents
jbiset Feb 22, 2024
86b05b4
Disabled filter outdated agent when no data and add donut-card test
jbiset Feb 22, 2024
35613f0
Finished donut-card tests and added outdated-agents-card tests
jbiset Feb 23, 2024
f00a03a
Adjusted visual styles of chart-legend and outdated-agents-card popover
jbiset Feb 23, 2024
251ba1e
Merge branch '4.9.0' into enhancement/6258-refactor-and-redesign-endp…
jbiset Feb 23, 2024
99177e7
Add CHANGELOG
jbiset Feb 23, 2024
a4ff85c
Fix responsive visualizations
jbiset Feb 26, 2024
326f778
Changed the services of obtaining agents by group and agents by OS. A…
jbiset Feb 26, 2024
f5dad7a
Fix chart legend on tablet-desktop breakpoint
jbiset Feb 26, 2024
08436ff
Change width chart legent to desktop breakpoint
jbiset Feb 26, 2024
73a99cf
Fix get-agents-by-group test
jbiset Feb 26, 2024
25b17b6
Updated get-agents-by-os to get top 5 agents by OS
jbiset Feb 26, 2024
f46bdc9
Merge branch '4.9.0' into enhancement/6258-refactor-and-redesign-endp…
jbiset Feb 28, 2024
52a929c
Fixed CSS for both the outdated-agents-card popover and the donut legend
jbiset Feb 28, 2024
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 @@ -16,6 +16,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Removed embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) [#6235](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6235) [#6254](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6254) [#6285](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6285) [#6288](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6288) [#6290](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6290) [#6289](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6289) [#6286](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6286) [#6275](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6275) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6297](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6297) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6291](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287)
- Develop logic of a new index for the fim module [#6227](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6227)
- Allow editing groups for an agent from Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250)
- Refactoring and redesign endpoints summary visualizations [#6268](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6268)

### Fixed

Expand Down
361 changes: 314 additions & 47 deletions docker/imposter/agents/agent_distinct.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,323 @@
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';

if (search instanceof RegExp) {
throw TypeError('first argument must not be a RegExp');
}
if (start === undefined) { start = 0; }
return this.indexOf(search, start) !== -1;
};
}
String.prototype.includes = function (search, start) {
'use strict';

function generateResponse(items, field, search){
return {
data: {
affected_items: items.filter(function(item){
return search ? item.includes(search) : true;
}).map(function(item){
var obj = {};
obj[field] = item
return obj;
}),
total_affected_items: 5,
total_failed_items: 0,
failed_items: []
},
message: "All selected agents information was returned",
error: 0
if (search instanceof RegExp) {
throw TypeError('first argument must not be a RegExp');
}
if (start === undefined) {
start = 0;
}
return this.indexOf(search, start) !== -1;
};
}

var fields = context.request.queryParams.fields;

/* Based on agents.json */
var originalResponse = {
data: {
affected_items: [
{
os: {
arch: 'x86_64',
major: '2',
name: 'Amazon Linux',
platform: 'amzn',
uname:
'Linux |wazuh-manager-master-0 |4.14.114-105.126.amzn2.x86_64 |#1 SMP Tue May 7 02:26:40 UTC 2019 |x86_64',
version: '2',
},
group: [
'default',
'test',
'test2',
'test3',
'test4',
'test5',
'test6',
'test7',
'test8',
'test9',
'test10',
],
ip: 'FE80:0034:0223:A000:0002:B3FF:0000:8329',
id: '000',
registerIP: 'FE80:0034:0223:A000:0002:B3FF:0000:8329',
dateAdd: '2022-08-25T16:17:46Z',
name: 'wazuh-manager-master-0',
status: 'active',
manager: 'wazuh-manager-master-0',
node_name: 'master',
lastKeepAlive: '9999-12-31T23:59:59Z',
version: 'Wazuh v4.4.0',
group_config_status: 'synced',
status_code: 0,
count: 1,
},
{
os: {
arch: 'x86_64',
major: '2',
name: 'Amazon Linux',
platform: 'amzn',
uname:
'Linux |wazuh-manager-master-0 |4.14.114-105.126.amzn2.x86_64 |#1 SMP Tue May 7 02:26:40 UTC 2019 |x86_64',
version: '2',
},
group: ['default', 'test', 'test2', 'test3', 'test4', 'test5'],
ip: 'FE80:1234:2223:A000:2202:B3FF:FE1E:8329',
id: '001',
registerIP: 'FE80:1234:2223:A000:2202:B3FF:FE1E:8329',
dateAdd: '2022-08-25T16:17:46Z',
name: 'wazuh-manager-master-0',
status: 'active',
manager: 'wazuh-manager-master-0',
node_name: 'master',
lastKeepAlive: '9999-12-31T23:59:59Z',
version: 'Wazuh v4.4.0',
group_config_status: 'not synced',
status_code: 0,
count: 1,
},
{
os: {
arch: 'x86_64',
major: '2',
name: 'Amazon Linux',
platform: 'amzn',
uname:
'Linux |wazuh-manager-master-0 |4.14.114-105.126.amzn2.x86_64 |#1 SMP Tue May 7 02:26:40 UTC 2019 |x86_64',
version: '2',
},
group: ['default', 'test', 'test2'],
ip: '127.0.0.1',
id: '002',
registerIP: '127.0.0.1',
dateAdd: '2022-08-25T16:17:46Z',
name: 'wazuh-manager-master-0',
status: 'active',
manager: 'wazuh-manager-master-0',
node_name: 'master',
lastKeepAlive: '9999-12-31T23:59:59Z',
version: 'Wazuh v4.5.0',
group_config_status: 'synced',
status_code: 0,
count: 1,
},
{
os: {
build: '19045',
major: '10',
minor: '0',
name: 'Microsoft Windows 10 Home Single Language',
platform: 'windows',
uname: 'Microsoft Windows 10 Home Single Language',
version: '10.0.19045',
},
disconnection_time: '2023-03-14T04:37:42Z',
manager: 'test.com',
status: 'disconnected',
name: 'disconnected-agent',
dateAdd: '1970-01-01T00:00:00Z',
group: ['default', 'test'],
lastKeepAlive: '2023-03-14T04:20:51Z',
node_name: 'node01',
registerIP: 'any',
id: '003',
version: 'Wazuh v4.3.10',
ip: '111.111.1.111',
mergedSum: 'e669d89eba52f6897060fc65a45300ac',
configSum: '97fccbb67e250b7c80aadc8d0dc59abe',
group_config_status: 'not synced',
status_code: 1,
count: 1,
},
{
status: 'never_connected',
name: 'never_connected_agent',
dateAdd: '2023-03-14T09:44:11Z',
node_name: 'unknown',
registerIP: 'any',
id: '004',
ip: 'any',
group_config_status: 'not synced',
status_code: 4,
count: 1,
},
{
os: {
arch: 'x86_64',
major: '2',
name: 'macOS High Sierra',
platform: 'darwin',
uname:
'macOS High Sierra |wazuh-manager-master-0 |4.14.114-105.126.amzn2.x86_64 |#1 SMP Tue May 7 02:26:40 UTC 2019 |x86_64',
version: '2',
},
ip: '127.0.0.1',
id: '005',
group: ['default'],
registerIP: '127.0.0.1',
dateAdd: '2022-08-25T16:17:46Z',
name: 'macOS High Sierra agent',
status: 'disconnected',
manager: 'wazuh-manager-master-0',
node_name: 'master',
lastKeepAlive: '9999-12-31T23:59:59Z',
version: 'Wazuh v4.5.0',
group_config_status: 'synced',
status_code: 2,
count: 1,
},
{
os: {
name: 'Ubuntu',
platform: 'ubuntu',
uname:
'Linux |f288f4c59dbc |5.19.0-35-generic |#36~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 17 15:17:25 UTC 2 |x86_64',
version: '18.04.6 LTS',
},
group_config_status: 'not synced',
status_code: 0,
ip: '172.19.0.27',
status: 'pending',
name: 'Pending agent',
group: ['default'],
node_name: 'master-node',
version: 'Wazuh v4.4.0',
lastKeepAlive: '2023-03-16T15:15:05+00:00',
id: '006',
dateAdd: '2023-03-16T15:14:47+00:00',
count: 1,
},
{
status: 'never_connected',
name: 'never_connected_agent-2',
dateAdd: '2023-03-14T09:44:11Z',
node_name: 'unknown',
registerIP: 'any',
id: '007',
ip: 'any',
group_config_status: 'not synced',
status_code: 5,
count: 1,
},
{
status: 'never_connected',
name: 'never_connected_agent-3',
dateAdd: '2023-03-14T09:44:11Z',
node_name: 'unknown',
registerIP: 'any',
id: '008',
ip: 'any',
group_config_status: 'not synced',
status_code: 1,
count: 1,
},
{
status: 'never_connected',
name: 'never_connected_agent-4',
dateAdd: '2023-03-14T09:44:11Z',
node_name: 'unknown',
registerIP: 'any',
id: '009',
ip: 'any',
group_config_status: 'not synced',
status_code: 2,
count: 1,
},
{
os: {
build: '19045',
major: '10',
minor: '0',
name: 'Microsoft Windows 10 Home Single Language',
platform: 'windows',
uname: 'Microsoft Windows 10 Home Single Language',
version: '10.0.19045',
},
disconnection_time: '2023-03-14T04:37:42Z',
manager: 'test.com',
status: 'disconnected',
name: 'disconnected-agent-2',
dateAdd: '1970-01-01T00:00:00Z',
group: ['default', 'test'],
lastKeepAlive: '2023-03-14T04:20:51Z',
node_name: 'node01',
registerIP: 'any',
id: '010',
version: 'Wazuh v4.3.10',
ip: '111.111.1.111',
mergedSum: 'e669d89eba52f6897060fc65a45300ac',
configSum: '97fccbb67e250b7c80aadc8d0dc59abe',
group_config_status: 'not synced',
count: 1,
},
],
total_affected_items: 5,
total_failed_items: 0,
failed_items: [],
},
message: 'All selected agents information was returned',
error: 0,
};

var mock = {
'configSum': ['97fccbb67e250b7c80aadc8d0dc59abc', '97fccbb67e250b7c80aadc8d0dc59abd', '97fccbb67e250b7c80aadc8d0dc59abf', '97fccbb67e250b7c80aadc8d0dc59abe'],
'dateAdd': ['2022-08-25T16:17:46Z', '2022-08-25T17:17:46Z', '2022-08-25T18:17:46Z'],
'id': ['001', '002','003','004','005'],
'ip': ['127.0.0.1', '127.0.0.2','127.0.0.3','127.0.0.4','127.0.0.5'],
'group': ['default', 'windows', 'linux', 'rhel', 'arch'],
'group_config_status': ['not synced', 'synced'],
'lastKeepAlive': ['2022-08-25T16:17:46Z', '2022-08-25T17:17:46Z', '2022-08-25T18:17:46Z'],
'manager': ['test.com', 'test2.com'],
'mergedSum': ['e669d89eba52f6897060fc65a45300ac', 'e669d89eba52f6897060fc65a45300ad', 'e669d89eba52f6897060fc65a45300ae', 'e669d89eba52f6897060fc65a45300af'],
'name': ['linux-agent', 'windows-agent'],
'node_name': ['node01', 'node02', 'node03'],
'os.platform': ['ubuntu', 'windows', 'darwin', 'amzn'],
'status': ['active', 'disconnected', 'pending', 'never_connected'],
'version': ['4.3.10', '4.4.0']
var selectedFields = fields.split(',');

var combinationsCount = {};

originalResponse.data.affected_items.forEach(function (agent) {
var combinationKey = selectedFields
.map(function (field) {
if (field.includes('.')) {
var subfields = field.split('.');
return agent[subfields[0]] !== undefined
? agent[subfields[0]][subfields[1]]
: 'unknown';
}
return agent[field];
})
.join(',');

if (!combinationsCount[combinationKey]) {
combinationsCount[combinationKey] = { count: 0 };
selectedFields.forEach(function (field) {
if (field.includes('.')) {
var subfields = field.split('.');
if (!combinationsCount[combinationKey][subfields[0]]) {
combinationsCount[combinationKey][subfields[0]] = {};
}
combinationsCount[combinationKey][subfields[0]][subfields[1]] =
agent[subfields[0]] && agent[subfields[0]][subfields[1]]
? agent[subfields[0]][subfields[1]]
: 'unknown';
} else {
combinationsCount[combinationKey][field] = agent[field];
}
});
}
combinationsCount[combinationKey].count += agent.count;
});

var transformedResponse = {
data: {
affected_items: [],
total_affected_items: 0,
total_failed_items: 0,
failed_items: [],
},
message: 'All selected agents information was returned',
error: 0,
};

var field = context.request.queryParams.fields;
var search = context.request.queryParams.search;
for (var key in combinationsCount) {
if (combinationsCount.hasOwnProperty(key)) {
transformedResponse.data.affected_items.push(combinationsCount[key]);
}
}

var responseJSON = generateResponse(mock[field], field, search);
transformedResponse.data.total_affected_items =
transformedResponse.data.affected_items.length;

respond()
.withStatusCode(200)
.withData(JSON.stringify(responseJSON))
respond().withStatusCode(200).withData(JSON.stringify(transformedResponse));
Loading
Loading