diff --git a/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.test.ts b/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.test.ts index c64b6e4b9298..e6ad484a8c8e 100644 --- a/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.test.ts +++ b/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.test.ts @@ -17,11 +17,13 @@ jest.mock('../lib/alerts/fetch_clusters', () => ({ fetchClusters: jest.fn(), })); jest.mock('moment', () => { - return function () { + const moment = function () { return { format: () => 'THE_DATE', }; }; + moment.duration = () => ({ humanize: () => 'HUMANIZED_DURATION' }); + return moment; }); jest.mock('../static_globals', () => ({ @@ -170,11 +172,11 @@ describe('LicenseExpirationAlert', () => { action: '[Please update your license.](elasticsearch/nodes)', actionPlain: 'Please update your license.', internalFullMessage: - 'License expiration alert is firing for testCluster. Your license expires in THE_DATE. [Please update your license.](elasticsearch/nodes)', + 'License expiration alert is firing for testCluster. Your license expires in HUMANIZED_DURATION. [Please update your license.](elasticsearch/nodes)', internalShortMessage: - 'License expiration alert is firing for testCluster. Your license expires in THE_DATE. Please update your license.', + 'License expiration alert is firing for testCluster. Your license expires in HUMANIZED_DURATION. Please update your license.', clusterName, - expiredDate: 'THE_DATE', + expiredDate: 'HUMANIZED_DURATION', state: 'firing', }); }); diff --git a/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.ts b/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.ts index 9dacba1dfe0e..f15b015ba84b 100644 --- a/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.ts +++ b/x-pack/plugins/monitoring/server/alerts/license_expiration_alert.ts @@ -17,11 +17,7 @@ import { LegacyAlert, } from '../../common/types/alerts'; import { AlertExecutorOptions, AlertInstance } from '../../../alerts/server'; -import { - ALERT_LICENSE_EXPIRATION, - FORMAT_DURATION_TEMPLATE_SHORT, - LEGACY_ALERT_DETAILS, -} from '../../common/constants'; +import { ALERT_LICENSE_EXPIRATION, LEGACY_ALERT_DETAILS } from '../../common/constants'; import { AlertMessageTokenType } from '../../common/enums'; import { AlertingDefaults } from './alert_helpers'; import { SanitizedAlert } from '../../../alerts/common'; @@ -113,12 +109,13 @@ export class LicenseExpirationAlert extends BaseAlert { ) { const legacyAlert = item.meta as LegacyAlert; const $expiry = moment(legacyAlert.metadata.time); + const $duration = moment.duration(+new Date() - $expiry.valueOf()); if (alertState.ui.isFiring) { const actionText = i18n.translate('xpack.monitoring.alerts.licenseExpiration.action', { defaultMessage: 'Please update your license.', }); const action = `[${actionText}](elasticsearch/nodes)`; - const expiredDate = $expiry.format(FORMAT_DURATION_TEMPLATE_SHORT).trim(); + const expiredDate = $duration.humanize(); instance.scheduleActions('default', { internalShortMessage: i18n.translate( 'xpack.monitoring.alerts.licenseExpiration.firing.internalShortMessage',