Skip to content

Commit

Permalink
updated log types; fixed bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Oct 13, 2023
1 parent f90e49b commit 4983178
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 32 deletions.
12 changes: 7 additions & 5 deletions public/pages/Correlations/containers/CreateCorrelationRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
formikErrors: FormikErrors<CorrelationRuleModel>,
props: any
) => {
const logTypeOptions = ruleTypes.map(({ value, label }) => ({
value,
label,
}));

return (
<>
{correlationQueries.map((query, queryIdx) => {
Expand Down Expand Up @@ -274,10 +279,7 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
isInvalid={isInvalidInputForQuery('logType')}
placeholder="Select a log type"
data-test-subj={'rule_type_dropdown'}
options={ruleTypes.map(({ label }) => ({
value: label.toLowerCase(),
label,
}))}
options={logTypeOptions}
singleSelection={{ asPlainText: true }}
onChange={(e) => {
props.handleChange(`queries[${queryIdx}].logType`)(
Expand All @@ -293,7 +295,7 @@ export const CreateCorrelationRule: React.FC<CreateCorrelationRuleProps> = (
label:
ruleTypes.find(
(logType) =>
logType.label.toLowerCase() === query.logType.toLowerCase()
logType.value.toLowerCase() === query.logType.toLowerCase()
)?.label || query.logType,
},
]
Expand Down
5 changes: 3 additions & 2 deletions public/pages/Correlations/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CorrelationGraphData } from '../../../../types';
import { ruleSeverity, ruleTypes } from '../../Rules/utils/constants';
import { FilterItem } from '../components/FilterGroup';
import { EuiIcon } from '@elastic/eui';
import { getLogTypeLabel } from '../../LogTypes/utils/helpers';

export const graphRenderOptions = {
nodes: {
Expand Down Expand Up @@ -49,8 +50,8 @@ export const graphRenderOptions = {

export const getDefaultLogTypeFilterItemOptions: () => FilterItem[] = () =>
Object.values(ruleTypes).map((type) => ({
name: `${type.label}`,
id: type.label.toLowerCase(),
name: getLogTypeLabel(type.label),
id: type.value.toLowerCase(),
checked: 'on',
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EuiBasicTableColumn, EuiLink, EuiSwitch } from '@elastic/eui';
import { capitalizeFirstLetter } from '../../../../../../../utils/helpers';
import React, { ReactNode } from 'react';
import { RuleItem } from '../types/interfaces';
import { getLogTypeLabel } from '../../../../../../LogTypes/utils/helpers';

export type ActiveToggleOnChangeEvent = React.BaseSyntheticEvent<
React.MouseEvent<HTMLButtonElement>,
Expand Down Expand Up @@ -51,7 +52,7 @@ export const getRulesColumns = (
name: 'Log type',
width: '10%',
sortable: true,
render: (logType: string) => capitalizeFirstLetter(logType),
render: (logType: string) => getLogTypeLabel(logType),
},
{
field: 'library',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class DetectorType extends Component<DetectorTypeProps, DetectorT
constructor(props: DetectorTypeProps) {
super(props);

this.detectorTypeOptions = ruleTypes.map(({ label }) => ({ value: label, label }));
this.detectorTypeOptions = ruleTypes.map(({ value, label }) => ({ value, label }));
const detectorTypeIds = this.detectorTypeOptions.map((option) => option.value);
this.state = {
fieldTouched: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createTextDetailsGroup, parseSchedule } from '../../../../utils/helpers
import moment from 'moment';
import { DEFAULT_EMPTY_DATA, logTypesWithDashboards } from '../../../../utils/constants';
import { Detector } from '../../../../../types';
import { getLogTypeLabel } from '../../../LogTypes/utils/helpers';

export interface DetectorBasicDetailsViewProps {
detector: Detector;
Expand Down Expand Up @@ -77,7 +78,7 @@ export const DetectorBasicDetailsView: React.FC<DetectorBasicDetailsViewProps> =
</>
),
},
{ label: 'Log type', content: detector_type.toLowerCase() },
{ label: 'Log type', content: getLogTypeLabel(detector_type.toLowerCase()) },
{
label: 'Detector dashboard',
content: (dashboardId ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Object {
data-test-subj="text-details-group-content-log-type"
id="some_html_id"
>
detector_type
Detector Type
</div>
</div>
</div>
Expand Down Expand Up @@ -684,7 +684,7 @@ Object {
data-test-subj="text-details-group-content-log-type"
id="some_html_id"
>
detector_type
Detector Type
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ exports[`<DetectorDetails /> spec renders the component 1`] = `
onBlur={[Function]}
onFocus={[Function]}
>
detector_type
Detector Type
</div>
</EuiText>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ exports[`<DetectorDetailsView /> spec renders the component 1`] = `
onBlur={[Function]}
onFocus={[Function]}
>
detector_type
Detector Type
</div>
</EuiText>
</div>
Expand Down
4 changes: 2 additions & 2 deletions public/pages/Detectors/containers/Detectors/Detectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export default class Detectors extends Component<DetectorsProps, DetectorsState>
detectorHits.map((detector) => (detector._source.enabled ? 'Active' : 'Inactive'))
),
];
const logType = [...new Set(detectorHits.map((detector) => detector._source.detector_type))];
const logTypes = [...new Set(detectorHits.map((detector) => detector._source.detector_type))];
const search = {
box: {
placeholder: 'Search threat detectors',
Expand All @@ -318,7 +318,7 @@ export default class Detectors extends Component<DetectorsProps, DetectorsState>
type: 'field_value_selection',
field: 'logType',
name: 'Log type',
options: logType.map((logType) => ({
options: logTypes.map((logType) => ({
value: logType,
name: formatRuleType(logType),
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ exports[`<Detectors /> spec renders the component 1`] = `
"name": "Log type",
"options": Array [
Object {
"name": "-",
"name": "Detector Type",
"value": "detector_type",
},
],
Expand Down Expand Up @@ -671,7 +671,7 @@ exports[`<Detectors /> spec renders the component 1`] = `
"name": "Log type",
"options": Array [
Object {
"name": "-",
"name": "Detector Type",
"value": "detector_type",
},
],
Expand Down Expand Up @@ -802,7 +802,7 @@ exports[`<Detectors /> spec renders the component 1`] = `
"name": "Log type",
"options": Array [
Object {
"name": "-",
"name": "Detector Type",
"value": "detector_type",
},
],
Expand Down Expand Up @@ -977,7 +977,7 @@ exports[`<Detectors /> spec renders the component 1`] = `
"name": "Log type",
"options": Array [
Object {
"name": "-",
"name": "Detector Type",
"value": "detector_type",
},
],
Expand Down Expand Up @@ -2136,7 +2136,7 @@ exports[`<Detectors /> spec renders the component 1`] = `
<div
className="euiTableCellContent euiTableCellContent--overflowingContent"
>
-
Detector Type
</div>
</td>
</EuiTableRowCell>
Expand Down
2 changes: 1 addition & 1 deletion public/pages/LogTypes/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const defaultLogType: LogTypeBase = {
tags: null,
};

export const logTypeLabels = {
export const logTypeLabels: { [value: string]: string } = {
cloudtrail: 'AWS Cloudtrail',
dns: 'DNS',
vpcflow: 'VPC Flow',
Expand Down
5 changes: 3 additions & 2 deletions public/pages/LogTypes/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EuiButtonIcon, EuiLink, EuiToolTip } from '@elastic/eui';
import { LogType } from '../../../../types';
import { capitalize, startCase } from 'lodash';
import { logTypeLabels } from './constants';
import { DEFAULT_EMPTY_DATA } from '../../../utils/constants';

export const getLogTypesTableColumns = (
showDetails: (id: string) => void,
Expand Down Expand Up @@ -52,6 +53,6 @@ export const getLogTypesTableColumns = (
},
];

export const getLogTypeLabel = (name: String) => {
return logTypeLabels[name] || startCase(name);
export const getLogTypeLabel = (name: string) => {
return !name ? DEFAULT_EMPTY_DATA : logTypeLabels[name.toLowerCase()] || startCase(name);
};
5 changes: 3 additions & 2 deletions public/pages/Overview/components/Widgets/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { AlertItem, FindingItem } from '../../models/interfaces';
import { createSelectComponent, renderVisualization } from '../../../../utils/helpers';
import { ROUTES } from '../../../../utils/constants';
import { ChartContainer } from '../../../../components/Charts/ChartContainer';
import { getLogTypeLabel } from '../../../LogTypes/utils/helpers';

export interface SummaryProps {
findings: FindingItem[];
Expand Down Expand Up @@ -96,7 +97,7 @@ export const Summary: React.FC<SummaryProps> = ({
time: getTimeWithMinPrecision(alert.time),
alert: 1,
finding: 0,
logType: alert.logType,
logType: getLogTypeLabel(alert.logType),
});
});

Expand All @@ -105,7 +106,7 @@ export const Summary: React.FC<SummaryProps> = ({
time: getTimeWithMinPrecision(finding.time),
alert: 0,
finding: 1,
logType: finding.logType,
logType: getLogTypeLabel(finding.logType),
});
});

Expand Down
2 changes: 1 addition & 1 deletion public/pages/Rules/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const getRulesTableColumns = (
width: '10%',
truncateText: true,
render: (category: string) =>
ruleTypes.find((ruleType) => ruleType.label.toLowerCase() === category)?.label ||
ruleTypes.find((ruleType) => ruleType.value.toLowerCase() === category)?.label ||
DEFAULT_EMPTY_DATA,
},
{
Expand Down
2 changes: 1 addition & 1 deletion public/store/RulesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class RulesStore implements IRulesStore {

if (!terms) {
terms = {
'rule.category': ruleTypes.map(({ label }) => label.toLowerCase()),
'rule.category': ruleTypes.map(({ value }) => value.toLowerCase()),
};
} else if (terms['rule.category']) {
terms['rule.category'] = terms['rule.category'].map((category) => category.toLowerCase());
Expand Down
5 changes: 1 addition & 4 deletions public/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ export const getPlugins = async (opensearchService: OpenSearchService) => {
};

export const formatRuleType = (matchingRuleType: string) => {
const type = ruleTypes.find(
(ruleType) => ruleType.label.toLowerCase() === matchingRuleType.toLowerCase()
)?.label;
return type === undefined ? DEFAULT_EMPTY_DATA : getLogTypeLabel(type);
return getLogTypeLabel(matchingRuleType);
};

export const getSeverityBadge = (severity: string) => {
Expand Down

0 comments on commit 4983178

Please sign in to comment.