diff --git a/docs/management/advanced-options.asciidoc b/docs/management/advanced-options.asciidoc index 3d15b0504e85cf..0aad6c2f6c3851 100644 --- a/docs/management/advanced-options.asciidoc +++ b/docs/management/advanced-options.asciidoc @@ -103,7 +103,8 @@ Example: `{ "display": "15 seconds", "pause": true, "value": 15000 }`. `timepicker:timeDefaults`:: The default selection in the time filter. `truncate:maxHeight`:: The maximum height that a cell occupies in a table. Set to 0 to disable truncation. -`xPack:defaultAdminEmail`:: Email address for X-Pack admin operations, such as +`xPack:defaultAdminEmail`:: **Deprecated. Use <> instead.** +Email address for X-Pack admin operations, such as cluster alert notifications from Monitoring. diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 9b672d40961d8e..41d934895ef412 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -119,6 +119,7 @@ export class DocLinksService { dateMath: `${ELASTICSEARCH_DOCS}common-options.html#date-math`, }, management: { + kibanaGeneralSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-general-settings`, kibanaSearchSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-search-settings`, dashboardSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-dashboard-settings`, }, diff --git a/x-pack/legacy/plugins/xpack_main/index.js b/x-pack/legacy/plugins/xpack_main/index.js index aeabbb12928754..d4df995492db01 100644 --- a/x-pack/legacy/plugins/xpack_main/index.js +++ b/x-pack/legacy/plugins/xpack_main/index.js @@ -52,6 +52,13 @@ export const xpackMain = (kibana) => { defaultMessage: 'Recipient email address for X-Pack admin operations, such as Cluster Alert email notifications from Monitoring.', }), + deprecation: { + message: i18n.translate('xpack.main.uiSettings.adminEmailDeprecation', { + defaultMessage: + 'This setting is deprecated and will not be supported in Kibana 8.0. Please configure `monitoring.cluster_alerts.email_notifications.email_address` in your kibana.yml settings.', + }), + docLinksKey: 'kibanaGeneralSettings', + }, type: 'string', // TODO: Any way of ensuring this is a valid email address? value: null, }, diff --git a/x-pack/plugins/monitoring/common/constants.ts b/x-pack/plugins/monitoring/common/constants.ts index eeed7b4d5acf61..b781740bed7ad9 100644 --- a/x-pack/plugins/monitoring/common/constants.ts +++ b/x-pack/plugins/monitoring/common/constants.ts @@ -258,5 +258,6 @@ export const NUMBER_OF_MIGRATED_ALERTS = 2; * The advanced settings config name for the email address */ export const MONITORING_CONFIG_ALERTING_EMAIL_ADDRESS = 'monitoring:alertingEmailAddress'; +export const XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING = 'xPack:defaultAdminEmail'; export const ALERT_EMAIL_SERVICES = ['gmail', 'hotmail', 'icloud', 'outlook365', 'ses', 'yahoo']; diff --git a/x-pack/plugins/monitoring/server/core_services.ts b/x-pack/plugins/monitoring/server/core_services.ts new file mode 100644 index 00000000000000..54fbbf310b188f --- /dev/null +++ b/x-pack/plugins/monitoring/server/core_services.ts @@ -0,0 +1,48 @@ +/* + * 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 { CoreStart, CoreSetup } from 'kibana/server'; + +import { SavedObjectsClient } from '../../../../src/core/server'; + +export class CoreServices { + private static _coreSetup: CoreSetup; + private static _coreStart: CoreStart; + + public static init(core: CoreSetup) { + this._coreSetup = core; + } + + public static get coreSetup(): CoreSetup { + this.checkError(); + return this._coreSetup; + } + + public static async getCoreStart(): Promise { + if (this._coreStart) { + return this._coreStart; + } + const [coreStart] = await this.coreSetup.getStartServices(); + this._coreStart = coreStart; + return coreStart; + } + + public static async getUISetting(key: string) { + const coreStart = await this.getCoreStart(); + const { savedObjects, uiSettings } = coreStart; + const savedObjectsClient = new SavedObjectsClient(savedObjects.createInternalRepository()); + const theSettings = uiSettings.asScopedToClient(savedObjectsClient); + return await theSettings.get(key); + } + + private static checkError() { + if (!this._coreSetup) { + throw new Error( + 'CoreServices has not been initialized. Please run CoreServices.init(...) before use' + ); + } + } +} diff --git a/x-pack/plugins/monitoring/server/deprecations.ts b/x-pack/plugins/monitoring/server/deprecations.ts index d40837885e1983..71b54313f31938 100644 --- a/x-pack/plugins/monitoring/server/deprecations.ts +++ b/x-pack/plugins/monitoring/server/deprecations.ts @@ -44,12 +44,15 @@ export const deprecations = ({ ), renameFromRoot('xpack.monitoring', 'monitoring'), (config, fromPath, logger) => { - const clusterAlertsEnabled = get(config, 'cluster_alerts.enabled'); + const clusterAlertsEnabled = get(config, 'monitoring.cluster_alerts.enabled', true); const emailNotificationsEnabled = - clusterAlertsEnabled && get(config, 'cluster_alerts.email_notifications.enabled'); - if (emailNotificationsEnabled && !get(config, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) { + clusterAlertsEnabled && + get(config, 'monitoring.cluster_alerts.email_notifications.enabled', true); + const updatedKey = get(config, `monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`); + const legacyKey = get(config, `xpack.monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`); + if (emailNotificationsEnabled && !updatedKey && !legacyKey) { logger( - `Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 7.0."` + `Config key [${fromPath}.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}] will be required for email notifications to work in 8.0."` ); } return config; diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts index 1b7c127f64286b..7e04d4b34f63cc 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/collectors/get_settings_collector.ts @@ -4,15 +4,41 @@ * you may not use this file except in compliance with the Elastic License. */ -import { KIBANA_SETTINGS_TYPE } from '../../../common/constants'; +import { + KIBANA_SETTINGS_TYPE, + XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING, + CLUSTER_ALERTS_ADDRESS_CONFIG_KEY, +} from '../../../common/constants'; import { MonitoringConfig } from '../../config'; +import { CoreServices } from '../../core_services'; +import { Logger } from '../../../../../../src/core/server'; +let loggedDeprecationWarning = false; /* * Check if Cluster Alert email notifications is enabled in config * If so, use uiSettings API to fetch the X-Pack default admin email */ -export async function getDefaultAdminEmail(config: MonitoringConfig) { - return config.cluster_alerts.email_notifications.email_address || null; +export async function getDefaultAdminEmail(config: MonitoringConfig, log?: Logger) { + const { + email_notifications: { enabled, email_address: emailAddress }, + } = config.cluster_alerts; + + if (enabled && emailAddress?.length) { + return emailAddress; + } + + const defaultAdminEmail = await CoreServices.getUISetting(XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING); + + if (defaultAdminEmail && !loggedDeprecationWarning && log) { + const emailAddressConfigKey = `monitoring.${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}`; + loggedDeprecationWarning = true; + const message = + `Monitoring is using "${XPACK_DEFAULT_ADMIN_EMAIL_UI_SETTING}" for cluster alert notifications, ` + + `which will not be supported in Kibana 8.0. Please configure ${emailAddressConfigKey} in your kibana.yml settings`; + log.warn(message); + } + + return defaultAdminEmail; } // we use shouldUseNull to determine if we need to send nulls; we only send nulls if the last email wasn't null @@ -21,9 +47,10 @@ let shouldUseNull = true; export async function checkForEmailValue( config: MonitoringConfig, _shouldUseNull = shouldUseNull, - _getDefaultAdminEmail = getDefaultAdminEmail + _getDefaultAdminEmail = getDefaultAdminEmail, + log?: Logger ) { - const defaultAdminEmail = await _getDefaultAdminEmail(config); + const defaultAdminEmail = await _getDefaultAdminEmail(config, log); // Allow null so clearing the advanced setting will be reflected in the data const isAcceptableNull = defaultAdminEmail === null && _shouldUseNull; diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts index 9b0cd3e43daeac..e19dbb2fe1e6ba 100644 --- a/x-pack/plugins/monitoring/server/plugin.ts +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -52,6 +52,7 @@ import { import { getLicenseExpiration } from './alerts/license_expiration'; import { getClusterState } from './alerts/cluster_state'; import { InfraPluginSetup } from '../../infra/server'; +import { CoreServices } from './core_services'; export interface LegacyAPI { getServerStatus: () => string; @@ -131,6 +132,8 @@ export class Plugin { .pipe(first()) .toPromise(); + CoreServices.init(core); + this.legacyShimDependencies = { router: core.http.createRouter(), instanceUuid: core.uuid.getInstanceUuid(),