This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathplugin.js
70 lines (62 loc) · 2.29 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { first } from 'rxjs/operators';
import { createAlertingCluster, createAlertingADCluster } from './clusters';
import {
AlertService,
DestinationsService,
ElasticsearchService,
MonitorService,
AnomalyDetectorService,
} from './services';
import { alerts, destinations, elasticsearch, monitors, detectors } from '../server/routes';
export class AlertingPlugin {
constructor(initializerContext) {
this.logger = initializerContext.logger.get();
this.globalConfig$ = initializerContext.config.legacy.globalConfig$;
}
async setup(core) {
// Get the global configuration settings of the cluster
const globalConfig = await this.globalConfig$.pipe(first()).toPromise();
// Create clusters
const alertingESClient = createAlertingCluster(core, globalConfig);
const adESClient = createAlertingADCluster(core, globalConfig);
// Initialize services
const alertService = new AlertService(alertingESClient);
const elasticsearchService = new ElasticsearchService(alertingESClient);
const monitorService = new MonitorService(alertingESClient);
const destinationsService = new DestinationsService(alertingESClient);
const anomalyDetectorService = new AnomalyDetectorService(adESClient);
const services = {
alertService,
destinationsService,
elasticsearchService,
monitorService,
anomalyDetectorService,
};
// Create router
const router = core.http.createRouter();
// Add server routes
alerts(services, router);
destinations(services, router);
elasticsearch(services, router);
monitors(services, router);
detectors(services, router);
return {};
}
async start(core) {
return {};
}
}