Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export const DYNAMIC_SETTINGS_DEFAULTS: DynamicSettings = {
cc: [],
bcc: [],
},
defaultTLSRuleEnabled: true,
defaultStatusRuleEnabled: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const DynamicSettingsCodec = t.intersection([
}),
t.partial({
defaultEmail: DefaultEmailCodec,
defaultTLSRuleEnabled: t.boolean,
defaultStatusRuleEnabled: t.boolean,
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const OverviewPendingStatusMetaDataCodec = t.intersection([
monitorQueryId: t.string,
configId: t.string,
status: t.string,
location: t.string,
locationId: t.string,
}),
t.partial({
timestamp: t.string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { SanitizedRule, SanitizedRuleAction, RuleSystemAction } from '@kbn/alerting-plugin/common';
import { SYNTHETICS_STATUS_RULE, SYNTHETICS_TLS_RULE } from '../constants/synthetics_alerts';

export type DefaultRuleType = typeof SYNTHETICS_STATUS_RULE | typeof SYNTHETICS_TLS_RULE;
type SYNTHETICS_DEFAULT_RULE = Omit<SanitizedRule<{}>, 'systemActions' | 'actions'> & {
actions: Array<SanitizedRuleAction | RuleSystemAction>;
ruleTypeId: SanitizedRule['alertTypeId'];
};

export interface DEFAULT_ALERT_RESPONSE {
statusRule: SYNTHETICS_DEFAULT_RULE | null;
tlsRule: SYNTHETICS_DEFAULT_RULE | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@

export * from './synthetics_monitor';
export * from './monitor_validation';
export * from './default_alerts';
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '../../../state';
import { ClientPluginsStart } from '../../../../../plugin';

export const useSyntheticsAlert = (isOpen: boolean) => {
export const useSyntheticsRules = (isOpen: boolean) => {
const dispatch = useDispatch();

const defaultRules = useSelector(selectSyntheticsAlerts);
Expand Down Expand Up @@ -64,14 +64,15 @@ export const useSyntheticsAlert = (isOpen: boolean) => {
const { triggersActionsUi } = useKibana<ClientPluginsStart>().services;

const EditAlertFlyout = useMemo(() => {
if (!defaultRules) {
const initialRule =
alertFlyoutVisible === SYNTHETICS_TLS_RULE ? defaultRules?.tlsRule : defaultRules?.statusRule;
if (!initialRule) {
return null;
}
return triggersActionsUi.getEditRuleFlyout({
onClose: () => dispatch(setAlertFlyoutVisible(null)),
hideInterval: true,
initialRule:
alertFlyoutVisible === SYNTHETICS_TLS_RULE ? defaultRules.tlsRule : defaultRules.statusRule,
initialRule,
});
}, [defaultRules, dispatch, triggersActionsUi, alertFlyoutVisible]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { ManageRulesLink } from '../common/links/manage_rules_link';
import { ClientPluginsStart } from '../../../../plugin';
import { ToggleFlyoutTranslations } from './hooks/translations';
import { useSyntheticsAlert } from './hooks/use_synthetics_alert';
import { useSyntheticsRules } from './hooks/use_synthetics_rules';
import {
selectAlertFlyoutVisibility,
selectMonitorListState,
Expand All @@ -40,7 +40,7 @@ export const ToggleAlertFlyoutButton = () => {
const { application } = useKibana<ClientPluginsStart>().services;
const hasUptimeWrite = application?.capabilities.uptime?.save ?? false;

const { EditAlertFlyout, loading } = useSyntheticsAlert(isOpen);
const { EditAlertFlyout, loading } = useSyntheticsRules(isOpen);

const { loaded, data: monitors } = useSelector(selectMonitorListState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiFlexItem,
EuiForm,
EuiSpacer,
EuiSwitch,
} from '@elastic/eui';
import { useDispatch, useSelector } from 'react-redux';
import { useKibana } from '@kbn/kibana-react-plugin/public';
Expand Down Expand Up @@ -80,6 +81,50 @@ export const AlertDefaultsForm = () => {

return (
<EuiForm>
<EuiSpacer size="m" />
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.synthetics.settings.defaultConnectors"
defaultMessage="Default rules"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.synthetics.settings.defaultConnectors.description"
defaultMessage="Default rules are automatically created. You can disable creation of default rules here."
/>
}
>
<EuiSpacer size="s" />
<EuiSwitch
label={i18n.translate('xpack.synthetics.ruleStatusDefaultsForm.euiSwitch.enabledLabel', {
defaultMessage: 'Status rule enabled',
})}
checked={formFields?.defaultStatusRuleEnabled ?? true}
onChange={() => {
setFormFields({
...formFields,
defaultStatusRuleEnabled: !(formFields.defaultStatusRuleEnabled ?? true),
});
}}
/>
<EuiSpacer size="m" />
<EuiSwitch
label={i18n.translate('xpack.synthetics.ruleTLSDefaultsForm.euiSwitch.enabledLabel', {
defaultMessage: 'TLS rule enabled',
})}
checked={formFields?.defaultTLSRuleEnabled ?? true}
onChange={() => {
setFormFields({
...formFields,
defaultTLSRuleEnabled: !(formFields.defaultTLSRuleEnabled ?? true),
});
}}
/>
</EuiDescribedFormGroup>
<EuiSpacer size="m" />
<EuiDescribedFormGroup
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('useMonitorsSortedByStatus', () => {
[`test-monitor-4-${location1.id}`]: {
configId: 'test-monitor-4',
monitorQueryId: 'test-monitor-4',
location: location1.id,
locationId: location1.id,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@
* 2.0.
*/

import { Rule } from '@kbn/triggers-actions-ui-plugin/public';
import { DEFAULT_ALERT_RESPONSE } from '../../../../../common/types/default_alerts';
import { createAsyncAction } from '../utils/actions';

export const getDefaultAlertingAction = createAsyncAction<
void,
{ statusRule: Rule; tlsRule: Rule }
>('getDefaultAlertingAction');
export const getDefaultAlertingAction = createAsyncAction<void, DEFAULT_ALERT_RESPONSE>(
'getDefaultAlertingAction'
);

export const enableDefaultAlertingAction = createAsyncAction<
void,
{ statusRule: Rule; tlsRule: Rule }
>('enableDefaultAlertingAction');
export const enableDefaultAlertingAction = createAsyncAction<void, DEFAULT_ALERT_RESPONSE>(
'enableDefaultAlertingAction'
);

export const enableDefaultAlertingSilentlyAction = createAsyncAction<
void,
{ statusRule: Rule; tlsRule: Rule }
>('enableDefaultAlertingSilentlyAction');
export const enableDefaultAlertingSilentlyAction = createAsyncAction<void, DEFAULT_ALERT_RESPONSE>(
'enableDefaultAlertingSilentlyAction'
);

export const updateDefaultAlertingAction = createAsyncAction<void, Rule>(
export const updateDefaultAlertingAction = createAsyncAction<void, DEFAULT_ALERT_RESPONSE>(
'updateDefaultAlertingAction'
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* 2.0.
*/

import { Rule } from '@kbn/triggers-actions-ui-plugin/public';
import { SYNTHETICS_API_URLS } from '../../../../../common/constants';
import { DEFAULT_ALERT_RESPONSE } from '../../../../../common/types/default_alerts';
import { apiService } from '../../../../utils/api_service';

export async function getDefaultAlertingAPI(): Promise<{ statusRule: Rule; tlsRule: Rule }> {
export async function getDefaultAlertingAPI(): Promise<DEFAULT_ALERT_RESPONSE> {
return apiService.get(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING);
}

export async function enableDefaultAlertingAPI(): Promise<{ statusRule: Rule; tlsRule: Rule }> {
export async function enableDefaultAlertingAPI(): Promise<DEFAULT_ALERT_RESPONSE> {
return apiService.post(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING);
}

export async function updateDefaultAlertingAPI(): Promise<Rule> {
export async function updateDefaultAlertingAPI(): Promise<DEFAULT_ALERT_RESPONSE> {
return apiService.put(SYNTHETICS_API_URLS.ENABLE_DEFAULT_ALERTING);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { createReducer } from '@reduxjs/toolkit';
import { Rule } from '@kbn/triggers-actions-ui-plugin/public';
import { DEFAULT_ALERT_RESPONSE } from '../../../../../common/types/default_alerts';
import { IHttpSerializedFetchError } from '..';
import {
enableDefaultAlertingAction,
Expand All @@ -16,7 +16,7 @@ import {
} from './actions';

export interface DefaultAlertingState {
data?: { statusRule: Rule; tlsRule: Rule };
data?: DEFAULT_ALERT_RESPONSE;
success: boolean | null;
loading: boolean;
error: IHttpSerializedFetchError | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ export const getDynamicSettings = async (): Promise<DynamicSettings> => {
export const setDynamicSettings = async ({
settings,
}: SaveApiRequest): Promise<DynamicSettingsSaveResponse> => {
const newSettings: DynamicSettings = {
certAgeThreshold: settings.certAgeThreshold,
certExpirationThreshold: settings.certExpirationThreshold,
defaultConnectors: settings.defaultConnectors,
defaultEmail: settings.defaultEmail,
defaultTLSRuleEnabled: settings.defaultTLSRuleEnabled,
defaultStatusRuleEnabled: settings.defaultStatusRuleEnabled,
};
return await apiService.put(
SYNTHETICS_API_URLS.DYNAMIC_SETTINGS,
settings,
newSettings,
DynamicSettingsSaveCodec,
{
version: '2023-10-31',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ describe('setRecoveredAlertsContext', () => {
alertDetailsUrl: 'https://localhost:5601/app/observability/alerts/alert-id',
monitorName: 'test-monitor',
recoveryReason: 'the monitor has been deleted',
'kibana.alert.reason': 'the monitor has been deleted',
recoveryStatus: 'has been deleted',
monitorUrl: '(unavailable)',
monitorUrlLabel: 'URL',
Expand Down Expand Up @@ -350,6 +351,7 @@ describe('setRecoveredAlertsContext', () => {
alertDetailsUrl: 'https://localhost:5601/app/observability/alerts/alert-id',
monitorName: 'test-monitor',
recoveryReason: 'this location has been removed from the monitor',
'kibana.alert.reason': 'this location has been removed from the monitor',
recoveryStatus: 'has recovered',
stateId: '123456',
status: 'recovered',
Expand Down Expand Up @@ -421,6 +423,8 @@ describe('setRecoveredAlertsContext', () => {
status: 'up',
recoveryReason:
'the monitor is now up again. It ran successfully at Feb 26, 2023 @ 00:00:00.000',
'kibana.alert.reason':
'the monitor is now up again. It ran successfully at Feb 26, 2023 @ 00:00:00.000',
recoveryStatus: 'is now up',
locationId: location,
checkedAt: 'Feb 26, 2023 @ 00:00:00.000',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { i18n } from '@kbn/i18n';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { legacyExperimentalFieldMap, ObservabilityUptimeAlert } from '@kbn/alerts-as-data-utils';
import { PublicAlertsClient } from '@kbn/alerting-plugin/server/alerts_client/types';
import { ALERT_REASON } from '@kbn/rule-data-utils';
import { syntheticsRuleFieldMap } from '../../common/rules/synthetics_rule_field_map';
import { combineFiltersAndUserSearch, stringifyKueries } from '../../common/lib';
import {
Expand Down Expand Up @@ -298,6 +299,7 @@ export const setRecoveredAlertsContext = ({
linkMessage,
...(isUp ? { status: 'up' } : {}),
...(recoveryReason ? { [RECOVERY_REASON]: recoveryReason } : {}),
...(recoveryReason ? { [ALERT_REASON]: recoveryReason } : {}),
...(basePath && spaceId && alertUuid
? { [ALERT_DETAILS_URL]: getAlertDetailsUrl(basePath, spaceId, alertUuid) }
: {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class StatusRuleExecutor {
monitorLocationMap,
projectMonitorsCount,
monitorQueryIdToConfigIdMap,
} = processMonitors(this.monitors, this.server, this.soClient, this.syntheticsMonitorClient);
} = processMonitors(this.monitors);

return {
enabledMonitorQueryIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class TLSRuleExecutor {
monitorLocationMap,
projectMonitorsCount,
monitorQueryIdToConfigIdMap,
} = processMonitors(this.monitors, this.server, this.soClient, this.syntheticsMonitorClient);
} = processMonitors(this.monitors);

return {
enabledMonitorQueryIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export async function queryMonitorStatus(
configId: `${monitorQueryIdToConfigIdMap[queryId]}`,
monitorQueryId: queryId,
status: 'unknown',
location: loc,
locationId: loc,
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ export const getSyntheticsCertsRoute: SyntheticsRestApiRouteFactory<
to: schema.maybe(schema.string()),
}),
},
handler: async ({
request,
syntheticsEsClient,
savedObjectsClient,
server,
syntheticsMonitorClient,
}) => {
handler: async ({ request, syntheticsEsClient, savedObjectsClient }) => {
const queryParams = request.query;

const monitors = await getAllMonitors({
Expand All @@ -57,12 +51,7 @@ export const getSyntheticsCertsRoute: SyntheticsRestApiRouteFactory<
};
}

const { enabledMonitorQueryIds } = processMonitors(
monitors,
server,
savedObjectsClient,
syntheticsMonitorClient
);
const { enabledMonitorQueryIds } = processMonitors(monitors);

const data = await getSyntheticsCerts({
...queryParams,
Expand Down
Loading