diff --git a/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx b/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx index 9d51ea64..063d891c 100644 --- a/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx +++ b/grafana-plugin/src/containers/IntegrationForm/IntegrationForm.tsx @@ -51,13 +51,9 @@ interface FormFields { alert_manager?: string; contact_point?: string; integration: ApiSchemas['AlertReceiveChannel']['integration']; + create_default_webhooks: boolean; - additional_settings: { - instance_url: string; - username: string; - password: string; - default_webhooks: boolean; - }; + additional_settings: ApiSchemas['AlertReceiveChannel']['additional_settings']; } interface IntegrationFormProps { @@ -106,6 +102,13 @@ export const IntegrationForm = observer( instance_url: undefined, password: undefined, username: undefined, + is_configured: false, + state_mapping: { + acknowledged: undefined, + firing: undefined, + resolved: undefined, + silenced: undefined, + }, }, } : prepareForEdit(alertReceiveChannelStore.items[id]); @@ -117,9 +120,7 @@ export const IntegrationForm = observer( ? { // these are the default values for creating an integration integration, - additional_settings: { - default_webhooks: true, - }, + additional_settings: {}, } : { // existing values from existing integration (edit-mode) @@ -338,7 +339,7 @@ export const IntegrationForm = observer( (
@@ -390,7 +391,7 @@ export const IntegrationForm = observer( async function onFormSubmit(formData: FormFields): Promise { const labels = labelsRef.current?.getValue(); - const data: OmitReadonlyMembers = { + const data: OmitReadonlyMembers = { labels, ...formData, }; @@ -418,7 +419,7 @@ export const IntegrationForm = observer( await onSubmit(); onHide(); - async function createNewIntegration(): Promise { + async function createNewIntegration(): Promise { const response = await alertReceiveChannelStore.create({ data, skipErrorHandling: true }); const pushHistory = (id: ApiSchemas['AlertReceiveChannel']['id']) => history.push(`${PLUGIN_ROOT}/integrations/${id}`); diff --git a/grafana-plugin/src/containers/ServiceNowConfigDrawer/ServiceNowConfigDrawer.tsx b/grafana-plugin/src/containers/ServiceNowConfigDrawer/ServiceNowConfigDrawer.tsx index c05bab2b..43c64a8b 100644 --- a/grafana-plugin/src/containers/ServiceNowConfigDrawer/ServiceNowConfigDrawer.tsx +++ b/grafana-plugin/src/containers/ServiceNowConfigDrawer/ServiceNowConfigDrawer.tsx @@ -42,18 +42,7 @@ enum OnCallAGStatus { } interface FormFields { - additional_settings: { - instance_url: string; - username: string; - password: string; - - state_mapping?: { - firing: string; - acknowledged: string; - resolved: string; - silenced: string; - }; - }; + additional_settings: ApiSchemas['AlertReceiveChannel']['additional_settings']; } interface StatusMapping { diff --git a/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts b/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts index e7702699..5717c998 100644 --- a/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts +++ b/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts @@ -49,12 +49,12 @@ export class AlertReceiveChannelStore { data, skipErrorHandling, }: { - data: OmitReadonlyMembers; + data: OmitReadonlyMembers; skipErrorHandling?: boolean; }) { const result = await onCallApi({ skipErrorHandling }).POST('/alert_receive_channels/', { params: {}, - body: data as ApiSchemas['AlertReceiveChannel'], + body: data as ApiSchemas['AlertReceiveChannelCreate'], }); await this.rootStore.organizationStore.loadCurrentOrganization(); return result.data; diff --git a/grafana-plugin/src/network/oncall-api/autogenerated-api.types.d.ts b/grafana-plugin/src/network/oncall-api/autogenerated-api.types.d.ts index 6f7f7656..7f9fa049 100644 --- a/grafana-plugin/src/network/oncall-api/autogenerated-api.types.d.ts +++ b/grafana-plugin/src/network/oncall-api/autogenerated-api.types.d.ts @@ -1190,6 +1190,7 @@ export interface components { * @enum {string} */ ActionEnum: 'acknowledge' | 'resolve' | 'silence' | 'restart'; + AdditionalSettingsField: components['schemas']['Settings']; Alert: { readonly id: string; /** Format: uri */ @@ -1445,17 +1446,7 @@ export interface components { alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels']; /** Format: date-time */ readonly alertmanager_v2_migrated_at: string | null; - additional_settings?: { - instance_url: string; - username: string; - password: string; - state_mapping?: { - firing: string; - acknowledged: string; - resolved: string; - silenced: string; - }; - }; + additional_settings?: components['schemas']['AdditionalSettingsField'] | null; }; AlertReceiveChannelConnectContactPoint: { datasource_uid: string; @@ -1483,6 +1474,49 @@ export interface components { name: string; contact_points: string[]; }; + AlertReceiveChannelCreate: { + readonly id: string; + readonly description: string | null; + description_short?: string | null; + integration: components['schemas']['IntegrationEnum']; + readonly smile_code: string; + verbal_name?: string | null; + readonly author: string; + readonly organization: string; + team?: string | null; + /** Format: date-time */ + readonly created_at: string; + readonly integration_url: string | null; + readonly alert_count: number; + readonly alert_groups_count: number; + allow_source_based_resolving?: boolean; + readonly instructions: string; + readonly is_able_to_autoresolve: boolean; + readonly default_channel_filter: string | null; + readonly demo_alert_enabled: boolean; + readonly maintenance_mode: + | (components['schemas']['MaintenanceModeEnum'] | components['schemas']['NullEnum']) + | null; + readonly maintenance_till: number | null; + readonly heartbeat: components['schemas']['IntegrationHeartBeat'] | null; + readonly is_available_for_integration_heartbeat: boolean; + readonly allow_delete: boolean; + readonly demo_alert_payload: { + [key: string]: unknown; + }; + readonly routes_count: number; + readonly connected_escalations_chains_count: number; + readonly is_based_on_alertmanager: boolean; + readonly inbound_email: string; + readonly is_legacy: boolean; + labels?: components['schemas']['LabelPair'][]; + alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels']; + /** Format: date-time */ + readonly alertmanager_v2_migrated_at: string | null; + additional_settings?: components['schemas']['AdditionalSettingsField'] | null; + /** @default true */ + create_default_webhooks: boolean; + }; AlertReceiveChannelCreateContactPoint: { datasource_uid: string; contact_point_name: string; @@ -1564,17 +1598,7 @@ export interface components { alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels']; /** Format: date-time */ readonly alertmanager_v2_migrated_at: string | null; - additional_settings?: { - instance_url: string; - username: string; - password: string; - state_mapping?: { - firing: string; - acknowledged: string; - resolved: string; - silenced: string; - }; - }; + additional_settings?: components['schemas']['AdditionalSettingsField'] | null; }; /** @enum {integer} */ CloudConnectionStatusEnum: 0 | 1 | 2 | 3; @@ -1882,17 +1906,7 @@ export interface components { alert_group_labels?: components['schemas']['IntegrationAlertGroupLabels']; /** Format: date-time */ readonly alertmanager_v2_migrated_at?: string | null; - additional_settings?: { - instance_url: 'string'; - username: 'string'; - password: 'string'; - state_mapping?: { - firing: null; - acknowledged: null; - resolved: null; - silenced: null; - }; - }; + additional_settings?: components['schemas']['AdditionalSettingsField'] | null; }; PatchedUser: { readonly pk?: string; @@ -1960,6 +1974,20 @@ export interface components { * @enum {integer} */ RoleEnum: 0 | 1 | 2 | 3; + Settings: { + instance_url: string; + username: string; + password: string; + /** @default { + * "firing": null, + * "acknowledged": null, + * "resolved": null, + * "silenced": null + * } */ + state_mapping: components['schemas']['StateMapping']; + /** @default false */ + is_configured: boolean; + }; ShortAlertGroup: { readonly pk: string; readonly render_for_web: @@ -1980,6 +2008,12 @@ export interface components { readonly name: string; readonly display_name: string | null; }; + StateMapping: { + firing: unknown[] | null; + acknowledged: unknown[] | null; + resolved: unknown[] | null; + silenced: unknown[] | null; + }; TelegramToUserConnector: { telegram_nick_name?: string | null; /** Format: int64 */ @@ -2291,9 +2325,9 @@ export interface operations { }; requestBody: { content: { - 'application/json': components['schemas']['AlertReceiveChannel']; - 'application/x-www-form-urlencoded': components['schemas']['AlertReceiveChannel']; - 'multipart/form-data': components['schemas']['AlertReceiveChannel']; + 'application/json': components['schemas']['AlertReceiveChannelCreate']; + 'application/x-www-form-urlencoded': components['schemas']['AlertReceiveChannelCreate']; + 'multipart/form-data': components['schemas']['AlertReceiveChannelCreate']; }; }; responses: { @@ -2302,7 +2336,7 @@ export interface operations { [name: string]: unknown; }; content: { - 'application/json': components['schemas']['AlertReceiveChannel']; + 'application/json': components['schemas']['AlertReceiveChannelCreate']; }; }; };