Skip to content

Commit

Permalink
Register geo alerts only with gold license, remove otherwise
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Dec 8, 2020
1 parent 0f56aea commit 17c64e6
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions x-pack/plugins/stack_alerts/public/alert_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getAlertType as getGeoThresholdAlertType } from './geo_threshold';
import { getAlertType as getGeoContainmentAlertType } from './geo_containment';
import { getAlertType as getThresholdAlertType } from './threshold';
import { Config, STACK_ALERTS_FEATURE_ID } from '../../common';
import { Config } from '../../common';
import { TriggersAndActionsUIPublicPluginSetup } from '../../../triggers_actions_ui/public';
import { LicensingPluginSetup } from '../../../licensing/public';

Expand All @@ -21,12 +21,23 @@ export function registerAlertTypes({
licensing: LicensingPluginSetup;
}) {
licensing.license$.subscribe((license) => {
const { state } = license.check(STACK_ALERTS_FEATURE_ID, 'gold');
const hasGoldLicense = state === 'valid';
if (hasGoldLicense && config.enableGeoAlerts) {
alertTypeRegistry.register(getGeoThresholdAlertType());
alertTypeRegistry.register(getGeoContainmentAlertType());
const geoThresholdAlertType = getGeoThresholdAlertType();
const geoContainmentAlertType = getGeoContainmentAlertType();
const thresholdAlertType = getThresholdAlertType();

if (license.hasAtLeast('gold') && config.enableGeoAlerts) {
alertTypeRegistry.register(geoThresholdAlertType);
alertTypeRegistry.register(geoContainmentAlertType);
} else {
if (alertTypeRegistry.has(geoThresholdAlertType.id)) {
alertTypeRegistry.delete(geoThresholdAlertType.id);
}
if (alertTypeRegistry.has(geoContainmentAlertType.id)) {
alertTypeRegistry.delete(geoContainmentAlertType.id);
}
}
if (!alertTypeRegistry.has(thresholdAlertType.id)) {
alertTypeRegistry.register(thresholdAlertType);
}
alertTypeRegistry.register(getThresholdAlertType());
});
}

0 comments on commit 17c64e6

Please sign in to comment.