mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
parent
32bcf31aaf
commit
b605837bcf
5 changed files with 80 additions and 5 deletions
|
@ -35,4 +35,7 @@ export enum API_URLS {
|
|||
DELETE_RULE = '/api/alerting/rule/',
|
||||
RULES_FIND = '/api/alerting/rules/_find',
|
||||
CONNECTOR_TYPES = '/api/actions/connector_types',
|
||||
|
||||
// Service end points
|
||||
INDEX_TEMPLATES = '/api/uptime/service/index_templates',
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import { UptimeESClient } from '../../lib';
|
|||
import type { UptimeRouter } from '../../../types';
|
||||
import { SecurityPluginStart } from '../../../../../security/server';
|
||||
import { CloudSetup } from '../../../../../cloud/server';
|
||||
import { FleetStartContract } from '../../../../../fleet/server';
|
||||
import { UptimeConfig } from '../../../../common/config';
|
||||
|
||||
export type UMElasticsearchQueryFn<P, R = any> = (
|
||||
|
@ -41,7 +42,8 @@ export type UMSavedObjectsQueryFn<T = any, P = undefined> = (
|
|||
export interface UptimeCoreSetup {
|
||||
router: UptimeRouter;
|
||||
config: UptimeConfig;
|
||||
cloud: CloudSetup;
|
||||
cloud?: CloudSetup;
|
||||
fleet: FleetStartContract;
|
||||
security: SecurityPluginStart;
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
|
||||
}
|
||||
|
@ -59,6 +61,7 @@ export interface UptimeCorePluginsSetup {
|
|||
|
||||
export interface UptimeCorePluginsStart {
|
||||
security: SecurityPluginStart;
|
||||
fleet: FleetStartContract;
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
Plugin as PluginType,
|
||||
ISavedObjectsRepository,
|
||||
Logger,
|
||||
SavedObjectsClient,
|
||||
} from '../../../../src/core/server';
|
||||
import { uptimeRuleFieldMap } from '../common/rules/uptime_rule_field_map';
|
||||
import { initServerWithKibana } from './kibana.index';
|
||||
|
@ -25,17 +26,19 @@ import { registerUptimeSavedObjects, savedObjectsAdapter } from './lib/saved_obj
|
|||
import { mappingFromFieldMap } from '../../rule_registry/common/mapping_from_field_map';
|
||||
import { Dataset } from '../../rule_registry/server';
|
||||
import { UptimeConfig } from '../common/config';
|
||||
import { installSyntheticsIndexTemplates } from './rest_api/synthetics_service/install_index_templates';
|
||||
|
||||
export type UptimeRuleRegistry = ReturnType<Plugin['setup']>['ruleRegistry'];
|
||||
|
||||
export class Plugin implements PluginType {
|
||||
private savedObjectsClient?: ISavedObjectsRepository;
|
||||
private initContext: PluginInitializerContext;
|
||||
private logger?: Logger;
|
||||
private logger: Logger;
|
||||
private server?: UptimeCoreSetup;
|
||||
|
||||
constructor(_initializerContext: PluginInitializerContext<UptimeConfig>) {
|
||||
this.initContext = _initializerContext;
|
||||
constructor(initializerContext: PluginInitializerContext<UptimeConfig>) {
|
||||
this.initContext = initializerContext;
|
||||
this.logger = initializerContext.logger.get();
|
||||
}
|
||||
|
||||
public setup(core: CoreSetup, plugins: UptimeCorePluginsSetup) {
|
||||
|
@ -60,8 +63,8 @@ export class Plugin implements PluginType {
|
|||
});
|
||||
|
||||
this.server = {
|
||||
router: core.http.createRouter(),
|
||||
config,
|
||||
router: core.http.createRouter(),
|
||||
cloud: plugins.cloud,
|
||||
} as UptimeCoreSetup;
|
||||
|
||||
|
@ -83,8 +86,29 @@ export class Plugin implements PluginType {
|
|||
this.savedObjectsClient = core.savedObjects.createInternalRepository();
|
||||
if (this.server) {
|
||||
this.server.security = plugins.security;
|
||||
this.server.fleet = plugins.fleet;
|
||||
this.server.encryptedSavedObjects = plugins.encryptedSavedObjects;
|
||||
}
|
||||
|
||||
if (this.server?.config?.unsafe?.service.enabled) {
|
||||
const esClient = core.elasticsearch.client.asInternalUser;
|
||||
installSyntheticsIndexTemplates({
|
||||
esClient,
|
||||
server: this.server,
|
||||
savedObjectsClient: new SavedObjectsClient(core.savedObjects.createInternalRepository()),
|
||||
}).then(
|
||||
(result) => {
|
||||
if (result.name === 'synthetics' && result.install_status === 'installed') {
|
||||
this.logger.info('Installed synthetics index templates');
|
||||
} else if (result.name === 'synthetics' && result.install_status === 'install_failed') {
|
||||
this.logger.warn('Failed to install synthetics index templates');
|
||||
}
|
||||
},
|
||||
() => {
|
||||
this.logger.warn('Failed to install synthetics index templates');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public stop() {}
|
||||
|
|
|
@ -27,6 +27,7 @@ import { createGetIndexStatusRoute } from './index_state';
|
|||
import { createNetworkEventsRoute } from './network_events';
|
||||
import { createJourneyFailedStepsRoute } from './pings/journeys';
|
||||
import { createLastSuccessfulStepRoute } from './synthetics/last_successful_step';
|
||||
import { installIndexTemplatesRoute } from './synthetics_service/install_index_templates';
|
||||
|
||||
export * from './types';
|
||||
export { createRouteWithAuth } from './create_route_with_auth';
|
||||
|
@ -51,4 +52,5 @@ export const restApiRoutes: UMRestApiRouteFactory[] = [
|
|||
createJourneyFailedStepsRoute,
|
||||
createLastSuccessfulStepRoute,
|
||||
createJourneyScreenshotBlocksRoute,
|
||||
installIndexTemplatesRoute,
|
||||
];
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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 { ElasticsearchClient, SavedObjectsClientContract } from 'kibana/server';
|
||||
import { UMRestApiRouteFactory } from '../types';
|
||||
import { API_URLS } from '../../../common/constants';
|
||||
import { UptimeCoreSetup } from '../../lib/adapters';
|
||||
|
||||
export const installIndexTemplatesRoute: UMRestApiRouteFactory = () => ({
|
||||
method: 'GET',
|
||||
path: API_URLS.INDEX_TEMPLATES,
|
||||
validate: {},
|
||||
handler: async ({ server, request, savedObjectsClient, uptimeEsClient }): Promise<any> => {
|
||||
return installSyntheticsIndexTemplates({
|
||||
server,
|
||||
savedObjectsClient,
|
||||
esClient: uptimeEsClient.baseESClient,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export async function installSyntheticsIndexTemplates({
|
||||
esClient,
|
||||
server,
|
||||
savedObjectsClient,
|
||||
}: {
|
||||
server: UptimeCoreSetup;
|
||||
esClient: ElasticsearchClient;
|
||||
savedObjectsClient: SavedObjectsClientContract;
|
||||
}) {
|
||||
// no need to add error handling here since fleetSetupCompleted is already wrapped in try/catch and will log
|
||||
// warning if setup fails to complete
|
||||
await server.fleet.fleetSetupCompleted();
|
||||
|
||||
return await server.fleet.packageService.ensureInstalledPackage({
|
||||
esClient,
|
||||
savedObjectsClient,
|
||||
pkgName: 'synthetics',
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue