-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e3039e
commit 884db2a
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...e/rule_management_ui/components/maintenance_window_callout/maintenance_window_callout.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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiCallOut } from '@elastic/eui'; | ||
import { useFetchRunningMaintenanceWindows } from './use_fetch_running_maintenance_windows'; | ||
import * as i18n from './translations'; | ||
|
||
export const MaintenanceWindowCallout = () => { | ||
const { data } = useFetchRunningMaintenanceWindows(); | ||
const runningMaintenanceWindows = data || []; | ||
|
||
if (runningMaintenanceWindows.length > 0) { | ||
return ( | ||
<EuiCallOut title={i18n.MAINTENANCE_WINDOW_RUNNING} color="warning" iconType="iInCircle"> | ||
{i18n.MAINTENANCE_WINDOW_RUNNING_DESCRIPTION} | ||
</EuiCallOut> | ||
); | ||
} | ||
|
||
return null; | ||
}; |
36 changes: 36 additions & 0 deletions
36
...detection_engine/rule_management_ui/components/maintenance_window_callout/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,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const FETCH_ERROR = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.ruleManagementUi.maintenanceWindowCallout.fetchError', | ||
{ | ||
defaultMessage: 'Failed to check if maintenance window is running', | ||
} | ||
); | ||
|
||
export const FETCH_ERROR_DESCRIPTION = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.ruleManagementUi.maintenanceWindowCallout.fetchErrorDescription', | ||
{ | ||
defaultMessage: "Notification actions won't run while the maintenance window is running.", | ||
} | ||
); | ||
|
||
export const MAINTENANCE_WINDOW_RUNNING = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.ruleManagementUi.maintenanceWindowCallout.maintenanceWindowRunning', | ||
{ | ||
defaultMessage: 'A maintenance window is currently running.', | ||
} | ||
); | ||
|
||
export const MAINTENANCE_WINDOW_RUNNING_DESCRIPTION = i18n.translate( | ||
'xpack.securitySolution.detectionEngine.ruleManagementUi.maintenanceWindowCallout.maintenanceWindowRunningDescription', | ||
{ | ||
defaultMessage: "Notification actions won't run while the maintenance window is running", | ||
} | ||
); |
39 changes: 39 additions & 0 deletions
39
...agement_ui/components/maintenance_window_callout/use_fetch_running_maintenance_windows.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,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
import type { MaintenanceWindow } from '@kbn/alerting-plugin/common/maintenance_window'; | ||
import { INTERNAL_BASE_ALERTING_API_PATH } from '@kbn/alerting-plugin/common'; | ||
import { useAppToasts } from '../../../../common/hooks/use_app_toasts'; | ||
import { KibanaServices } from '../../../../common/lib/kibana'; | ||
import * as i18n from './translations'; | ||
|
||
const GET_RUNNING_MAINTENANCE_WINDOWS_URL = `${INTERNAL_BASE_ALERTING_API_PATH}/rules/maintenance_window/_active`; | ||
|
||
export const fetchRunningMaintenanceWindows = async ( | ||
signal?: AbortSignal | ||
): Promise<MaintenanceWindow[]> => { | ||
return KibanaServices.get().http.fetch(GET_RUNNING_MAINTENANCE_WINDOWS_URL, { | ||
method: 'GET', | ||
signal, | ||
}); | ||
}; | ||
|
||
export const useFetchRunningMaintenanceWindows = () => { | ||
const { addError } = useAppToasts(); | ||
|
||
return useQuery( | ||
['GET', GET_RUNNING_MAINTENANCE_WINDOWS_URL], | ||
({ signal }) => fetchRunningMaintenanceWindows(signal), | ||
{ | ||
refetchInterval: 60000, | ||
onError: (error) => { | ||
addError(error, { title: i18n.FETCH_ERROR, toastMessage: i18n.FETCH_ERROR_DESCRIPTION }); | ||
}, | ||
} | ||
); | ||
}; |
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