Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan committed Sep 11, 2024
1 parent 58fc39f commit 02ccde7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 19 deletions.
43 changes: 34 additions & 9 deletions public/pages/Findings/containers/Findings/Findings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import {
BREADCRUMBS,
DEFAULT_DATE_RANGE,
DEFAULT_EMPTY_DATA,
FindingTabId,
MAX_RECENTLY_USED_TIME_RANGES,
} from '../../../../utils/constants';
Expand All @@ -49,6 +50,7 @@ import {
getDuration,
getIsNotificationPluginInstalled,
setBreadcrumbs,
isThreatIntelQuery,
} from '../../../../utils/helpers';
import { RuleSource } from '../../../../../server/models/interfaces';
import { NotificationsStart } from 'opensearch-dashboards/public';
Expand All @@ -66,6 +68,7 @@ import {
} from '../../../../../types';
import { ThreatIntelFindingsTable } from '../../components/FindingsTable/ThreatIntelFindingsTable';
import { PageHeader } from '../../../../components/PageHeader/PageHeader';
import { RuleSeverityValue, RuleSeverityPriority } from '../../../Rules/utils/constants';

interface FindingsProps extends RouteComponentProps, DataSourceProps {
detectorService: DetectorsService;
Expand Down Expand Up @@ -436,7 +439,8 @@ class Findings extends Component<FindingsProps, FindingsState> {
const ruleLevel =
finding.detectionType === 'Threat intelligence'
? 'high'
: (findingsState as DetectionRulesFindingsState).rules[finding.queries[0].id].level;
: (findingsState as DetectionRulesFindingsState).rules[finding.queries[0].id]?.level ||
DEFAULT_EMPTY_DATA;
visData.push({
finding: 1,
time: findingTime.getTime(),
Expand Down Expand Up @@ -521,13 +525,30 @@ class Findings extends Component<FindingsProps, FindingsState> {
} = this.props;
if (selectedTabId === FindingTabId.DetectionRules && Object.keys(rules).length > 0) {
findings = findings.map((finding: any) => {
const rule = rules[finding.queries[0].id];
if (rule) {
finding['ruleName'] = rule.title;
finding['ruleSeverity'] =
rule.level === 'critical' ? rule.level : finding['ruleSeverity'] || rule.level;
finding['tags'] = rule.tags;
}
const matchedRules: RuleSource[] = [];
finding.queries.forEach((query: any) => {
if (rules[query.id]) {
matchedRules.push(rules[query.id]);
}
});

matchedRules.sort((a, b) => {
return RuleSeverityPriority[a.level as RuleSeverityValue] <
RuleSeverityPriority[b.level as RuleSeverityValue]
? -1
: 1;
});

finding['ruleName'] =
matchedRules[0]?.title ||
(finding.queries.find(({ id }) => isThreatIntelQuery(id))
? 'Threat intel'
: DEFAULT_EMPTY_DATA);
finding['ruleSeverity'] =
matchedRules[0]?.level === 'critical'
? 'critical'
: finding['ruleSeverity'] || matchedRules[0]?.level || DEFAULT_EMPTY_DATA;
finding['tags'] = matchedRules[0]?.tags || [];
return finding;
});
}
Expand Down Expand Up @@ -625,7 +646,11 @@ class Findings extends Component<FindingsProps, FindingsState> {
<EuiFlexItem>
{!findings || findings.length === 0 ? (
<EuiEmptyPrompt
title={<EuiText size="s"><h2>No findings</h2></EuiText>}
title={
<EuiText size="s">
<h2>No findings</h2>
</EuiText>
}
body={
<EuiText size="s">
{this.state.findingStateByTabId[this.state.selectedTabId].emptyPromptBody}
Expand Down
36 changes: 26 additions & 10 deletions public/pages/Rules/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ export const ruleTypes: {

const paletteColors = euiPaletteForStatus(5);

export enum RuleSeverityValue {
Critical = 'critical',
High = 'high',
Medium = 'medium',
Low = 'low',
Informational = 'informational',
}

export const RuleSeverityPriority: Record<RuleSeverityValue, string> = {
[RuleSeverityValue.Critical]: '1',
[RuleSeverityValue.High]: '2',
[RuleSeverityValue.Medium]: '3',
[RuleSeverityValue.Low]: '4',
[RuleSeverityValue.Informational]: '5',
};

export const ruleSeverity: {
name: string;
value: string;
Expand All @@ -23,32 +39,32 @@ export const ruleSeverity: {
}[] = [
{
name: 'Critical',
value: 'critical',
priority: '1',
value: RuleSeverityValue.Critical,
priority: RuleSeverityPriority[RuleSeverityValue.Critical],
color: { background: paletteColors[4], text: 'white' },
},
{
name: 'High',
value: 'high',
priority: '2',
value: RuleSeverityValue.High,
priority: RuleSeverityPriority[RuleSeverityValue.High],
color: { background: paletteColors[3], text: 'white' },
},
{
name: 'Medium',
value: 'medium',
priority: '3',
value: RuleSeverityValue.Medium,
priority: RuleSeverityPriority[RuleSeverityValue.Medium],
color: { background: paletteColors[2], text: 'black' },
},
{
name: 'Low',
value: 'low',
priority: '4',
value: RuleSeverityValue.Low,
priority: RuleSeverityPriority[RuleSeverityValue.Low],
color: { background: paletteColors[1], text: 'white' },
},
{
name: 'Informational',
value: 'informational',
priority: '5',
value: RuleSeverityValue.Informational,
priority: RuleSeverityPriority[RuleSeverityValue.Informational],
color: { background: paletteColors[0], text: 'white' },
},
];
Expand Down

0 comments on commit 02ccde7

Please sign in to comment.