Skip to content

Commit

Permalink
Fetch currently running MWs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaindik committed Apr 21, 2023
1 parent 3e3039e commit 884db2a
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
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;
};
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",
}
);
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 });
},
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { RulesTableContextProvider } from '../../components/rules_table/rules_ta
import * as i18n from '../../../../detections/pages/detection_engine/rules/translations';
import { useInvalidateFetchRuleManagementFiltersQuery } from '../../../rule_management/api/hooks/use_fetch_rule_management_filters_query';

import { MaintenanceWindowCallout } from '../../components/maintenance_window_callout/maintenance_window_callout';

const RulesPageComponent: React.FC = () => {
const [isImportModalVisible, showImportModal, hideImportModal] = useBoolState();
const [isValueListFlyoutVisible, showValueListFlyout, hideValueListFlyout] = useBoolState();
Expand Down Expand Up @@ -158,6 +160,7 @@ const RulesPageComponent: React.FC = () => {
prePackagedTimelineStatus === 'timelineNeedUpdate') && (
<UpdatePrePackagedRulesCallOut data-test-subj="update-callout-button" />
)}
<MaintenanceWindowCallout />
<AllRules data-test-subj="all-rules" />
</SecuritySolutionPageWrapper>
</RulesTableContextProvider>
Expand Down

0 comments on commit 884db2a

Please sign in to comment.