Skip to content

Commit

Permalink
custom field formatter for alerts risk score with helper
Browse files Browse the repository at this point in the history
  • Loading branch information
CAWilson94 committed Nov 1, 2024
1 parent be2a037 commit f23502c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const SIGNAL_STATUS_FIELD_NAME = 'kibana.alert.workflow_status';
export const AGENT_STATUS_FIELD_NAME = 'agent.status';
export const QUARANTINED_PATH_FIELD_NAME = 'quarantined.path';
export const REASON_FIELD_NAME = 'kibana.alert.reason';
export const RISK_SCORE = 'kibana.alert.risk_score';
export const EVENT_SUMMARY_FIELD_NAME = 'eventSummary';
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ import {
IP_FIELD_TYPE,
MESSAGE_FIELD_NAME,
REFERENCE_URL_FIELD_NAME,
RISK_SCORE,
RULE_REFERENCE_FIELD_NAME,
SIGNAL_RULE_NAME_FIELD_NAME,
SIGNAL_STATUS_FIELD_NAME,
USER_NAME_FIELD_NAME,
} from './constants';
import { renderEventModule, RenderRuleName, renderUrl } from './formatted_field_helpers';
import {
renderEventModule,
RenderRiskScore,
RenderRuleName,
renderUrl,
} from './formatted_field_helpers';
import { RuleStatus } from './rule_status';
import { HostName } from './host_name';
import { UserName } from './user_name';
Expand Down Expand Up @@ -239,6 +245,8 @@ const FormattedFieldValueComponent: React.FC<{
value={value}
/>
);
} else if (fieldName === RISK_SCORE) {
return value ? <RenderRiskScore value={value} /> : null;
} else if (fieldName === EVENT_MODULE_FIELD_NAME) {
return renderEventModule({
contextId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { SyntheticEvent } from 'react';
import React, { useCallback, useMemo, useContext } from 'react';
import styled from 'styled-components';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import { formatRiskScore } from '../../../../../entity_analytics/common';
import { DefaultDraggable } from '../../../../../common/components/draggables';
import { getEmptyTagValue } from '../../../../../common/components/empty_value';
import { getRuleDetailsUrl } from '../../../../../common/components/link_to/redirect_to_detection_engine';
Expand Down Expand Up @@ -382,3 +383,16 @@ export const renderUrl = ({
getEmptyTagValue()
);
};

interface RenderRiskScoreProps {
value: number | string;
}

export const RenderRiskScore: React.FC<RenderRiskScoreProps> = ({ value }) => {
return (
<span data-test-subj="risk-score-truncate" title={`${value}`}>
{/* Usually is a string */}
{formatRiskScore(Number(value))}
</span>
);
};

0 comments on commit f23502c

Please sign in to comment.