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

Fixed errors in group reports #4350

Merged
merged 5 commits into from
Aug 5, 2022
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ All notable changes to the Wazuh app project will be documented in this file.

### Fixed

- Fixed an error during the generation of a group's report, if the request to the Wazuh API fails [#4350](https://github.com/wazuh/wazuh-kibana-app/pull/4350)
- Fixed a problem with the group's report, when the group has no agents [#4350](https://github.com/wazuh/wazuh-kibana-app/pull/4350)
- Fixed path in logo customization section [#4352](https://github.com/wazuh/wazuh-kibana-app/pull/4352)

# Removed

- Removed the use of `manager_host` field related to agent information of Wazuh API responses, which is obsolete [#4350](https://github.com/wazuh/wazuh-kibana-app/pull/4350)

## Wazuh v4.3.6 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 4307

### Fixed
Expand Down
1 change: 0 additions & 1 deletion common/csv-key-equivalence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const KeyEquivalence: {[key: string]: string} = {
architecture: 'Architecture',
node_name: 'Node',
dateAdd: 'Registration date',
manager_host: 'Manager',
manager: 'Manager',
lastKeepAlive: 'Last keep alive',
os: 'OS',
Expand Down
1 change: 0 additions & 1 deletion public/utils/monitoring-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const FieldsMonitoring =[
{ "name": "configSum", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": false, "readFromDocValues": false },
{ "name": "node_name", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": false, "readFromDocValues": false },
{ "name": "manager", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": false, "readFromDocValues": false },
{ "name": "manager_host", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": false, "readFromDocValues": false },
{ "name": "name", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": true, "readFromDocValues": true },
{ "name": "os.arch", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": false, "readFromDocValues": false },
{ "name": "os.codename", "type": "string", "count": 0, "scripted": false, "searchable": true, "aggregatable": false, "readFromDocValues": false },
Expand Down
157 changes: 69 additions & 88 deletions server/controllers/wazuh-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,8 @@ export class WazuhReportingCtrl {
} else if (section === 'groupConfig') {
printer.addContent({
text: 'Agents in group',
style: { fontSize: 14, color: '#000' },
margin: [0, 20, 0, 0],
style: 'h1',
});
if (section === 'groupConfig' && !Object.keys(isAgents).length) {
printer.addContent({
text: 'There are still no agents in this group.',
style: { fontSize: 12, color: '#000' },
margin: [0, 10, 0, 0],
});
}
}
printer.addNewLine();
}
Expand All @@ -154,7 +146,7 @@ export class WazuhReportingCtrl {
printer,
isAgents,
apiId,
section === 'groupConfig' ? tab : false
section === 'groupConfig' ? tab : ''
);
}

Expand Down Expand Up @@ -188,8 +180,6 @@ export class WazuhReportingCtrl {
style: 'standard',
});
}

return;
} catch (error) {
log('reporting:renderHeader', error.message || error);
return Promise.reject(error);
Expand All @@ -201,57 +191,44 @@ export class WazuhReportingCtrl {
* @param {Array<Strings>} ids ids of agents
* @param {String} apiId API id
*/
private async buildAgentsTable(context, printer: ReportPrinter, agentIDs: string[], apiId: string, multi = false) {
private async buildAgentsTable(context, printer: ReportPrinter, agentIDs: string[], apiId: string, groupID: string = '') {
const dateFormat = await context.core.uiSettings.client.get('dateFormat');
if (!agentIDs || !agentIDs.length) return;
if ((!agentIDs || !agentIDs.length) && !groupID) return;
log('reporting:buildAgentsTable', `${agentIDs.length} agents for API ${apiId}`, 'info');
try {
let agentRows = [];
if (multi) {
try {
const agentsResponse = await context.wazuh.api.client.asCurrentUser.request(
let agentsData = [];
if (groupID) {
let totalAgentsInGroup = null;
do{
const { data: { data: { affected_items, total_affected_items } } } = await context.wazuh.api.client.asCurrentUser.request(
'GET',
`/groups/${multi}/agents`,
{},
`/groups/${groupID}/agents`,
{
params: {
offset: agentsData.length,
select: 'dateAdd,id,ip,lastKeepAlive,manager,name,os.name,os.version,version',
}
},
{ apiHostID: apiId }
);
const agentsData =
agentsResponse &&
agentsResponse.data &&
agentsResponse.data.data &&
agentsResponse.data.data.affected_items;
agentRows = (agentsData || []).map((agent) => ({
...agent,
manager: agent.manager || agent.manager_host,
os:
agent.os && agent.os.name && agent.os.version
? `${agent.os.name} ${agent.os.version}`
: '',
}));
} catch (error) {
log(
'reporting:buildAgentsTable',
`Skip agent due to: ${error.message || error}`,
'debug'
);
}
!totalAgentsInGroup && (totalAgentsInGroup = total_affected_items);
agentsData = [...agentsData, ...affected_items];
}while(agentsData.length < totalAgentsInGroup);
} else {
for (const agentID of agentIDs) {
try {
const agentResponse = await context.wazuh.api.client.asCurrentUser.request(
const { data: { data: { affected_items: [agent] } } } = await context.wazuh.api.client.asCurrentUser.request(
'GET',
`/agents`,
{ params: { q: `id=${agentID}` } },
{
params: {
q: `id=${agentID}`,
select: 'dateAdd,id,ip,lastKeepAlive,manager,name,os.name,os.version,version',
}
},
{ apiHostID: apiId }
);
const [agent] = agentResponse.data.data.affected_items;
agentRows.push({
...agent,
manager: agent.manager || agent.manager_host,
os: (agent.os && agent.os.name && agent.os.version) ? `${agent.os.name} ${agent.os.version}` : '',
lastKeepAlive: moment(agent.lastKeepAlive).format(dateFormat),
dateAdd: moment(agent.dateAdd).format(dateFormat)
});
agentsData.push(agent);
} catch (error) {
log(
'reporting:buildAgentsTable',
Expand All @@ -261,19 +238,37 @@ export class WazuhReportingCtrl {
}
}
}
printer.addSimpleTable({
columns: [
{ id: 'id', label: 'ID' },
{ id: 'name', label: 'Name' },
{ id: 'ip', label: 'IP' },
{ id: 'version', label: 'Version' },
{ id: 'manager', label: 'Manager' },
{ id: 'os', label: 'OS' },
{ id: 'dateAdd', label: 'Registration date' },
{ id: 'lastKeepAlive', label: 'Last keep alive' },
],
items: agentRows,
});

if(agentsData.length){
// Print a table with agent/s information
printer.addSimpleTable({
columns: [
{ id: 'id', label: 'ID' },
{ id: 'name', label: 'Name' },
{ id: 'ip', label: 'IP' },
{ id: 'version', label: 'Version' },
{ id: 'manager', label: 'Manager' },
{ id: 'os', label: 'OS' },
{ id: 'dateAdd', label: 'Registration date' },
{ id: 'lastKeepAlive', label: 'Last keep alive' },
],
items: agentsData.map((agent) => {
return {
...agent,
os: (agent.os && agent.os.name && agent.os.version) ? `${agent.os.name} ${agent.os.version}` : '',
lastKeepAlive: moment(agent.lastKeepAlive).format(dateFormat),
dateAdd: moment(agent.dateAdd).format(dateFormat)
}
}),
});
}else if(!agentsData.length && groupID){
// For group reports when there is no agents in the group
printer.addContent({
text: 'There are no agents in this group.',
style: { fontSize: 12, color: '#000' },
});
}

} catch (error) {
log('reporting:buildAgentsTable', error.message || error);
return Promise.reject(error);
Expand Down Expand Up @@ -1249,19 +1244,15 @@ export class WazuhReportingCtrl {
style: 'h1',
});

// Group configuration
if (components['0']) {
let configuration = {};
try {
const configurationResponse = await context.wazuh.api.client.asCurrentUser.request(
'GET',
`/groups/${groupID}/configuration`,
{},
{ apiHostID: apiId }
);
configuration = configurationResponse.data.data;
} catch (error) {
log('reporting:createReportsGroups', error.message || error, 'debug');
}

const { data: { data: configuration } } = await context.wazuh.api.client.asCurrentUser.request(
'GET',
`/groups/${groupID}/configuration`,
{},
{ apiHostID: apiId }
);

if (
configuration.affected_items.length > 0 &&
Expand Down Expand Up @@ -1441,25 +1432,15 @@ export class WazuhReportingCtrl {
});
}
}

// Agents in group
if (components['1']) {
let agentsInGroup = [];
try {
const agentsInGroupResponse = await context.wazuh.api.client.asCurrentUser.request(
'GET',
`/groups/${groupID}/agents`,
{},
{ apiHostID: apiId }
);
agentsInGroup = agentsInGroupResponse.data.data.affected_items;
} catch (error) {
log('reporting:report', error.message || error, 'debug');
}
await this.renderHeader(
context,
printer,
'groupConfig',
groupID,
(agentsInGroup || []).map((x) => x.id),
[],
apiId
);
}
Expand Down
9 changes: 0 additions & 9 deletions server/integration-files/monitoring-known-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,6 @@ export const monitoringKnownFields = [
aggregatable: false,
readFromDocValues: false
},
{
name: 'manager_host',
type: 'string',
count: 0,
scripted: false,
searchable: true,
aggregatable: false,
readFromDocValues: false
},
{
name: 'name',
type: 'string',
Expand Down