Skip to content

Commit

Permalink
use log types from API
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Jul 28, 2023
1 parent b595a7d commit 29fb641
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import React, { Component } from 'react';
import { ContentPanel } from '../../../../../../components/ContentPanel';
import { EuiFormRow, EuiFlexGrid, EuiFlexItem, EuiRadio, EuiSpacer } from '@elastic/eui';
import { FormFieldHeader } from '../../../../../../components/FormFieldHeader/FormFieldHeader';
import { DETECTOR_TYPES } from '../../../../../Detectors/utils/constants';
import { DetectorTypeOption } from '../../../../../Detectors/models/interfaces';
import { CreateDetectorRulesState, DetectionRules } from '../DetectionRules/DetectionRules';
import { RuleItem } from '../DetectionRules/types/interfaces';
import { ruleTypes } from '../../../../../Rules/utils/constants';

interface DetectorTypeProps {
detectorType: string;
Expand All @@ -32,7 +32,10 @@ export default class DetectorType extends Component<DetectorTypeProps, DetectorT
constructor(props: DetectorTypeProps) {
super(props);

const detectorTypeOptions = Object.values(DETECTOR_TYPES);
const detectorTypeOptions: DetectorTypeOption[] = ruleTypes.map(({ label, value }) => ({
id: value,
label: label,
}));
const detectorTypeIds = detectorTypeOptions.map((option) => option.id);
this.state = {
fieldTouched: false,
Expand Down
17 changes: 0 additions & 17 deletions public/pages/Detectors/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,3 @@ export const EMPTY_DEFAULT_DETECTOR_INPUT = {
rules: [],
},
};

export const DETECTOR_TYPES = {
NETWORK: { id: 'network', label: 'Network events', abbr: 'NTW' },
DNS: { id: 'dns', label: 'DNS logs', abbr: 'DNS' },
APACHE_ACCESS: { id: 'apache_access', label: 'Apache access logs', abbr: 'APC' },
WINDOWS: { id: 'windows', label: 'Windows logs', abbr: 'WIN' },
AD_LDAP: { id: 'ad_ldap', label: 'AD/LDAP logs', abbr: 'AD' },
SYSTEM: { id: 'linux', label: 'System logs', abbr: 'LNX' },
CLOUD_TRAIL: { id: 'cloudtrail', label: 'Cloud Trail logs', abbr: 'CLT' },
S3: { id: 's3', label: 'S3 access logs', abbr: 'S3' },
GWORKSPACE: { id: 'gworkspace', label: 'Google Workspace logs', abbr: 'GGL' },
GITHUB: { id: 'github', label: 'Github actions', abbr: 'GHB' },
M365: { id: 'm365', label: 'Microsoft 365 logs', abbr: 'MSO' },
OKTA: { id: 'okta', label: 'Okta events', abbr: 'OKT' },
AZURE: { id: 'azure', label: 'Azure logs', abbr: 'AZR' },
VPC_FLOW: { id: 'vpcflow', label: 'VPC Flow logs', abbr: 'VPC' },
};
65 changes: 39 additions & 26 deletions public/pages/Rules/components/RuleEditor/RuleEditorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EuiText,
EuiTitle,
EuiPanel,
EuiIcon,
} from '@elastic/eui';
import { ContentPanel } from '../../../../components/ContentPanel';
import { FieldTextArray } from './components/FieldTextArray';
Expand Down Expand Up @@ -255,32 +256,44 @@ export const RuleEditorForm: React.FC<VisualRuleEditorProps> = ({

<EuiSpacer />

<EuiFormRow
label={
<EuiText size={'s'}>
<strong>Log type</strong>
</EuiText>
}
isInvalid={props.touched.logType && !!props.errors?.logType}
error={props.errors.logType}
>
<EuiComboBox
isInvalid={props.touched.logType && !!props.errors.logType}
placeholder="Select a log type"
data-test-subj={'rule_type_dropdown'}
options={ruleTypes.map(({ value, label }) => ({ value, label }))}
singleSelection={{ asPlainText: true }}
onChange={(e) => {
props.handleChange('logType')(e[0]?.value ? e[0].value : '');
}}
onBlur={props.handleBlur('logType')}
selectedOptions={
props.values.logType
? [{ value: props.values.logType, label: props.values.logType }]
: []
}
/>
</EuiFormRow>
<EuiFlexGroup alignItems="flexStart">
<EuiFlexItem style={{ maxWidth: 400 }}>
<EuiFormRow
label={
<EuiText size={'s'}>
<strong>Log type</strong>
</EuiText>
}
isInvalid={props.touched.logType && !!props.errors?.logType}
error={props.errors.logType}
>
<EuiComboBox
isInvalid={props.touched.logType && !!props.errors.logType}
placeholder="Select a log type"
data-test-subj={'rule_type_dropdown'}
options={ruleTypes.map(({ value, label }) => ({ value, label }))}
singleSelection={{ asPlainText: true }}
onChange={(e) => {
props.handleChange('logType')(e[0]?.value ? e[0].value : '');
}}
onBlur={props.handleBlur('logType')}
selectedOptions={
props.values.logType
? [{ value: props.values.logType, label: props.values.logType }]
: []
}
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ marginTop: 36 }}>
<EuiButton
href={'opensearch_security_analytics_dashboards#/log-types'}
target="_blank"
>
Manage <EuiIcon type={'popout'} />
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer />

Expand Down
17 changes: 1 addition & 16 deletions public/pages/Rules/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@

import { euiPaletteForStatus } from '@elastic/eui';

export const ruleTypes: { label: string; value: string; abbr: string }[] = [
{ abbr: 'NTW', label: 'Network', value: 'network' },
{ abbr: 'DNS', label: 'DNS', value: 'dns' },
{ abbr: 'APC', label: 'Apache Access', value: 'apache_access' },
{ abbr: 'WIN', label: 'Windows', value: 'windows' },
{ abbr: 'AD', label: 'AD/LDAP', value: 'ad_ldap' },
{ abbr: 'LNX', label: 'Linux', value: 'linux' },
{ abbr: 'CLT', label: 'Cloudtrail', value: 'cloudtrail' },
{ abbr: 'S3', label: 'S3', value: 's3' },
{ abbr: 'GGL', label: 'Google Workspace', value: 'gworkspace' },
{ abbr: 'GHB', label: 'Github actions', value: 'github' },
{ abbr: 'MSO', label: 'Microsoft 365', value: 'm365' },
{ abbr: 'OKT', label: 'Okta', value: 'okta' },
{ abbr: 'AZR', label: 'Azure', value: 'azure' },
{ abbr: 'VPC', label: 'VPC Flow', value: 'vpcflow' },
];
export const ruleTypes: { label: string; value: string; abbr: string }[] = [];

const paletteColors = euiPaletteForStatus(5);

Expand Down
46 changes: 30 additions & 16 deletions public/security_analytics_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import SavedObjectService from './services/SavedObjectService';
import { SecurityAnalyticsPluginStartDeps } from './plugin';
import { DataStore } from './store/DataStore';
import CorrelationService from './services/CorrelationService';
import { LogType } from '../types';
import { ruleTypes } from './pages/Rules/utils/constants';

export function renderApp(
coreStart: CoreStart,
Expand Down Expand Up @@ -68,22 +70,34 @@ export function renderApp(

const isDarkMode = coreStart.uiSettings.get('theme:darkMode') || false;
DataStore.init(services, coreStart.notifications);
DataStore.logTypes.getLogTypes().then((logTypes: LogType[]) => {
ruleTypes.splice(
0,
0,
...logTypes.map((logType) => ({
label: logType.name,
value: logType.id,
abbr: '',
}))
);

ReactDOM.render(
<Router>
<Route
render={(props) => (
<DarkModeContext.Provider value={isDarkMode}>
<ServicesContext.Provider value={services}>
<CoreServicesContext.Provider value={coreStart}>
<Main {...props} landingPage={landingPage} />
</CoreServicesContext.Provider>
</ServicesContext.Provider>
</DarkModeContext.Provider>
)}
/>
</Router>,
params.element
);
});

ReactDOM.render(
<Router>
<Route
render={(props) => (
<DarkModeContext.Provider value={isDarkMode}>
<ServicesContext.Provider value={services}>
<CoreServicesContext.Provider value={coreStart}>
<Main {...props} landingPage={landingPage} />
</CoreServicesContext.Provider>
</ServicesContext.Provider>
</DarkModeContext.Provider>
)}
/>
</Router>,
params.element
);
return () => ReactDOM.unmountComponentAtNode(params.element);
}
3 changes: 1 addition & 2 deletions public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { SimpleSavedObject } from 'opensearch-dashboards/public';
import { Detector, ServerResponse } from '../../types';
import { DetectorInput, PeriodSchedule } from '../../models/interfaces';
import { DetectorHit } from '../../server/models/interfaces';
import { DETECTOR_TYPES } from '../pages/Detectors/utils/constants';

export const DATE_MATH_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
export const MAX_RECENTLY_USED_TIME_RANGES = 5;
Expand Down Expand Up @@ -142,7 +141,7 @@ export const EMPTY_DEFAULT_DETECTOR_INPUT: DetectorInput = {

export const EMPTY_DEFAULT_DETECTOR: Detector = {
type: 'detector',
detector_type: DETECTOR_TYPES.NETWORK.id,
detector_type: 'network',
name: '',
enabled: true,
createdBy: '',
Expand Down

0 comments on commit 29fb641

Please sign in to comment.