Skip to content

Commit

Permalink
fixed setup alerting dependencies for siem and monitoring plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Feb 18, 2020
1 parent ddecd61 commit 2d92916
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/monitoring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ export const monitoring = (kibana: LegacyPluginApi): LegacyPluginSpec => {
};

const legacyPlugins = plugins as Partial<typeof plugins> & { infra?: InfraPlugin };
const { xpack_main, elasticsearch, infra, alerting } = legacyPlugins;
const { xpack_main, elasticsearch, infra } = legacyPlugins;
const {
core: coreSetup,
plugins: { usageCollection, licensing },
plugins: { usageCollection, licensing, alerting },
} = server.newPlatform.setup;

const pluginsSetup: PluginsSetup = {
usageCollection,
licensing,
alerting,
};

const __LEGACY: LegacySetup = {
Expand All @@ -125,7 +126,6 @@ export const monitoring = (kibana: LegacyPluginApi): LegacyPluginSpec => {
xpack_main,
elasticsearch,
infra,
alerting,
},
};

Expand Down
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/monitoring/server/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Plugin {
} = __LEGACY;
const config = monitoringConfig();

const { usageCollection, licensing } = pluginsSetup;
const { usageCollection, licensing, alerting } = pluginsSetup;
registerMonitoringCollection();
/*
* Register collector objects for stats to show up in the APIs
Expand Down Expand Up @@ -152,7 +152,7 @@ export class Plugin {
};
});

if (KIBANA_ALERTING_ENABLED && plugins.alerting) {
if (KIBANA_ALERTING_ENABLED && alerting) {
// this is not ready right away but we need to register alerts right away
async function getMonitoringCluster() {
const configs = config.get('xpack.monitoring.elasticsearch');
Expand All @@ -174,7 +174,7 @@ export class Plugin {
function getLogger(contexts) {
return logger.get('plugins', LOGGING_TAG, ...contexts);
}
plugins.alerting.setup.registerType(
alerting.registerType(
getLicenseExpiration(
hapiServer,
getMonitoringCluster,
Expand Down
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/siem/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { i18n } from '@kbn/i18n';

import { PluginStartContract as AlertingStart } from '../../../../plugins/alerting/server';
import {
CoreSetup,
CoreStart,
Expand Down Expand Up @@ -42,6 +43,7 @@ export interface SetupPlugins {

export interface StartPlugins {
actions: ActionsStart;
alerting: AlertingStart;
}

export class Plugin {
Expand Down Expand Up @@ -145,7 +147,7 @@ export class Plugin {
}

public start(core: CoreStart, plugins: StartPlugins) {
this.clients.start(core.savedObjects, plugins.actions);
this.clients.start(core.savedObjects, plugins.actions, plugins.alerting);

this.legacyInitRoutes!(this.clients.createGetScoped());
}
Expand Down
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/siem/server/services/clients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { coreMock, httpServerMock } from '../../../../../../src/core/server/mocks';
import { actionsMock } from '../../../../../plugins/actions/server/mocks';
import { alertsMock } from '../../../../../plugins/alerting/server/mocks';

import { ClientsService } from './clients';

Expand All @@ -16,13 +17,14 @@ describe('ClientsService', () => {
const clients = new ClientsService();

const actions = actionsMock.createStart();
const alerting = alertsMock.createStart();
const { elasticsearch } = coreMock.createSetup();
const { savedObjects } = coreMock.createStart();
const request = httpServerMock.createRawRequest();
const spacesService = undefined;

clients.setup(elasticsearch.dataClient, spacesService);
clients.start(savedObjects, actions);
clients.start(savedObjects, actions, alerting);

const { spacesClient } = await clients.createGetScoped()(request);
expect(spacesClient.getSpaceId()).toEqual('default');
Expand Down
10 changes: 8 additions & 2 deletions x-pack/legacy/plugins/siem/server/services/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type GetScopedClients = (request: LegacyRequest) => Promise<Clients>;

export class ClientsService {
private actions?: StartPlugins['actions'];
private alerting?: StartPlugins['alerting'];
private clusterClient?: IClusterClient;
private savedObjects?: CoreStart['savedObjects'];
private spacesService?: SpacesServiceSetup;
Expand All @@ -37,9 +38,14 @@ export class ClientsService {
this.spacesService = spacesService;
}

public start(savedObjects: CoreStart['savedObjects'], actions: StartPlugins['actions']) {
public start(
savedObjects: CoreStart['savedObjects'],
actions: StartPlugins['actions'],
alerting: StartPlugins['alerting']
) {
this.savedObjects = savedObjects;
this.actions = actions;
this.alerting = alerting;
}

public createGetScoped(): GetScopedClients {
Expand All @@ -51,7 +57,7 @@ export class ClientsService {
const kibanaRequest = KibanaRequest.from(request);

return {
alertsClient: request.getAlertsClient?.(),
alertsClient: await this.alerting?.getAlertsClientWithRequest?.(kibanaRequest),
actionsClient: await this.actions?.getActionsClientWithRequest?.(kibanaRequest),
clusterClient: this.clusterClient!.asScoped(kibanaRequest),
savedObjectsClient: this.savedObjects!.getScopedClient(kibanaRequest),
Expand Down

0 comments on commit 2d92916

Please sign in to comment.