Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Rules]Move uptime rule params to package #205238

Merged
merged 11 commits into from
Jan 3, 2025
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<typeof uptimeDurationAnomalyRuleParamsSchema>;
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<typeof uptimeMonitorStatusRuleParamsSchema>;
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<typeof uptimeTLSRuleParamsSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -109,11 +109,7 @@ export const durationAnomalyAlertFactory: UptimeAlertTypeFactory<ActionGroupIds>
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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -294,45 +294,7 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -123,12 +124,7 @@ export const tlsAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@kbn/core-rendering-browser",
"@kbn/charts-theme",
"@kbn/charts-plugin",
"@kbn/response-ops-rule-params",
],
"exclude": ["target/**/*"]
}
Loading