"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ruleSnoozeScheduleSchema = exports.ruleResponseSchema = exports.ruleParamsSchema = exports.ruleLastRunSchema = exports.ruleExecutionStatusSchema = exports.rRuleSchema = exports.monitoringSchema = exports.mappedParamsSchema = exports.actionParamsSchema = void 0; var _configSchema = require("@kbn/config-schema"); var _v = require("../constants/v1"); /* * 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; you may not use this file except in compliance with the Elastic License * 2.0. */ const ruleParamsSchema = _configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.maybe(_configSchema.schema.any())); exports.ruleParamsSchema = ruleParamsSchema; const actionParamsSchema = _configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.maybe(_configSchema.schema.any())); exports.actionParamsSchema = actionParamsSchema; const mappedParamsSchema = _configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.maybe(_configSchema.schema.any())); exports.mappedParamsSchema = mappedParamsSchema; const notifyWhenSchema = _configSchema.schema.oneOf([_configSchema.schema.literal(_v.ruleNotifyWhen.CHANGE), _configSchema.schema.literal(_v.ruleNotifyWhen.ACTIVE), _configSchema.schema.literal(_v.ruleNotifyWhen.THROTTLE)]); const intervalScheduleSchema = _configSchema.schema.object({ interval: _configSchema.schema.string() }); const actionFrequencySchema = _configSchema.schema.object({ summary: _configSchema.schema.boolean(), notify_when: notifyWhenSchema, throttle: _configSchema.schema.nullable(_configSchema.schema.string()) }); const actionAlertsFilterSchema = _configSchema.schema.object({ query: _configSchema.schema.maybe(_configSchema.schema.object({ kql: _configSchema.schema.string(), filters: _configSchema.schema.arrayOf(_configSchema.schema.object({ query: _configSchema.schema.maybe(_configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.any())), meta: _configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.any()), state$: _configSchema.schema.maybe(_configSchema.schema.object({ store: _configSchema.schema.string() })) })) })), timeframe: _configSchema.schema.maybe(_configSchema.schema.object({ days: _configSchema.schema.arrayOf(_configSchema.schema.oneOf([_configSchema.schema.literal(1), _configSchema.schema.literal(2), _configSchema.schema.literal(3), _configSchema.schema.literal(4), _configSchema.schema.literal(5), _configSchema.schema.literal(6), _configSchema.schema.literal(7)])), hours: _configSchema.schema.object({ start: _configSchema.schema.string(), end: _configSchema.schema.string() }), timezone: _configSchema.schema.string() })) }); const actionSchema = _configSchema.schema.object({ uuid: _configSchema.schema.maybe(_configSchema.schema.string()), group: _configSchema.schema.string(), id: _configSchema.schema.string(), connector_type_id: _configSchema.schema.string(), params: actionParamsSchema, frequency: _configSchema.schema.maybe(actionFrequencySchema), alerts_filter: _configSchema.schema.maybe(actionAlertsFilterSchema) }); const ruleExecutionStatusSchema = _configSchema.schema.object({ status: _configSchema.schema.oneOf([_configSchema.schema.literal(_v.ruleExecutionStatusValues.OK), _configSchema.schema.literal(_v.ruleExecutionStatusValues.ACTIVE), _configSchema.schema.literal(_v.ruleExecutionStatusValues.ERROR), _configSchema.schema.literal(_v.ruleExecutionStatusValues.WARNING), _configSchema.schema.literal(_v.ruleExecutionStatusValues.PENDING), _configSchema.schema.literal(_v.ruleExecutionStatusValues.UNKNOWN)]), last_execution_date: _configSchema.schema.string(), last_duration: _configSchema.schema.maybe(_configSchema.schema.number()), error: _configSchema.schema.maybe(_configSchema.schema.object({ reason: _configSchema.schema.oneOf([_configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.READ), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.DECRYPT), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.EXECUTE), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.UNKNOWN), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.LICENSE), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.TIMEOUT), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.DISABLED), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.VALIDATE)]), message: _configSchema.schema.string() })), warning: _configSchema.schema.maybe(_configSchema.schema.object({ reason: _configSchema.schema.oneOf([_configSchema.schema.literal(_v.ruleExecutionStatusWarningReason.MAX_EXECUTABLE_ACTIONS), _configSchema.schema.literal(_v.ruleExecutionStatusWarningReason.MAX_ALERTS)]), message: _configSchema.schema.string() })) }); exports.ruleExecutionStatusSchema = ruleExecutionStatusSchema; const ruleLastRunSchema = _configSchema.schema.object({ outcome: _configSchema.schema.oneOf([_configSchema.schema.literal(_v.ruleLastRunOutcomeValues.SUCCEEDED), _configSchema.schema.literal(_v.ruleLastRunOutcomeValues.WARNING), _configSchema.schema.literal(_v.ruleLastRunOutcomeValues.FAILED)]), outcome_order: _configSchema.schema.maybe(_configSchema.schema.number()), warning: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.oneOf([_configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.READ), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.DECRYPT), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.EXECUTE), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.UNKNOWN), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.LICENSE), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.TIMEOUT), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.DISABLED), _configSchema.schema.literal(_v.ruleExecutionStatusErrorReason.VALIDATE), _configSchema.schema.literal(_v.ruleExecutionStatusWarningReason.MAX_EXECUTABLE_ACTIONS), _configSchema.schema.literal(_v.ruleExecutionStatusWarningReason.MAX_ALERTS)]))), outcome_msg: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.arrayOf(_configSchema.schema.string()))), alerts_count: _configSchema.schema.object({ active: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), new: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), recovered: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), ignored: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())) }) }); exports.ruleLastRunSchema = ruleLastRunSchema; const monitoringSchema = _configSchema.schema.object({ run: _configSchema.schema.object({ history: _configSchema.schema.arrayOf(_configSchema.schema.object({ success: _configSchema.schema.boolean(), timestamp: _configSchema.schema.number(), duration: _configSchema.schema.maybe(_configSchema.schema.number()), outcome: _configSchema.schema.maybe(ruleLastRunSchema) })), calculated_metrics: _configSchema.schema.object({ p50: _configSchema.schema.maybe(_configSchema.schema.number()), p95: _configSchema.schema.maybe(_configSchema.schema.number()), p99: _configSchema.schema.maybe(_configSchema.schema.number()), success_ratio: _configSchema.schema.number() }), last_run: _configSchema.schema.object({ timestamp: _configSchema.schema.string(), metrics: _configSchema.schema.object({ duration: _configSchema.schema.maybe(_configSchema.schema.number()), total_search_duration_ms: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), total_indexing_duration_ms: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), total_alerts_detected: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), total_alerts_created: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())), gap_duration_s: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.number())) }) }) }) }); exports.monitoringSchema = monitoringSchema; const rRuleSchema = _configSchema.schema.object({ dtstart: _configSchema.schema.string(), tzid: _configSchema.schema.string(), freq: _configSchema.schema.maybe(_configSchema.schema.oneOf([_configSchema.schema.literal(0), _configSchema.schema.literal(1), _configSchema.schema.literal(2), _configSchema.schema.literal(3), _configSchema.schema.literal(4), _configSchema.schema.literal(5), _configSchema.schema.literal(6)])), until: _configSchema.schema.maybe(_configSchema.schema.string()), count: _configSchema.schema.maybe(_configSchema.schema.number()), interval: _configSchema.schema.maybe(_configSchema.schema.number()), wkst: _configSchema.schema.maybe(_configSchema.schema.oneOf([_configSchema.schema.literal('MO'), _configSchema.schema.literal('TU'), _configSchema.schema.literal('WE'), _configSchema.schema.literal('TH'), _configSchema.schema.literal('FR'), _configSchema.schema.literal('SA'), _configSchema.schema.literal('SU')])), byweekday: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.oneOf([_configSchema.schema.string(), _configSchema.schema.number()]))), bymonth: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.number())), bysetpos: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.number())), bymonthday: _configSchema.schema.arrayOf(_configSchema.schema.number()), byyearday: _configSchema.schema.arrayOf(_configSchema.schema.number()), byweekno: _configSchema.schema.arrayOf(_configSchema.schema.number()), byhour: _configSchema.schema.arrayOf(_configSchema.schema.number()), byminute: _configSchema.schema.arrayOf(_configSchema.schema.number()), bysecond: _configSchema.schema.arrayOf(_configSchema.schema.number()) }); exports.rRuleSchema = rRuleSchema; const ruleSnoozeScheduleSchema = _configSchema.schema.object({ duration: _configSchema.schema.number(), rRule: rRuleSchema, id: _configSchema.schema.maybe(_configSchema.schema.string()), skipRecurrences: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())) }); exports.ruleSnoozeScheduleSchema = ruleSnoozeScheduleSchema; const ruleResponseSchema = _configSchema.schema.object({ id: _configSchema.schema.string(), enabled: _configSchema.schema.boolean(), name: _configSchema.schema.string(), tags: _configSchema.schema.arrayOf(_configSchema.schema.string()), rule_type_id: _configSchema.schema.string(), consumer: _configSchema.schema.string(), schedule: intervalScheduleSchema, actions: _configSchema.schema.arrayOf(actionSchema), params: ruleParamsSchema, mapped_params: _configSchema.schema.maybe(mappedParamsSchema), scheduled_task_id: _configSchema.schema.maybe(_configSchema.schema.string()), created_by: _configSchema.schema.nullable(_configSchema.schema.string()), updated_by: _configSchema.schema.nullable(_configSchema.schema.string()), created_at: _configSchema.schema.string(), updated_at: _configSchema.schema.string(), api_key_owner: _configSchema.schema.nullable(_configSchema.schema.string()), api_key_created_by_user: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.boolean())), throttle: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.string())), mute_all: _configSchema.schema.boolean(), notify_when: _configSchema.schema.maybe(_configSchema.schema.nullable(notifyWhenSchema)), muted_alert_ids: _configSchema.schema.arrayOf(_configSchema.schema.string()), execution_status: ruleExecutionStatusSchema, monitoring: _configSchema.schema.maybe(monitoringSchema), snooze_schedule: _configSchema.schema.maybe(_configSchema.schema.arrayOf(ruleSnoozeScheduleSchema)), active_snoozes: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())), is_snoozed_until: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.string())), last_run: _configSchema.schema.maybe(_configSchema.schema.nullable(ruleLastRunSchema)), next_run: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.string())), revision: _configSchema.schema.number(), running: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.boolean())), view_in_app_relative_url: _configSchema.schema.maybe(_configSchema.schema.nullable(_configSchema.schema.string())) }); exports.ruleResponseSchema = ruleResponseSchema;