mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Alerting] Unifies the use of a single constant for Api urls in alerting & actions (#60430) (#60786)
Unifies the use of a single constant for Api urls in alerting & actions Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
42857d534a
commit
78a963f437
25 changed files with 63 additions and 35 deletions
|
@ -32,7 +32,11 @@ import {
|
|||
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
||||
import { CoreStart } from 'kibana/public';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { Alert, AlertTaskState } from '../../../../x-pack/plugins/alerting/common';
|
||||
import {
|
||||
Alert,
|
||||
AlertTaskState,
|
||||
BASE_ALERT_API_PATH,
|
||||
} from '../../../../x-pack/plugins/alerting/common';
|
||||
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';
|
||||
|
||||
type Props = RouteComponentProps & {
|
||||
|
@ -45,10 +49,10 @@ export const ViewAlertPage = withRouter(({ http, id }: Props) => {
|
|||
|
||||
useEffect(() => {
|
||||
if (!alert) {
|
||||
http.get(`/api/alert/${id}`).then(setAlert);
|
||||
http.get(`${BASE_ALERT_API_PATH}/${id}`).then(setAlert);
|
||||
}
|
||||
if (!alertState) {
|
||||
http.get(`/api/alert/${id}/state`).then(setAlertState);
|
||||
http.get(`${BASE_ALERT_API_PATH}/${id}/state`).then(setAlertState);
|
||||
}
|
||||
}, [alert, alertState, http, id]);
|
||||
|
||||
|
|
|
@ -34,7 +34,11 @@ import {
|
|||
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
||||
import { CoreStart } from 'kibana/public';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { Alert, AlertTaskState } from '../../../../x-pack/plugins/alerting/common';
|
||||
import {
|
||||
Alert,
|
||||
AlertTaskState,
|
||||
BASE_ALERT_API_PATH,
|
||||
} from '../../../../x-pack/plugins/alerting/common';
|
||||
import { ALERTING_EXAMPLE_APP_ID } from '../../common/constants';
|
||||
|
||||
type Props = RouteComponentProps & {
|
||||
|
@ -51,10 +55,10 @@ export const ViewPeopleInSpaceAlertPage = withRouter(({ http, id }: Props) => {
|
|||
|
||||
useEffect(() => {
|
||||
if (!alert) {
|
||||
http.get(`/api/alert/${id}`).then(setAlert);
|
||||
http.get(`${BASE_ALERT_API_PATH}/${id}`).then(setAlert);
|
||||
}
|
||||
if (!alertState) {
|
||||
http.get(`/api/alert/${id}/state`).then(setAlertState);
|
||||
http.get(`${BASE_ALERT_API_PATH}/${id}/state`).then(setAlertState);
|
||||
}
|
||||
}, [alert, alertState, http, id]);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
import { kfetch } from 'ui/kfetch';
|
||||
import { omit, pick } from 'lodash';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { ActionResult } from '../../../../../../../plugins/actions/common';
|
||||
import { ActionResult, BASE_ACTION_API_PATH } from '../../../../../../../plugins/actions/common';
|
||||
import { ManageEmailAction, EmailActionData } from '../manage_email_action';
|
||||
import { ALERT_ACTION_TYPE_EMAIL } from '../../../../common/constants';
|
||||
import { NEW_ACTION_ID } from './configuration';
|
||||
|
@ -44,7 +44,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {
|
|||
if (props.editAction) {
|
||||
await kfetch({
|
||||
method: 'PUT',
|
||||
pathname: `/api/action/${props.editAction.id}`,
|
||||
pathname: `${BASE_ACTION_API_PATH}/${props.editAction.id}`,
|
||||
body: JSON.stringify({
|
||||
name: props.editAction.name,
|
||||
config: omit(data, ['user', 'password']),
|
||||
|
@ -55,7 +55,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {
|
|||
} else {
|
||||
await kfetch({
|
||||
method: 'POST',
|
||||
pathname: '/api/action',
|
||||
pathname: BASE_ACTION_API_PATH,
|
||||
body: JSON.stringify({
|
||||
name: i18n.translate('xpack.monitoring.alerts.configuration.emailAction.name', {
|
||||
defaultMessage: 'Email action for Stack Monitoring alerts',
|
||||
|
@ -75,7 +75,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {
|
|||
|
||||
await kfetch({
|
||||
method: 'DELETE',
|
||||
pathname: `/api/action/${id}`,
|
||||
pathname: `${BASE_ACTION_API_PATH}/${id}`,
|
||||
});
|
||||
|
||||
if (props.editAction && props.editAction.id === id) {
|
||||
|
@ -101,7 +101,7 @@ export const Step1: React.FC<GetStep1Props> = (props: GetStep1Props) => {
|
|||
|
||||
const result = await kfetch({
|
||||
method: 'POST',
|
||||
pathname: `/api/action/${props.selectedEmailActionId}/_execute`,
|
||||
pathname: `${BASE_ACTION_API_PATH}/${props.selectedEmailActionId}/_execute`,
|
||||
body: JSON.stringify({ params }),
|
||||
});
|
||||
if (result.status === 'ok') {
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import { FormattedMessage } from '@kbn/i18n/react';
|
||||
import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links';
|
||||
import { Alert } from '../../../../../../plugins/alerting/common';
|
||||
import { Alert, BASE_ALERT_API_PATH } from '../../../../../../plugins/alerting/common';
|
||||
import { getSetupModeState, addSetupModeCallback, toggleSetupMode } from '../../lib/setup_mode';
|
||||
import { NUMBER_OF_MIGRATED_ALERTS, ALERT_TYPE_PREFIX } from '../../../common/constants';
|
||||
import { AlertsConfiguration } from './configuration';
|
||||
|
@ -39,7 +39,7 @@ export const AlertsStatus: React.FC<AlertsStatusProps> = (props: AlertsStatusPro
|
|||
|
||||
React.useEffect(() => {
|
||||
async function fetchAlertsStatus() {
|
||||
const alerts = await kfetch({ method: 'GET', pathname: `/api/alert/_find` });
|
||||
const alerts = await kfetch({ method: 'GET', pathname: `${BASE_ALERT_API_PATH}/_find` });
|
||||
const monitoringAlerts = alerts.data.filter((alert: Alert) =>
|
||||
alert.alertTypeId.startsWith(ALERT_TYPE_PREFIX)
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { ActionResult } from '../types';
|
||||
import { ILicenseState, verifyApiAccess, isErrorThatHandlesItsOwnResponse } from '../lib';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
export const bodySchema = schema.object({
|
||||
name: schema.string(),
|
||||
|
@ -25,7 +26,7 @@ export const bodySchema = schema.object({
|
|||
export const createActionRoute = (router: IRouter, licenseState: ILicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: `/api/action`,
|
||||
path: BASE_ACTION_API_PATH,
|
||||
validate: {
|
||||
body: bodySchema,
|
||||
},
|
||||
|
|
|
@ -18,6 +18,7 @@ import {
|
|||
KibanaResponseFactory,
|
||||
} from 'kibana/server';
|
||||
import { ILicenseState, verifyApiAccess } from '../lib';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -26,7 +27,7 @@ const paramSchema = schema.object({
|
|||
export const deleteActionRoute = (router: IRouter, licenseState: ILicenseState) => {
|
||||
router.delete(
|
||||
{
|
||||
path: `/api/action/{id}`,
|
||||
path: `${BASE_ACTION_API_PATH}/{id}`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -15,6 +15,7 @@ import { ILicenseState, verifyApiAccess, isErrorThatHandlesItsOwnResponse } from
|
|||
|
||||
import { ActionExecutorContract } from '../lib';
|
||||
import { ActionTypeExecutorResult } from '../types';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -31,7 +32,7 @@ export const executeActionRoute = (
|
|||
) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/action/{id}/_execute',
|
||||
path: `${BASE_ACTION_API_PATH}/{id}/_execute`,
|
||||
validate: {
|
||||
body: bodySchema,
|
||||
params: paramSchema,
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { FindOptions } from '../../../alerting/server';
|
||||
import { ILicenseState, verifyApiAccess } from '../lib';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
// config definition
|
||||
const querySchema = schema.object({
|
||||
|
@ -43,7 +44,7 @@ const querySchema = schema.object({
|
|||
export const findActionRoute = (router: IRouter, licenseState: ILicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: `/api/action/_find`,
|
||||
path: `${BASE_ACTION_API_PATH}/_find`,
|
||||
validate: {
|
||||
query: querySchema,
|
||||
},
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
KibanaResponseFactory,
|
||||
} from 'kibana/server';
|
||||
import { ILicenseState, verifyApiAccess } from '../lib';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -21,7 +22,7 @@ const paramSchema = schema.object({
|
|||
export const getActionRoute = (router: IRouter, licenseState: ILicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: `/api/action/{id}`,
|
||||
path: `${BASE_ACTION_API_PATH}/{id}`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -12,11 +12,12 @@ import {
|
|||
KibanaResponseFactory,
|
||||
} from 'kibana/server';
|
||||
import { ILicenseState, verifyApiAccess } from '../lib';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
export const listActionTypesRoute = (router: IRouter, licenseState: ILicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: `/api/action/types`,
|
||||
path: `${BASE_ACTION_API_PATH}/types`,
|
||||
validate: {},
|
||||
options: {
|
||||
tags: ['access:actions-read'],
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
KibanaResponseFactory,
|
||||
} from 'kibana/server';
|
||||
import { ILicenseState, verifyApiAccess, isErrorThatHandlesItsOwnResponse } from '../lib';
|
||||
import { BASE_ACTION_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -27,7 +28,7 @@ const bodySchema = schema.object({
|
|||
export const updateActionRoute = (router: IRouter, licenseState: ILicenseState) => {
|
||||
router.put(
|
||||
{
|
||||
path: `/api/action/{id}`,
|
||||
path: `${BASE_ACTION_API_PATH}/{id}`,
|
||||
validate: {
|
||||
body: bodySchema,
|
||||
params: paramSchema,
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { validateDurationSchema } from '../lib';
|
||||
import { Alert } from '../types';
|
||||
import { Alert, BASE_ALERT_API_PATH } from '../types';
|
||||
|
||||
export const bodySchema = schema.object({
|
||||
name: schema.string(),
|
||||
|
@ -42,7 +42,7 @@ export const bodySchema = schema.object({
|
|||
export const createAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert',
|
||||
path: BASE_ALERT_API_PATH,
|
||||
validate: {
|
||||
body: bodySchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const deleteAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.delete(
|
||||
{
|
||||
path: '/api/alert/{id}',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const disableAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{id}/_disable',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}/_disable`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const enableAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{id}/_enable',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}/_enable`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
import { FindOptions } from '../../../alerting/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
// config definition
|
||||
const querySchema = schema.object({
|
||||
|
@ -44,7 +45,7 @@ const querySchema = schema.object({
|
|||
export const findAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: '/api/alert/_find',
|
||||
path: `${BASE_ALERT_API_PATH}/_find`,
|
||||
validate: {
|
||||
query: querySchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const getAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: `/api/alert/{id}`,
|
||||
path: `${BASE_ALERT_API_PATH}/{id}`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const getAlertStateRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: '/api/alert/{id}/state',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}/state`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -13,11 +13,12 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
export const listAlertTypesRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.get(
|
||||
{
|
||||
path: `/api/alert/types`,
|
||||
path: `${BASE_ALERT_API_PATH}/types`,
|
||||
validate: {},
|
||||
options: {
|
||||
tags: ['access:alerting-read'],
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const muteAllAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{id}/_mute_all',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}/_mute_all`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
alertId: schema.string(),
|
||||
|
@ -23,7 +24,7 @@ const paramSchema = schema.object({
|
|||
export const muteAlertInstanceRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{alertId}/alert_instance/{alertInstanceId}/_mute',
|
||||
path: `${BASE_ALERT_API_PATH}/{alertId}/alert_instance/{alertInstanceId}/_mute`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const unmuteAllAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{id}/_unmute_all',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}/_unmute_all`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
alertId: schema.string(),
|
||||
|
@ -23,7 +24,7 @@ const paramSchema = schema.object({
|
|||
export const unmuteAlertInstanceRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute',
|
||||
path: `${BASE_ALERT_API_PATH}/{alertId}/alert_instance/{alertInstanceId}/_unmute`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { validateDurationSchema } from '../lib';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -42,7 +43,7 @@ const bodySchema = schema.object({
|
|||
export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.put(
|
||||
{
|
||||
path: '/api/alert/{id}',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}`,
|
||||
validate: {
|
||||
body: bodySchema,
|
||||
params: paramSchema,
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from 'kibana/server';
|
||||
import { LicenseState } from '../lib/license_state';
|
||||
import { verifyApiAccess } from '../lib/license_api_access';
|
||||
import { BASE_ALERT_API_PATH } from '../../common';
|
||||
|
||||
const paramSchema = schema.object({
|
||||
id: schema.string(),
|
||||
|
@ -22,7 +23,7 @@ const paramSchema = schema.object({
|
|||
export const updateApiKeyRoute = (router: IRouter, licenseState: LicenseState) => {
|
||||
router.post(
|
||||
{
|
||||
path: '/api/alert/{id}/_update_api_key',
|
||||
path: `${BASE_ALERT_API_PATH}/{id}/_update_api_key`,
|
||||
validate: {
|
||||
params: paramSchema,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue