diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/index.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/index.ts new file mode 100644 index 0000000000000..ab67697c8d42c --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/index.ts @@ -0,0 +1,14 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export { uptimeDurationAnomalyRuleParamsSchema } from './latest'; +export { uptimeDurationAnomalyRuleParamsSchema as uptimeDurationAnomalyRuleParamsSchemaV1 } from './v1'; + +export type { UptimeDurationAnomalyRuleParams } from './latest'; +export type { UptimeDurationAnomalyRuleParams as UptimeDurationAnomalyRuleParamsV1 } from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/latest.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/latest.ts @@ -0,0 +1,10 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export * from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/v1.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/v1.ts new file mode 100644 index 0000000000000..f3cb96ac42dbe --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_duration_anomaly/v1.ts @@ -0,0 +1,18 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { TypeOf, schema } from '@kbn/config-schema'; + +export const uptimeDurationAnomalyRuleParamsSchema = schema.object({ + stackVersion: schema.maybe(schema.string()), + monitorId: schema.string(), + severity: schema.number(), +}); + +export type UptimeDurationAnomalyRuleParams = TypeOf; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/index.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/index.ts new file mode 100644 index 0000000000000..da4a31c8f023a --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/index.ts @@ -0,0 +1,14 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export { uptimeMonitorStatusRuleParamsSchema } from './latest'; +export { uptimeMonitorStatusRuleParamsSchema as uptimeMonitorStatusRuleParamsSchemaV1 } from './v1'; + +export type { UptimeMonitorStatusParams } from './latest'; +export type { UptimeMonitorStatusParams as UptimeMonitorStatusParamsV1 } from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/latest.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/latest.ts @@ -0,0 +1,10 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export * from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/v1.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/v1.ts new file mode 100644 index 0000000000000..c8588dffdcd1c --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_monitor_status/v1.ts @@ -0,0 +1,52 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { TypeOf, schema } from '@kbn/config-schema'; + +export const uptimeMonitorStatusRuleParamsSchema = schema.object({ + stackVersion: schema.maybe(schema.string()), + availability: schema.maybe( + schema.object({ + range: schema.number(), + rangeUnit: schema.string(), + threshold: schema.string(), + }) + ), + // deprecated + filters: schema.maybe( + schema.oneOf([ + // deprecated + schema.object({ + 'monitor.type': schema.maybe(schema.arrayOf(schema.string())), + 'observer.geo.name': schema.maybe(schema.arrayOf(schema.string())), + tags: schema.maybe(schema.arrayOf(schema.string())), + 'url.port': schema.maybe(schema.arrayOf(schema.string())), + }), + schema.string(), + ]) + ), + locations: schema.maybe(schema.arrayOf(schema.string())), + numTimes: schema.number(), + search: schema.maybe(schema.string()), + shouldCheckStatus: schema.boolean(), + shouldCheckAvailability: schema.boolean(), + timerangeCount: schema.maybe(schema.number()), + timerangeUnit: schema.maybe(schema.string()), + // deprecated + timerange: schema.maybe( + schema.object({ + from: schema.string(), + to: schema.string(), + }) + ), + version: schema.maybe(schema.number()), + isAutoGenerated: schema.maybe(schema.boolean()), +}); + +export type UptimeMonitorStatusParams = TypeOf; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_tls/index.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_tls/index.ts new file mode 100644 index 0000000000000..89b393515819e --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_tls/index.ts @@ -0,0 +1,14 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export { uptimeTLSRuleParamsSchema } from './latest'; +export { uptimeTLSRuleParamsSchema as uptimeTLSRuleParamsSchemaV1 } from './v1'; + +export type { UptimeTLSRuleParams } from './latest'; +export type { UptimeTLSRuleParams as UptimeTLSRuleParamsV1 } from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_tls/latest.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_tls/latest.ts new file mode 100644 index 0000000000000..f278309c22b03 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_tls/latest.ts @@ -0,0 +1,10 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export * from './v1'; diff --git a/src/platform/packages/shared/response-ops/rule_params/uptime_tls/v1.ts b/src/platform/packages/shared/response-ops/rule_params/uptime_tls/v1.ts new file mode 100644 index 0000000000000..c92b67fb26b23 --- /dev/null +++ b/src/platform/packages/shared/response-ops/rule_params/uptime_tls/v1.ts @@ -0,0 +1,19 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { TypeOf, schema } from '@kbn/config-schema'; + +export const uptimeTLSRuleParamsSchema = schema.object({ + stackVersion: schema.maybe(schema.string()), + search: schema.maybe(schema.string()), + certExpirationThreshold: schema.maybe(schema.number()), + certAgeThreshold: schema.maybe(schema.number()), +}); + +export type UptimeTLSRuleParams = TypeOf; diff --git a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/duration_anomaly.ts b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/duration_anomaly.ts index 4bb64fe694446..653bbd798fdd4 100644 --- a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/duration_anomaly.ts +++ b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/duration_anomaly.ts @@ -12,7 +12,6 @@ import { SavedObjectsClientContract, DEFAULT_APP_CATEGORIES, } from '@kbn/core/server'; -import { schema } from '@kbn/config-schema'; import { ALERT_EVALUATION_VALUE, ALERT_EVALUATION_THRESHOLD, @@ -21,6 +20,7 @@ import { import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; import type { MlAnomaliesTableRecord } from '@kbn/ml-anomaly-utils'; import { getSeverityType } from '@kbn/ml-anomaly-utils'; +import { uptimeDurationAnomalyRuleParamsSchema } from '@kbn/response-ops-rule-params/uptime_duration_anomaly'; import { alertsLocatorID, AlertsLocatorParams, @@ -109,11 +109,7 @@ export const durationAnomalyAlertFactory: UptimeAlertTypeFactory producer: 'uptime', name: durationAnomalyTranslations.alertFactoryName, validate: { - params: schema.object({ - stackVersion: schema.maybe(schema.string()), - monitorId: schema.string(), - severity: schema.number(), - }), + params: uptimeDurationAnomalyRuleParamsSchema, }, defaultActionGroupId: DURATION_ANOMALY.id, actionGroups: [ diff --git a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/status_check.ts b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/status_check.ts index 0ce64bc803821..da49a9e67cadf 100644 --- a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/status_check.ts +++ b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/status_check.ts @@ -10,12 +10,12 @@ import { min } from 'lodash'; import moment from 'moment'; import datemath from '@kbn/datemath'; -import { schema } from '@kbn/config-schema'; import { i18n } from '@kbn/i18n'; import { JsonObject } from '@kbn/utility-types'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; import { ALERT_REASON } from '@kbn/rule-data-utils'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; +import { uptimeMonitorStatusRuleParamsSchema } from '@kbn/response-ops-rule-params/uptime_monitor_status'; import { alertsLocatorID, AlertsLocatorParams, @@ -294,45 +294,7 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory = ( defaultMessage: 'Uptime monitor status', }), validate: { - params: schema.object({ - stackVersion: schema.maybe(schema.string()), - availability: schema.maybe( - schema.object({ - range: schema.number(), - rangeUnit: schema.string(), - threshold: schema.string(), - }) - ), - // deprecated - filters: schema.maybe( - schema.oneOf([ - // deprecated - schema.object({ - 'monitor.type': schema.maybe(schema.arrayOf(schema.string())), - 'observer.geo.name': schema.maybe(schema.arrayOf(schema.string())), - tags: schema.maybe(schema.arrayOf(schema.string())), - 'url.port': schema.maybe(schema.arrayOf(schema.string())), - }), - schema.string(), - ]) - ), - locations: schema.maybe(schema.arrayOf(schema.string())), - numTimes: schema.number(), - search: schema.maybe(schema.string()), - shouldCheckStatus: schema.boolean(), - shouldCheckAvailability: schema.boolean(), - timerangeCount: schema.maybe(schema.number()), - timerangeUnit: schema.maybe(schema.string()), - // deprecated - timerange: schema.maybe( - schema.object({ - from: schema.string(), - to: schema.string(), - }) - ), - version: schema.maybe(schema.number()), - isAutoGenerated: schema.maybe(schema.boolean()), - }), + params: uptimeMonitorStatusRuleParamsSchema, }, defaultActionGroupId: MONITOR_STATUS.id, actionGroups: [ diff --git a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/tls.ts b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/tls.ts index bf0ba8596332f..d2557256c9b6b 100644 --- a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/tls.ts +++ b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/tls.ts @@ -9,7 +9,6 @@ import { DEFAULT_APP_CATEGORIES } from '@kbn/core/server'; import { AlertsClientError, GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server'; import moment from 'moment'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; -import { schema } from '@kbn/config-schema'; import { alertsLocatorID, AlertsLocatorParams, @@ -20,6 +19,8 @@ import { LocatorPublic } from '@kbn/share-plugin/common'; import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils'; import { asyncForEach } from '@kbn/std'; import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; +import { uptimeTLSRuleParamsSchema } from '@kbn/response-ops-rule-params/uptime_tls'; + import { uptimeRuleFieldMap } from '../../../../common/rules/uptime_rule_field_map'; import { formatFilterString } from './status_check'; import { UptimeAlertTypeFactory } from './types'; @@ -123,12 +124,7 @@ export const tlsAlertFactory: UptimeAlertTypeFactory = ( producer: 'uptime', name: tlsTranslations.alertFactoryName, validate: { - params: schema.object({ - stackVersion: schema.maybe(schema.string()), - search: schema.maybe(schema.string()), - certExpirationThreshold: schema.maybe(schema.number()), - certAgeThreshold: schema.maybe(schema.number()), - }), + params: uptimeTLSRuleParamsSchema, }, defaultActionGroupId: TLS.id, actionGroups: [ diff --git a/x-pack/solutions/observability/plugins/uptime/tsconfig.json b/x-pack/solutions/observability/plugins/uptime/tsconfig.json index 496ae1f398f2c..56b4e84c1795c 100644 --- a/x-pack/solutions/observability/plugins/uptime/tsconfig.json +++ b/x-pack/solutions/observability/plugins/uptime/tsconfig.json @@ -79,6 +79,7 @@ "@kbn/core-rendering-browser", "@kbn/charts-theme", "@kbn/charts-plugin", + "@kbn/response-ops-rule-params", ], "exclude": ["target/**/*"] }