Skip to content

Commit 0c4d33c

Browse files
authored
Register uiSettings on New Platform (#64015) (#64094)
This now requires us to define a schema for each setting, which is a little redundant given that we also have to type the useUiSetting calls; this might be an issue between kibana-react and new UiSettings changes.
1 parent 26b23b3 commit 0c4d33c

File tree

3 files changed

+145
-112
lines changed

3 files changed

+145
-112
lines changed

x-pack/legacy/plugins/siem/index.ts

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,7 @@ import { Root } from 'joi';
1111
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
1212
import { savedObjectMappings } from '../../../plugins/siem/server/saved_objects';
1313

14-
import {
15-
APP_ID,
16-
APP_NAME,
17-
DEFAULT_INDEX_KEY,
18-
DEFAULT_ANOMALY_SCORE,
19-
DEFAULT_SIEM_TIME_RANGE,
20-
DEFAULT_SIEM_REFRESH_INTERVAL,
21-
DEFAULT_INTERVAL_PAUSE,
22-
DEFAULT_INTERVAL_VALUE,
23-
DEFAULT_FROM,
24-
DEFAULT_TO,
25-
ENABLE_NEWS_FEED_SETTING,
26-
NEWS_FEED_URL_SETTING,
27-
NEWS_FEED_URL_SETTING_DEFAULT,
28-
IP_REPUTATION_LINKS_SETTING,
29-
IP_REPUTATION_LINKS_SETTING_DEFAULT,
30-
DEFAULT_INDEX_PATTERN,
31-
} from '../../../plugins/siem/common/constants';
14+
import { APP_ID, APP_NAME } from '../../../plugins/siem/common/constants';
3215
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils';
3316

3417
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -63,100 +46,6 @@ export const siem = (kibana: any) => {
6346
category: DEFAULT_APP_CATEGORIES.security,
6447
},
6548
],
66-
uiSettingDefaults: {
67-
[DEFAULT_SIEM_REFRESH_INTERVAL]: {
68-
type: 'json',
69-
name: i18n.translate('xpack.siem.uiSettings.defaultRefreshIntervalLabel', {
70-
defaultMessage: 'Time filter refresh interval',
71-
}),
72-
value: `{
73-
"pause": ${DEFAULT_INTERVAL_PAUSE},
74-
"value": ${DEFAULT_INTERVAL_VALUE}
75-
}`,
76-
description: i18n.translate('xpack.siem.uiSettings.defaultRefreshIntervalDescription', {
77-
defaultMessage:
78-
'<p>Default refresh interval for the SIEM time filter, in milliseconds.</p>',
79-
}),
80-
category: ['siem'],
81-
requiresPageReload: true,
82-
},
83-
[DEFAULT_SIEM_TIME_RANGE]: {
84-
type: 'json',
85-
name: i18n.translate('xpack.siem.uiSettings.defaultTimeRangeLabel', {
86-
defaultMessage: 'Time filter period',
87-
}),
88-
value: `{
89-
"from": "${DEFAULT_FROM}",
90-
"to": "${DEFAULT_TO}"
91-
}`,
92-
description: i18n.translate('xpack.siem.uiSettings.defaultTimeRangeDescription', {
93-
defaultMessage: '<p>Default period of time in the SIEM time filter.</p>',
94-
}),
95-
category: ['siem'],
96-
requiresPageReload: true,
97-
},
98-
[DEFAULT_INDEX_KEY]: {
99-
name: i18n.translate('xpack.siem.uiSettings.defaultIndexLabel', {
100-
defaultMessage: 'Elasticsearch indices',
101-
}),
102-
value: DEFAULT_INDEX_PATTERN,
103-
description: i18n.translate('xpack.siem.uiSettings.defaultIndexDescription', {
104-
defaultMessage:
105-
'<p>Comma-delimited list of Elasticsearch indices from which the SIEM app collects events.</p>',
106-
}),
107-
category: ['siem'],
108-
requiresPageReload: true,
109-
},
110-
[DEFAULT_ANOMALY_SCORE]: {
111-
name: i18n.translate('xpack.siem.uiSettings.defaultAnomalyScoreLabel', {
112-
defaultMessage: 'Anomaly threshold',
113-
}),
114-
value: 50,
115-
type: 'number',
116-
description: i18n.translate('xpack.siem.uiSettings.defaultAnomalyScoreDescription', {
117-
defaultMessage:
118-
'<p>Value above which Machine Learning job anomalies are displayed in the SIEM app.</p><p>Valid values: 0 to 100.</p>',
119-
}),
120-
category: ['siem'],
121-
requiresPageReload: true,
122-
},
123-
[ENABLE_NEWS_FEED_SETTING]: {
124-
name: i18n.translate('xpack.siem.uiSettings.enableNewsFeedLabel', {
125-
defaultMessage: 'News feed',
126-
}),
127-
value: true,
128-
description: i18n.translate('xpack.siem.uiSettings.enableNewsFeedDescription', {
129-
defaultMessage: '<p>Enables the News feed</p>',
130-
}),
131-
type: 'boolean',
132-
category: ['siem'],
133-
requiresPageReload: true,
134-
},
135-
[NEWS_FEED_URL_SETTING]: {
136-
name: i18n.translate('xpack.siem.uiSettings.newsFeedUrl', {
137-
defaultMessage: 'News feed URL',
138-
}),
139-
value: NEWS_FEED_URL_SETTING_DEFAULT,
140-
description: i18n.translate('xpack.siem.uiSettings.newsFeedUrlDescription', {
141-
defaultMessage: '<p>News feed content will be retrieved from this URL</p>',
142-
}),
143-
category: ['siem'],
144-
requiresPageReload: true,
145-
},
146-
[IP_REPUTATION_LINKS_SETTING]: {
147-
name: i18n.translate('xpack.siem.uiSettings.ipReputationLinks', {
148-
defaultMessage: 'IP Reputation Links',
149-
}),
150-
value: IP_REPUTATION_LINKS_SETTING_DEFAULT,
151-
type: 'json',
152-
description: i18n.translate('xpack.siem.uiSettings.ipReputationLinksDescription', {
153-
defaultMessage:
154-
'Array of URL templates to build the list of reputation URLs to be displayed on the IP Details page.',
155-
}),
156-
category: ['siem'],
157-
requiresPageReload: true,
158-
},
159-
},
16049
mappings: savedObjectMappings,
16150
},
16251
config(Joi: Root) {

x-pack/plugins/siem/server/plugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
} from './saved_objects';
4343
import { SiemClientFactory } from './client';
4444
import { createConfig$, ConfigType } from './config';
45+
import { initUiSettings } from './ui_settings';
4546

4647
export { CoreSetup, CoreStart };
4748

@@ -86,6 +87,8 @@ export class Plugin {
8687
);
8788
}
8889

90+
initUiSettings(core.uiSettings);
91+
8992
const router = core.http.createRouter();
9093
core.http.registerRouteHandlerContext(this.name, (context, request, response) => ({
9194
getSiemClient: () => this.siemClientFactory.create(request),
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { i18n } from '@kbn/i18n';
8+
import { schema } from '@kbn/config-schema';
9+
10+
import { CoreSetup } from '../../../../src/core/server';
11+
import {
12+
DEFAULT_INDEX_KEY,
13+
DEFAULT_INDEX_PATTERN,
14+
DEFAULT_ANOMALY_SCORE,
15+
DEFAULT_SIEM_TIME_RANGE,
16+
DEFAULT_SIEM_REFRESH_INTERVAL,
17+
DEFAULT_INTERVAL_PAUSE,
18+
DEFAULT_INTERVAL_VALUE,
19+
DEFAULT_FROM,
20+
DEFAULT_TO,
21+
ENABLE_NEWS_FEED_SETTING,
22+
NEWS_FEED_URL_SETTING,
23+
NEWS_FEED_URL_SETTING_DEFAULT,
24+
IP_REPUTATION_LINKS_SETTING,
25+
IP_REPUTATION_LINKS_SETTING_DEFAULT,
26+
} from '../common/constants';
27+
28+
export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
29+
uiSettings.register({
30+
[DEFAULT_SIEM_REFRESH_INTERVAL]: {
31+
type: 'json',
32+
name: i18n.translate('xpack.siem.uiSettings.defaultRefreshIntervalLabel', {
33+
defaultMessage: 'Time filter refresh interval',
34+
}),
35+
value: `{
36+
"pause": ${DEFAULT_INTERVAL_PAUSE},
37+
"value": ${DEFAULT_INTERVAL_VALUE}
38+
}`,
39+
description: i18n.translate('xpack.siem.uiSettings.defaultRefreshIntervalDescription', {
40+
defaultMessage:
41+
'<p>Default refresh interval for the SIEM time filter, in milliseconds.</p>',
42+
}),
43+
category: ['siem'],
44+
requiresPageReload: true,
45+
schema: schema.object({
46+
value: schema.number(),
47+
pause: schema.boolean(),
48+
}),
49+
},
50+
[DEFAULT_SIEM_TIME_RANGE]: {
51+
type: 'json',
52+
name: i18n.translate('xpack.siem.uiSettings.defaultTimeRangeLabel', {
53+
defaultMessage: 'Time filter period',
54+
}),
55+
value: `{
56+
"from": "${DEFAULT_FROM}",
57+
"to": "${DEFAULT_TO}"
58+
}`,
59+
description: i18n.translate('xpack.siem.uiSettings.defaultTimeRangeDescription', {
60+
defaultMessage: '<p>Default period of time in the SIEM time filter.</p>',
61+
}),
62+
category: ['siem'],
63+
requiresPageReload: true,
64+
schema: schema.object({
65+
from: schema.string(),
66+
to: schema.string(),
67+
}),
68+
},
69+
[DEFAULT_INDEX_KEY]: {
70+
name: i18n.translate('xpack.siem.uiSettings.defaultIndexLabel', {
71+
defaultMessage: 'Elasticsearch indices',
72+
}),
73+
value: DEFAULT_INDEX_PATTERN,
74+
description: i18n.translate('xpack.siem.uiSettings.defaultIndexDescription', {
75+
defaultMessage:
76+
'<p>Comma-delimited list of Elasticsearch indices from which the SIEM app collects events.</p>',
77+
}),
78+
category: ['siem'],
79+
requiresPageReload: true,
80+
schema: schema.arrayOf(schema.string()),
81+
},
82+
[DEFAULT_ANOMALY_SCORE]: {
83+
name: i18n.translate('xpack.siem.uiSettings.defaultAnomalyScoreLabel', {
84+
defaultMessage: 'Anomaly threshold',
85+
}),
86+
value: 50,
87+
type: 'number',
88+
description: i18n.translate('xpack.siem.uiSettings.defaultAnomalyScoreDescription', {
89+
defaultMessage:
90+
'<p>Value above which Machine Learning job anomalies are displayed in the SIEM app.</p><p>Valid values: 0 to 100.</p>',
91+
}),
92+
category: ['siem'],
93+
requiresPageReload: true,
94+
schema: schema.number(),
95+
},
96+
[ENABLE_NEWS_FEED_SETTING]: {
97+
name: i18n.translate('xpack.siem.uiSettings.enableNewsFeedLabel', {
98+
defaultMessage: 'News feed',
99+
}),
100+
value: true,
101+
description: i18n.translate('xpack.siem.uiSettings.enableNewsFeedDescription', {
102+
defaultMessage: '<p>Enables the News feed</p>',
103+
}),
104+
type: 'boolean',
105+
category: ['siem'],
106+
requiresPageReload: true,
107+
schema: schema.boolean(),
108+
},
109+
[NEWS_FEED_URL_SETTING]: {
110+
name: i18n.translate('xpack.siem.uiSettings.newsFeedUrl', {
111+
defaultMessage: 'News feed URL',
112+
}),
113+
value: NEWS_FEED_URL_SETTING_DEFAULT,
114+
description: i18n.translate('xpack.siem.uiSettings.newsFeedUrlDescription', {
115+
defaultMessage: '<p>News feed content will be retrieved from this URL</p>',
116+
}),
117+
category: ['siem'],
118+
requiresPageReload: true,
119+
schema: schema.string(),
120+
},
121+
[IP_REPUTATION_LINKS_SETTING]: {
122+
name: i18n.translate('xpack.siem.uiSettings.ipReputationLinks', {
123+
defaultMessage: 'IP Reputation Links',
124+
}),
125+
value: IP_REPUTATION_LINKS_SETTING_DEFAULT,
126+
type: 'json',
127+
description: i18n.translate('xpack.siem.uiSettings.ipReputationLinksDescription', {
128+
defaultMessage:
129+
'Array of URL templates to build the list of reputation URLs to be displayed on the IP Details page.',
130+
}),
131+
category: ['siem'],
132+
requiresPageReload: true,
133+
schema: schema.arrayOf(
134+
schema.object({
135+
name: schema.string(),
136+
url_template: schema.string(),
137+
})
138+
),
139+
},
140+
});
141+
};

0 commit comments

Comments
 (0)