diff --git a/src/platform/packages/private/kbn-reporting/common/types.ts b/src/platform/packages/private/kbn-reporting/common/types.ts index a7931e642f9ca..0b5f6636ccc41 100644 --- a/src/platform/packages/private/kbn-reporting/common/types.ts +++ b/src/platform/packages/private/kbn-reporting/common/types.ts @@ -112,6 +112,7 @@ export interface ReportingServerInfo { export interface ReportingHealthInfo { isSufficientlySecure: boolean; hasPermanentEncryptionKey: boolean; + areNotificationsEnabled: boolean; } export type IlmPolicyMigrationStatus = 'policy-not-found' | 'indices-not-managed-by-policy' | 'ok'; diff --git a/x-pack/platform/plugins/private/reporting/kibana.jsonc b/x-pack/platform/plugins/private/reporting/kibana.jsonc index ce6b130018af0..a27970e2cec8d 100644 --- a/x-pack/platform/plugins/private/reporting/kibana.jsonc +++ b/x-pack/platform/plugins/private/reporting/kibana.jsonc @@ -22,6 +22,7 @@ "fieldFormats", "home", "management", + "notifications", "licensing", "uiActions", "taskManager", diff --git a/x-pack/platform/plugins/private/reporting/server/core.ts b/x-pack/platform/plugins/private/reporting/server/core.ts index a29f4303ac1ca..b082dd526e9ef 100644 --- a/x-pack/platform/plugins/private/reporting/server/core.ts +++ b/x-pack/platform/plugins/private/reporting/server/core.ts @@ -43,6 +43,7 @@ import type { TaskManagerStartContract, } from '@kbn/task-manager-plugin/server'; import type { UsageCounter } from '@kbn/usage-collection-plugin/server'; +import type { NotificationsPluginStart } from '@kbn/notifications-plugin/server'; import { checkLicense } from '@kbn/reporting-server/check_license'; import { ExportTypesRegistry } from '@kbn/reporting-server/export_types_registry'; @@ -80,6 +81,7 @@ export interface ReportingInternalStart { fieldFormats: FieldFormatsStart; licensing: LicensingPluginStart; logger: Logger; + notifications: NotificationsPluginStart; screenshotting?: ScreenshottingStart; securityService: SecurityServiceStart; taskManager: TaskManagerStartContract; @@ -251,7 +253,7 @@ export class ReportingCore { public async getHealthInfo(): Promise { const { encryptedSavedObjects } = this.getPluginSetupDeps(); - const { securityService } = await this.getPluginStartDeps(); + const { notifications, securityService } = await this.getPluginStartDeps(); const isSecurityEnabled = await this.isSecurityEnabled(); let isSufficientlySecure: boolean; @@ -272,6 +274,7 @@ export class ReportingCore { return { isSufficientlySecure, hasPermanentEncryptionKey: encryptedSavedObjects.canEncrypt, + areNotificationsEnabled: notifications.isEmailServiceAvailable(), }; } diff --git a/x-pack/platform/plugins/private/reporting/server/lib/tasks/execute_report.test.ts b/x-pack/platform/plugins/private/reporting/server/lib/tasks/execute_report.test.ts index 0c1657b019a08..a8b5eb35f6ad0 100644 --- a/x-pack/platform/plugins/private/reporting/server/lib/tasks/execute_report.test.ts +++ b/x-pack/platform/plugins/private/reporting/server/lib/tasks/execute_report.test.ts @@ -170,9 +170,11 @@ describe('Execute Report Task', () => { }); it('schedules task with request if health indicates security and api keys are enabled', async () => { - jest - .spyOn(mockReporting, 'getHealthInfo') - .mockResolvedValueOnce({ isSufficientlySecure: true, hasPermanentEncryptionKey: true }); + jest.spyOn(mockReporting, 'getHealthInfo').mockResolvedValueOnce({ + isSufficientlySecure: true, + hasPermanentEncryptionKey: true, + areNotificationsEnabled: true, + }); const task = new ExecuteReportTask(mockReporting, configType, logger); const mockTaskManager = taskManagerMock.createStart(); await task.init(mockTaskManager); @@ -201,9 +203,11 @@ describe('Execute Report Task', () => { }); it('schedules task without request if health indicates security is disabled', async () => { - jest - .spyOn(mockReporting, 'getHealthInfo') - .mockResolvedValueOnce({ isSufficientlySecure: false, hasPermanentEncryptionKey: true }); + jest.spyOn(mockReporting, 'getHealthInfo').mockResolvedValueOnce({ + isSufficientlySecure: false, + hasPermanentEncryptionKey: true, + areNotificationsEnabled: false, + }); const task = new ExecuteReportTask(mockReporting, configType, logger); const mockTaskManager = taskManagerMock.createStart(); await task.init(mockTaskManager); @@ -229,9 +233,11 @@ describe('Execute Report Task', () => { }); it('schedules task without request if health indicates no permanent encryption key', async () => { - jest - .spyOn(mockReporting, 'getHealthInfo') - .mockResolvedValueOnce({ isSufficientlySecure: true, hasPermanentEncryptionKey: false }); + jest.spyOn(mockReporting, 'getHealthInfo').mockResolvedValueOnce({ + isSufficientlySecure: true, + hasPermanentEncryptionKey: false, + areNotificationsEnabled: true, + }); const task = new ExecuteReportTask(mockReporting, configType, logger); const mockTaskManager = taskManagerMock.createStart(); await task.init(mockTaskManager); diff --git a/x-pack/platform/plugins/private/reporting/server/routes/internal/health/health.ts b/x-pack/platform/plugins/private/reporting/server/routes/internal/health/health.ts index e35ea67a22e4f..ab0e7d7224022 100644 --- a/x-pack/platform/plugins/private/reporting/server/routes/internal/health/health.ts +++ b/x-pack/platform/plugins/private/reporting/server/routes/internal/health/health.ts @@ -33,6 +33,7 @@ export const registerHealthRoute = (reporting: ReportingCore, logger: Logger) => body: { has_permanent_encryption_key: healthInfo.hasPermanentEncryptionKey, is_sufficiently_secure: healthInfo.isSufficientlySecure, + are_notifications_enabled: healthInfo.areNotificationsEnabled, }, }); } catch (err) { diff --git a/x-pack/platform/plugins/private/reporting/server/test_helpers/create_mock_reportingplugin.ts b/x-pack/platform/plugins/private/reporting/server/test_helpers/create_mock_reportingplugin.ts index 4d4b386c1020f..36b4420f1670d 100644 --- a/x-pack/platform/plugins/private/reporting/server/test_helpers/create_mock_reportingplugin.ts +++ b/x-pack/platform/plugins/private/reporting/server/test_helpers/create_mock_reportingplugin.ts @@ -30,6 +30,7 @@ import { setFieldFormats } from '@kbn/reporting-server'; import { createMockScreenshottingStart } from '@kbn/screenshotting-plugin/server/mock'; import { securityMock } from '@kbn/security-plugin/server/mocks'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; +import { notificationsMock } from '@kbn/notifications-plugin/server/mocks'; import { ReportingCore } from '..'; import type { ReportingInternalSetup, ReportingInternalStart } from '../core'; @@ -76,6 +77,7 @@ export const createMockPluginStart = async ( data: dataPluginMock.createStartContract(), fieldFormats: () => Promise.resolve(fieldFormatsMock), store: await createMockReportingStore(config), + notifications: notificationsMock.createStart(), taskManager: { schedule: jest.fn().mockImplementation(() => ({ id: 'taskId' })), ensureScheduled: jest.fn(), diff --git a/x-pack/platform/plugins/private/reporting/server/types.ts b/x-pack/platform/plugins/private/reporting/server/types.ts index 4d4b25177ab1e..e4644380227b4 100644 --- a/x-pack/platform/plugins/private/reporting/server/types.ts +++ b/x-pack/platform/plugins/private/reporting/server/types.ts @@ -28,6 +28,7 @@ import type { TaskManagerStartContract, } from '@kbn/task-manager-plugin/server'; import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server'; +import type { NotificationsPluginStart } from '@kbn/notifications-plugin/server'; import { ExportTypesRegistry } from '@kbn/reporting-server/export_types_registry'; import type { AuthenticatedUser } from '@kbn/core-security-common'; @@ -63,6 +64,7 @@ export interface ReportingStartDeps { discover: DiscoverServerPluginStart; fieldFormats: FieldFormatsStart; licensing: LicensingPluginStart; + notifications: NotificationsPluginStart; taskManager: TaskManagerStartContract; screenshotting?: ScreenshottingStart; } diff --git a/x-pack/platform/plugins/private/reporting/tsconfig.json b/x-pack/platform/plugins/private/reporting/tsconfig.json index ddde2d34d6d7f..c7cfd10ec35e3 100644 --- a/x-pack/platform/plugins/private/reporting/tsconfig.json +++ b/x-pack/platform/plugins/private/reporting/tsconfig.json @@ -52,6 +52,7 @@ "@kbn/react-kibana-mount", "@kbn/core-security-common", "@kbn/core-http-server-utils", + "@kbn/notifications-plugin", ], "exclude": [ "target/**/*",