-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#55277) * adds logic for returning / updating status when a rule is switched from enabled to disabled and vice versa. * update response for find rules statuses to include current status and failures * update status on demand and on enable/disable * adds ternary to allow removal of 'let' * adds savedObjectsClient to the add and upate prepackaged rules and import rules route. * fix bug where convertToSnakeCase would throw error 'cannot convert null or undefined to object' if passed null * genericize snake_case converter and updates isAuthorized to snake_case (different situation) * renaming to 'going to run' instead of executing because when task manager exits because of api key error it won't write the error status so the actual status is 'going to run' on the next interval. This is more accurate than being stuck on 'executing' because of an error we don't control and can't write a status for. * fix missed merge conflict Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com> Co-authored-by: Xavier Mouligneau <189600+XavierM@users.noreply.github.com>
- Loading branch information
Showing
25 changed files
with
310 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,5 +96,5 @@ export interface Privilege { | |
write: boolean; | ||
}; | ||
}; | ||
isAuthenticated: boolean; | ||
is_authenticated: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_status/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { RuleStatusType } from '../../../../../containers/detection_engine/rules'; | ||
|
||
export const getStatusColor = (status: RuleStatusType | string | null) => | ||
status == null | ||
? 'subdued' | ||
: status === 'succeeded' | ||
? 'success' | ||
: status === 'failed' | ||
? 'danger' | ||
: status === 'executing' || status === 'going to run' | ||
? 'warning' | ||
: 'subdued'; |
99 changes: 99 additions & 0 deletions
99
.../legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_status/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
EuiButtonIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHealth, | ||
EuiLoadingSpinner, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { isEqual } from 'lodash/fp'; | ||
import React, { memo, useCallback, useEffect, useState } from 'react'; | ||
|
||
import { useRuleStatus, RuleInfoStatus } from '../../../../../containers/detection_engine/rules'; | ||
import { FormattedDate } from '../../../../../components/formatted_date'; | ||
import { getEmptyTagValue } from '../../../../../components/empty_value'; | ||
import { getStatusColor } from './helpers'; | ||
import * as i18n from './translations'; | ||
|
||
interface RuleStatusProps { | ||
ruleId: string | null; | ||
ruleEnabled?: boolean | null; | ||
} | ||
|
||
const RuleStatusComponent: React.FC<RuleStatusProps> = ({ ruleId, ruleEnabled }) => { | ||
const [loading, ruleStatus, fetchRuleStatus] = useRuleStatus(ruleId); | ||
const [myRuleEnabled, setMyRuleEnabled] = useState<boolean | null>(ruleEnabled ?? null); | ||
const [currentStatus, setCurrentStatus] = useState<RuleInfoStatus | null>( | ||
ruleStatus?.current_status ?? null | ||
); | ||
|
||
useEffect(() => { | ||
if (myRuleEnabled !== ruleEnabled && fetchRuleStatus != null && ruleId != null) { | ||
fetchRuleStatus(ruleId); | ||
if (myRuleEnabled !== ruleEnabled) { | ||
setMyRuleEnabled(ruleEnabled ?? null); | ||
} | ||
} | ||
}, [fetchRuleStatus, myRuleEnabled, ruleId, ruleEnabled, setMyRuleEnabled]); | ||
|
||
useEffect(() => { | ||
if (!isEqual(currentStatus, ruleStatus?.current_status)) { | ||
setCurrentStatus(ruleStatus?.current_status ?? null); | ||
} | ||
}, [currentStatus, ruleStatus, setCurrentStatus]); | ||
|
||
const handleRefresh = useCallback(() => { | ||
if (fetchRuleStatus != null && ruleId != null) { | ||
fetchRuleStatus(ruleId); | ||
} | ||
}, [fetchRuleStatus, ruleId]); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="xs" alignItems="center" justifyContent="flexStart"> | ||
<EuiFlexItem grow={false}> | ||
{i18n.STATUS} | ||
{':'} | ||
</EuiFlexItem> | ||
{loading && ( | ||
<EuiFlexItem> | ||
<EuiLoadingSpinner size="m" data-test-subj="rule-status-loader" /> | ||
</EuiFlexItem> | ||
)} | ||
{!loading && ( | ||
<> | ||
<EuiFlexItem grow={false}> | ||
<EuiHealth color={getStatusColor(currentStatus?.status ?? null)}> | ||
<EuiText size="xs">{currentStatus?.status ?? getEmptyTagValue()}</EuiText> | ||
</EuiHealth> | ||
</EuiFlexItem> | ||
{currentStatus?.status_date != null && currentStatus?.status != null && ( | ||
<> | ||
<EuiFlexItem grow={false}> | ||
<>{i18n.STATUS_AT}</> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<FormattedDate value={currentStatus?.status_date} fieldName={i18n.STATUS_DATE} /> | ||
</EuiFlexItem> | ||
</> | ||
)} | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonIcon | ||
color="primary" | ||
onClick={handleRefresh} | ||
iconType="refresh" | ||
aria-label={i18n.REFRESH} | ||
/> | ||
</EuiFlexItem> | ||
</> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
export const RuleStatus = memo(RuleStatusComponent); |
29 changes: 29 additions & 0 deletions
29
...y/plugins/siem/public/pages/detection_engine/rules/components/rule_status/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const STATUS = i18n.translate('xpack.siem.detectionEngine.ruleStatus.statusDescription', { | ||
defaultMessage: 'Status', | ||
}); | ||
|
||
export const STATUS_AT = i18n.translate( | ||
'xpack.siem.detectionEngine.ruleStatus.statusAtDescription', | ||
{ | ||
defaultMessage: 'at', | ||
} | ||
); | ||
|
||
export const STATUS_DATE = i18n.translate( | ||
'xpack.siem.detectionEngine.ruleStatus.statusDateDescription', | ||
{ | ||
defaultMessage: 'Status date', | ||
} | ||
); | ||
|
||
export const REFRESH = i18n.translate('xpack.siem.detectionEngine.ruleStatus.refreshButton', { | ||
defaultMessage: 'Refresh', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.