Skip to content

Commit

Permalink
[Monitoring] Migrate license expiration alert to Kibana alerting (ela…
Browse files Browse the repository at this point in the history
…stic#54306)

* License expiration

* Flip off

* Only require alerting and actions if enabled

* Support date formating and timezones in the alert UI messages, support ccs better

* Fix status tests

* Fix up front end tests

* Fix linting, and switch this back

* Add this back in so legacy alerts continue to work

* Fix type issues

* Handle CCS better

* Code cleanup

* Fix type issues

* Flip this off, and fix test

* Moved the email address config to advanced settings, but need help with test failures and typescript

* Fix issue with task manager

* Deprecate email_address

* Use any until we can figure out this TS issue

* Fix type issue

* More tests

* Fix mocha tests

* Use mock instead of any

* I'm not sure why these changed...

* Provide timezone in moment usage in tests for consistency

* Fix type issue

* Change how we get dateFormat and timezone

* Change where we calculate the dates to show in the alerts UI

* Show deprecation warning based on the feature toggle

* Ensure we are using UTC

* PR feedback

* Only add this if the feature flag is enabled

* Fix tests

* Ensure we only attempt to look this up if the feature flag is enabled

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
2 people authored and cauemarcondes committed Feb 5, 2020
1 parent b41d4b2 commit d94082f
Show file tree
Hide file tree
Showing 55 changed files with 4,223 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,45 @@ export const REPORTING_SYSTEM_ID = 'reporting';
* @type {Number}
*/
export const TELEMETRY_COLLECTION_INTERVAL = 86400000;

/**
* We want to slowly rollout the migration from watcher-based cluster alerts to
* kibana alerts and we only want to enable the kibana alerts once all
* watcher-based cluster alerts have been migrated so this flag will serve
* as the only way to see the new UI and actually run Kibana alerts. It will
* be false until all alerts have been migrated, then it will be removed
*/
export const KIBANA_ALERTING_ENABLED = false;

/**
* The prefix for all alert types used by monitoring
*/
export const ALERT_TYPE_PREFIX = 'monitoring_';

/**
* This is the alert type id for the license expiration alert
*/
export const ALERT_TYPE_LICENSE_EXPIRATION = `${ALERT_TYPE_PREFIX}alert_type_license_expiration`;

/**
* A listing of all alert types
*/
export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION];

/**
* Matches the id for the built-in in email action type
* See x-pack/legacy/plugins/actions/server/builtin_action_types/email.ts
*/
export const ALERT_ACTION_TYPE_EMAIL = '.email';

/**
* The number of alerts that have been migrated
*/
export const NUMBER_OF_MIGRATED_ALERTS = 1;

/**
* The advanced settings config name for the email address
*/
export const MONITORING_CONFIG_ALERTING_EMAIL_ADDRESS = 'monitoring:alertingEmailAddress';

export const ALERT_EMAIL_SERVICES = ['gmail', 'hotmail', 'icloud', 'outlook365', 'ses', 'yahoo'];
20 changes: 15 additions & 5 deletions x-pack/legacy/plugins/monitoring/deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { get } from 'lodash';
import { CLUSTER_ALERTS_ADDRESS_CONFIG_KEY } from './common/constants';
import { CLUSTER_ALERTS_ADDRESS_CONFIG_KEY, KIBANA_ALERTING_ENABLED } from './common/constants';

/**
* Re-writes deprecated user-defined config settings and logs warnings as a
Expand All @@ -21,10 +21,20 @@ export const deprecations = () => {
const clusterAlertsEnabled = get(settings, 'cluster_alerts.enabled');
const emailNotificationsEnabled =
clusterAlertsEnabled && get(settings, 'cluster_alerts.email_notifications.enabled');
if (emailNotificationsEnabled && !get(settings, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) {
log(
`Config key "${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}" will be required for email notifications to work in 7.0."`
);
if (emailNotificationsEnabled) {
if (KIBANA_ALERTING_ENABLED) {
if (get(settings, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) {
log(
`Config key "${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}" is deprecated. Please configure the email adddress through the Stack Monitoring UI instead."`
);
}
} else {
if (!get(settings, CLUSTER_ALERTS_ADDRESS_CONFIG_KEY)) {
log(
`Config key "${CLUSTER_ALERTS_ADDRESS_CONFIG_KEY}" will be required for email notifications to work in 7.0."`
);
}
}
}
},
(settings, log) => {
Expand Down
12 changes: 10 additions & 2 deletions x-pack/legacy/plugins/monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ import { deprecations } from './deprecations';
import { getUiExports } from './ui_exports';
import { Plugin } from './server/plugin';
import { initInfraSource } from './server/lib/logs/init_infra_source';
import { KIBANA_ALERTING_ENABLED } from './common/constants';

/**
* Invokes plugin modules to instantiate the Monitoring plugin for Kibana
* @param kibana {Object} Kibana plugin instance
* @return {Object} Monitoring UI Kibana plugin object
*/
const deps = ['kibana', 'elasticsearch', 'xpack_main'];
if (KIBANA_ALERTING_ENABLED) {
deps.push(...['alerting', 'actions']);
}
export const monitoring = kibana =>
new kibana.Plugin({
require: ['kibana', 'elasticsearch', 'xpack_main'],
require: deps,
id: 'monitoring',
configPrefix: 'monitoring',
publicDir: resolve(__dirname, 'public'),
Expand Down Expand Up @@ -59,6 +64,7 @@ export const monitoring = kibana =>
}),
injectUiAppVars: server.injectUiAppVars,
log: (...args) => server.log(...args),
logger: server.newPlatform.coreContext.logger,
getOSInfo: server.getOSInfo,
events: {
on: (...args) => server.events.on(...args),
Expand All @@ -73,11 +79,13 @@ export const monitoring = kibana =>
xpack_main: server.plugins.xpack_main,
elasticsearch: server.plugins.elasticsearch,
infra: server.plugins.infra,
alerting: server.plugins.alerting,
usageCollection,
licensing,
};

new Plugin().setup(serverFacade, plugins);
const plugin = new Plugin();
plugin.setup(serverFacade, plugins);
},
config,
deprecations,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d94082f

Please sign in to comment.