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

Rework home overview #7310

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions plugins/wazuh-core/public/home/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

export function Application() {
return (
<div>
<h1>Home</h1>
</div>
);
}
37 changes: 37 additions & 0 deletions plugins/wazuh-core/public/home/register-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import React from 'react';
import { i18n } from '@osd/i18n';
import { AppMountParameters } from 'opensearch_dashboards/public';

export function registerHomeApp(deps: { core: any }) {
const { http } = deps.core;

deps.core.application.register({
id: 'wz-home-core',
title: 'Overview',
order: '1',
mount: async (params: AppMountParameters) => {
try {
const { renderApp } = await import('./render-app');

params.element.classList.add('dscAppWrapper', 'wz-app');

const unmount = await renderApp({ http, params });

return () => {
unmount();
};
} catch (error) {
console.debug(error);
}
},
category: {
id: 'wz-category-home-core',
label: i18n.translate('wz-app-category-home-core', {
defaultMessage: 'Home',
}),
order: 0,
euiIconType: 'appSearchApp',
},
});
}
17 changes: 17 additions & 0 deletions plugins/wazuh-core/public/home/render-app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { I18nProvider } from '@osd/i18n/react';
import { Application } from './application';

export async function renderApp({ http, params }) {
const deps = { http, params };

ReactDOM.render(
<I18nProvider>
<Application {...deps} />
</I18nProvider>,
params.element,
);

return () => ReactDOM.unmountComponentAtNode(params.element);
}
5 changes: 3 additions & 2 deletions plugins/wazuh-core/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ServerHostStateContainer } from './services/state/containers/server-hos
import { DataSourceAlertsStateContainer } from './services/state/containers/data-source-alerts';
import { CoreServerSecurity } from './services';
import { CoreHTTPClient } from './services/http/http-client';
import { registerHomeApp } from './home/register-app';

const noop = () => {};

Expand All @@ -47,7 +48,6 @@ export class WazuhCorePlugin

public async setup(core: CoreSetup): Promise<WazuhCorePluginSetup> {
// No operation logger

const logger = {
info: noop,
error: noop,
Expand All @@ -66,7 +66,6 @@ export class WazuhCorePlugin
new InitializerConfigProvider(this.initializerContext),
);

// register the uiSettins on the configuration store to avoid the use inside of configuration service
this.internal.configurationStore.registerProvider(
EConfigurationProviders.PLUGIN_UI_SETTINGS,
new UISettingsConfigProvider(core.uiSettings),
Expand Down Expand Up @@ -127,6 +126,8 @@ export class WazuhCorePlugin
this.runtime.start.serverSecurityDeps.chrome.logos.AnimatedMark,
});

registerHomeApp({ core });

return {
...this.services,
utils,
Expand Down
65 changes: 65 additions & 0 deletions plugins/wazuh-core/server/home/fields-home.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"name": "_id",
"type": "string",
"esTypes": ["_id"],
"searchable": true,
"aggregatable": true,
"readFromDocValues": false
},
{
"name": "_index",
"type": "string",
"esTypes": ["_index"],
"searchable": true,
"aggregatable": true,
"readFromDocValues": false
},
{
"name": "_score",
"type": "number",
"searchable": false,
"aggregatable": false,
"readFromDocValues": false
},
{
"name": "_source",
"type": "_source",
"esTypes": ["_source"],
"searchable": false,
"aggregatable": false,
"readFromDocValues": false
},
{
"name": "_type",
"type": "string",
"esTypes": ["_type"],
"searchable": true,
"aggregatable": true,
"readFromDocValues": false
},
{
"name": "@timestamp",
"type": "date",
"esTypes": ["date"],
"searchable": true,
"aggregatable": true,
"readFromDocValues": true
},
{
"name": "@version",
"type": "string",
"esTypes": ["text"],
"searchable": true,
"aggregatable": false,
"readFromDocValues": false
},
{
"name": "agent.name_terms",
"type": "string",
"esTypes": ["keyword"],
"searchable": true,
"aggregatable": true,
"readFromDocValues": true
}
]
20 changes: 20 additions & 0 deletions plugins/wazuh-core/server/home/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import IndexPatternDefaultFields from './fields-home.json';

export const registerHomeApp = (
services,
initializationTaskCreatorIndexPattern,
) => {
services.initialization.register(
initializationTaskCreatorIndexPattern({
getIndexPatternID: async () => 'wazuh-home-*',
taskName: 'index-pattern:wazuh-home',
options: {
savedObjectOverwrite: {
timeFieldName: '@timestamp',
},
fieldsNoIndices: IndexPatternDefaultFields,
},
// configurationSettingKey: 'checks.statistics', // TODO: create new setting
}),
);
};
3 changes: 3 additions & 0 deletions plugins/wazuh-core/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from './initialization';
import monitoringIndexPatternDefaultFields from './initialization/index-patterns-fields/monitoring-fields.json';
import statisticsIndexPatternDefaultFields from './initialization/index-patterns-fields/statistics-fields.json';
import { registerHomeApp } from './home/index';
import indexPatternFieldsAgent from './initialization/index-patterns-fields/fields-agent.json';
import indexPatternFieldsAlerts from './initialization/index-patterns-fields/fields-alerts.json';
import indexPatternFieldsCommands from './initialization/index-patterns-fields/fields-commands.json';
Expand Down Expand Up @@ -348,6 +349,8 @@ export class WazuhCorePlugin
},
}));

registerHomeApp(this.services, initializationTaskCreatorIndexPattern);

return {
...this.services,
api: {
Expand Down