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

[SIEM] Adds a configuraton option for the default SIEM date time range #44540

Merged
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
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/siem/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ export const DEFAULT_DATE_FORMAT = 'dateFormat';
export const DEFAULT_DATE_FORMAT_TZ = 'dateFormat:tz';
export const DEFAULT_DARK_MODE = 'theme:darkMode';
export const DEFAULT_INDEX_KEY = 'siem:defaultIndex';
export const DEFAULT_TIME_RANGE = 'timepicker:timeDefaults';
export const DEFAULT_REFRESH_RATE_INTERVAL = 'timepicker:refreshIntervalDefaults';
export const DEFAULT_SIEM_TIME_RANGE = 'siem:timeDefaults';
export const DEFAULT_SIEM_REFRESH_INTERVAL = 'siem:refreshIntervalDefaults';
export const DEFAULT_ANOMALY_SCORE = 'siem:defaultAnomalyScore';
export const DEFAULT_MAX_TABLE_QUERY_SIZE = 10000;
export const DEFAULT_SCALE_DATE_FORMAT = 'dateFormat:scaled';
export const DEFAULT_KBN_VERSION = 'kbnVersion';
export const DEFAULT_TIMEZONE_BROWSER = 'timezoneBrowser';
export const DEFAULT_FROM = 'now-24h';
export const DEFAULT_TO = 'now';
export const DEFAULT_INTERVAL_PAUSE = true;
export const DEFAULT_INTERVAL_TYPE = 'manual';
export const DEFAULT_INTERVAL_VALUE = 300000; // ms
44 changes: 43 additions & 1 deletion x-pack/legacy/plugins/siem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ import { Server } from 'hapi';
import { initServerWithKibana } from './server/kibana.index';
import { savedObjectMappings } from './server/saved_objects';

import { APP_ID, APP_NAME, DEFAULT_INDEX_KEY, DEFAULT_ANOMALY_SCORE } from './common/constants';
import {
APP_ID,
APP_NAME,
DEFAULT_INDEX_KEY,
DEFAULT_ANOMALY_SCORE,
DEFAULT_SIEM_TIME_RANGE,
DEFAULT_SIEM_REFRESH_INTERVAL,
DEFAULT_INTERVAL_PAUSE,
DEFAULT_INTERVAL_VALUE,
DEFAULT_FROM,
DEFAULT_TO,
} from './common/constants';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function siem(kibana: any) {
Expand Down Expand Up @@ -45,6 +56,37 @@ export function siem(kibana: any) {
},
],
uiSettingDefaults: {
[DEFAULT_SIEM_REFRESH_INTERVAL]: {
type: 'json',
name: i18n.translate('xpack.siem.uiSettings.defaultRefreshIntervalLabel', {
defaultMessage: 'Time picker refresh interval',
}),
value: `{
"pause": ${DEFAULT_INTERVAL_PAUSE},
"value": ${DEFAULT_INTERVAL_VALUE}
}`,
description: i18n.translate('xpack.siem.uiSettings.defaultRefreshIntervalDescription', {
defaultMessage: "The SIEM timefilter's default refresh interval",
}),
category: ['siem'],
requiresPageReload: true,
},
[DEFAULT_SIEM_TIME_RANGE]: {
type: 'json',
name: i18n.translate('xpack.siem.uiSettings.defaultTimeRangeLabel', {
defaultMessage: 'Time picker defaults',
}),
value: `{
"from": "${DEFAULT_FROM}",
"to": "${DEFAULT_TO}"
}`,
description: i18n.translate('xpack.siem.uiSettings.defaultTimeRangeDescription', {
defaultMessage:
'The SIEM timefilter selection to use when Kibana is started without one',
}),
category: ['siem'],
requiresPageReload: true,
},
[DEFAULT_INDEX_KEY]: {
name: i18n.translate('xpack.siem.uiSettings.defaultIndexLabel', {
defaultMessage: 'Default index',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { i18n } from '@kbn/i18n';
import chrome from 'ui/chrome';
import moment from 'moment-timezone';
import { DEFAULT_DATE_FORMAT_TZ, DEFAULT_DARK_MODE } from '../../../common/constants';

const chartHeight = 74;
const chartDefaultRotation: Rotation = 0;
Expand Down Expand Up @@ -138,10 +139,10 @@ export const getTheme = () => {
barsPadding: 0.5,
},
};
const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode');
const isDarkMode: boolean = chrome.getUiSettingsClient().get(DEFAULT_DARK_MODE);
const defaultTheme = isDarkMode ? DARK_THEME : LIGHT_THEME;
return mergeWithDefaultTheme(theme, defaultTheme);
};

const kibanaTimezone = chrome.getUiSettingsClient().get('dateFormat:tz');
const kibanaTimezone: string = chrome.getUiSettingsClient().get(DEFAULT_DATE_FORMAT_TZ);
export const browserTimezone = kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import dateMath from '@elastic/datemath';
import ApolloClient from 'apollo-client';
import { getOr, set } from 'lodash/fp';
import { ActionCreator } from 'typescript-fsa';
Expand All @@ -28,6 +27,7 @@ import {
import { DEFAULT_DATE_COLUMN_MIN_WIDTH, DEFAULT_COLUMN_MIN_WIDTH } from '../timeline/body/helpers';

import { OpenTimelineResult, UpdateTimeline, DispatchUpdateTimeline } from './types';
import { getDefaultFromValue, getDefaultToValue } from '../../utils/default_date_settings';

export const OPEN_TIMELINE_CLASS_NAME = 'open-timeline';

Expand Down Expand Up @@ -177,16 +177,14 @@ export const queryTimelineById = <TCache>({
);

const { timeline, notes } = formatTimelineResultToModel(timelineToOpen, duplicate);

const momentDate = dateMath.parse('now-24h');
if (updateTimeline) {
updateTimeline({
duplicate,
from: getOr(momentDate ? momentDate.valueOf() : 0, 'dateRange.start', timeline),
from: getOr(getDefaultFromValue(), 'dateRange.start', timeline),
id: 'timeline-1',
notes,
timeline,
to: getOr(Date.now(), 'dateRange.end', timeline),
to: getOr(getDefaultToValue(), 'dateRange.end', timeline),
})();
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
isLoadingSelector,
refetchSelector,
} from './selectors';
import { InputsRange } from '../../store/inputs/model';
import { InputsRange, Policy } from '../../store/inputs/model';

const MAX_RECENTLY_USED_RANGES = 9;

Expand All @@ -53,7 +53,7 @@ const MyEuiSuperDatePicker: React.SFC<MyEuiSuperDatePickerProps> = EuiSuperDateP

interface SuperDatePickerStateRedux {
duration: number;
policy: string;
policy: Policy['kind'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ on fixing the typing -- thanks! 🙂

kind: string;
fromStr: string;
toStr: string;
Expand Down
14 changes: 10 additions & 4 deletions x-pack/legacy/plugins/siem/public/mock/global_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ import {
import { State } from '../store';

import { defaultHeaders } from './header';
import {
DEFAULT_FROM,
DEFAULT_TO,
DEFAULT_INTERVAL_TYPE,
DEFAULT_INTERVAL_VALUE,
} from '../../common/constants';

export const mockGlobalState: State = {
app: {
Expand Down Expand Up @@ -111,16 +117,16 @@ export const mockGlobalState: State = {
},
inputs: {
global: {
timerange: { kind: 'relative', fromStr: 'now-24h', toStr: 'now', from: 0, to: 1 },
timerange: { kind: 'relative', fromStr: DEFAULT_FROM, toStr: DEFAULT_TO, from: 0, to: 1 },
linkTo: ['timeline'],
query: [],
policy: { kind: 'manual', duration: 300000 },
policy: { kind: DEFAULT_INTERVAL_TYPE, duration: DEFAULT_INTERVAL_VALUE },
},
timeline: {
timerange: { kind: 'relative', fromStr: 'now-24h', toStr: 'now', from: 0, to: 1 },
timerange: { kind: 'relative', fromStr: DEFAULT_FROM, toStr: DEFAULT_TO, from: 0, to: 1 },
linkTo: ['global'],
query: [],
policy: { kind: 'manual', duration: 300000 },
policy: { kind: DEFAULT_INTERVAL_TYPE, duration: DEFAULT_INTERVAL_VALUE },
},
},
dragAndDrop: { dataProviders: {} },
Expand Down
33 changes: 28 additions & 5 deletions x-pack/legacy/plugins/siem/public/mock/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,41 @@
*/

import chrome from 'ui/chrome';
import {
DEFAULT_SIEM_TIME_RANGE,
DEFAULT_SIEM_REFRESH_INTERVAL,
DEFAULT_INDEX_KEY,
DEFAULT_DATE_FORMAT_TZ,
DEFAULT_DARK_MODE,
DEFAULT_TIME_RANGE,
DEFAULT_REFRESH_RATE_INTERVAL,
DEFAULT_FROM,
DEFAULT_TO,
DEFAULT_INTERVAL_PAUSE,
DEFAULT_INTERVAL_VALUE,
} from '../../common/constants';

chrome.getUiSettingsClient().get.mockImplementation((key: string) => {
switch (key) {
case 'timepicker:timeDefaults':
case DEFAULT_TIME_RANGE:
return { from: 'now-15m', to: 'now', mode: 'quick' };
case 'timepicker:refreshIntervalDefaults':
case DEFAULT_REFRESH_RATE_INTERVAL:
return { pause: false, value: 0 };
case 'siem:defaultIndex':
case DEFAULT_SIEM_TIME_RANGE:
return {
from: DEFAULT_FROM,
to: DEFAULT_TO,
};
case DEFAULT_SIEM_REFRESH_INTERVAL:
return {
pause: DEFAULT_INTERVAL_PAUSE,
value: DEFAULT_INTERVAL_VALUE,
};
case DEFAULT_INDEX_KEY:
return ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'];
case 'dateFormat:tz':
case DEFAULT_DATE_FORMAT_TZ:
return 'Asia/Taipei';
case 'theme:darkMode':
case DEFAULT_DARK_MODE:
return false;
default:
throw new Error(`Unexpected config key: ${key}`);
Expand Down
35 changes: 21 additions & 14 deletions x-pack/legacy/plugins/siem/public/store/inputs/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import dateMath from '@elastic/datemath';
import { get } from 'lodash/fp';
import { reducerWithInitialState } from 'typescript-fsa-reducers';

Expand Down Expand Up @@ -35,37 +34,45 @@ import {
addTimelineLink,
} from './helpers';
import { InputsModel, TimeRange } from './model';
import {
getDefaultFromValue,
getDefaultToValue,
getDefaultFromString,
getDefaultToString,
getDefaultIntervalKind,
getDefaultIntervalDuration,
} from '../../utils/default_date_settings';

export type InputsState = InputsModel;
const momentDate = dateMath.parse('now-24h');

export const initialInputsState: InputsState = {
global: {
timerange: {
kind: 'relative',
fromStr: 'now-24h',
toStr: 'now',
from: momentDate ? momentDate.valueOf() : 0,
to: Date.now(),
fromStr: getDefaultFromString(),
toStr: getDefaultToString(),
from: getDefaultFromValue(),
to: getDefaultToValue(),
},
query: [],
policy: {
kind: 'manual',
duration: 300000,
kind: getDefaultIntervalKind(),
duration: getDefaultIntervalDuration(),
},
linkTo: ['timeline'],
},
timeline: {
timerange: {
kind: 'relative',
fromStr: 'now-24h',
toStr: 'now',
from: momentDate ? momentDate.valueOf() : 0,
to: Date.now(),
fromStr: getDefaultFromString(),
toStr: getDefaultToString(),
from: getDefaultFromValue(),
to: getDefaultToValue(),
},
query: [],
policy: {
kind: 'manual',
duration: 300000,
kind: getDefaultIntervalKind(),
duration: getDefaultIntervalDuration(),
},
linkTo: ['global'],
},
Expand Down
Loading