diff --git a/packages/clients/src/api/cockpit/v1/api.gen.ts b/packages/clients/src/api/cockpit/v1/api.gen.ts index e0a22cb34..aeb7de93a 100644 --- a/packages/clients/src/api/cockpit/v1/api.gen.ts +++ b/packages/clients/src/api/cockpit/v1/api.gen.ts @@ -31,6 +31,7 @@ import { unmarshalListDataSourcesResponse, unmarshalListGrafanaProductDashboardsResponse, unmarshalListGrafanaUsersResponse, + unmarshalListManagedAlertsResponse, unmarshalListPlansResponse, unmarshalListTokensResponse, unmarshalPlan, @@ -59,6 +60,7 @@ import type { ListDataSourcesResponse, ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, + ListManagedAlertsResponse, ListPlansResponse, ListTokensResponse, Plan, @@ -78,6 +80,7 @@ import type { RegionalApiGetUsageOverviewRequest, RegionalApiListContactPointsRequest, RegionalApiListDataSourcesRequest, + RegionalApiListManagedAlertsRequest, RegionalApiListTokensRequest, RegionalApiTriggerTestAlertRequest, Token, @@ -759,6 +762,39 @@ export class RegionalAPI extends ParentAPI { path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/contact-points/delete`, }) + protected pageOfListManagedAlerts = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/managed-alerts`, + urlParams: urlParams( + ['order_by', request.orderBy], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ), + }, + unmarshalListManagedAlertsResponse, + ) + + /** + * List managed alerts. List all managed alerts for the specified Project. + * + * @param request - The request {@link RegionalApiListManagedAlertsRequest} + * @returns A Promise of ListManagedAlertsResponse + */ + listManagedAlerts = ( + request: Readonly = {}, + ) => enrichForPagination('alerts', this.pageOfListManagedAlerts, request) + /** * Enable managed alerts. Enable the sending of managed alerts for the * specified Project. Managed alerts are predefined alerts that apply to diff --git a/packages/clients/src/api/cockpit/v1/index.gen.ts b/packages/clients/src/api/cockpit/v1/index.gen.ts index 40c7c709c..ef05544e7 100644 --- a/packages/clients/src/api/cockpit/v1/index.gen.ts +++ b/packages/clients/src/api/cockpit/v1/index.gen.ts @@ -2,6 +2,7 @@ // If you have any remark or suggestion do not hesitate to open an issue. export { GlobalAPI, RegionalAPI } from './api.gen' export type { + Alert, AlertManager, ContactPoint, ContactPointEmail, @@ -29,6 +30,8 @@ export type { ListGrafanaProductDashboardsResponse, ListGrafanaUsersRequestOrderBy, ListGrafanaUsersResponse, + ListManagedAlertsRequestOrderBy, + ListManagedAlertsResponse, ListPlansRequestOrderBy, ListPlansResponse, ListTokensRequestOrderBy, @@ -51,6 +54,7 @@ export type { RegionalApiGetUsageOverviewRequest, RegionalApiListContactPointsRequest, RegionalApiListDataSourcesRequest, + RegionalApiListManagedAlertsRequest, RegionalApiListTokensRequest, RegionalApiTriggerTestAlertRequest, Token, diff --git a/packages/clients/src/api/cockpit/v1/marshalling.gen.ts b/packages/clients/src/api/cockpit/v1/marshalling.gen.ts index 22b20825e..ab6719985 100644 --- a/packages/clients/src/api/cockpit/v1/marshalling.gen.ts +++ b/packages/clients/src/api/cockpit/v1/marshalling.gen.ts @@ -8,6 +8,7 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + Alert, AlertManager, ContactPoint, ContactPointEmail, @@ -23,6 +24,7 @@ import type { ListDataSourcesResponse, ListGrafanaProductDashboardsResponse, ListGrafanaUsersResponse, + ListManagedAlertsResponse, ListPlansResponse, ListTokensResponse, Plan, @@ -255,6 +257,37 @@ export const unmarshalListGrafanaUsersResponse = ( } as ListGrafanaUsersResponse } +const unmarshalAlert = (data: unknown): Alert => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Alert' failed as data isn't a dictionary.`, + ) + } + + return { + description: data.description, + name: data.name, + product: data.product, + productFamily: data.product_family, + rule: data.rule, + } as Alert +} + +export const unmarshalListManagedAlertsResponse = ( + data: unknown, +): ListManagedAlertsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListManagedAlertsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + alerts: unmarshalArrayOfObject(data.alerts, unmarshalAlert), + totalCount: data.total_count, + } as ListManagedAlertsResponse +} + export const unmarshalListPlansResponse = ( data: unknown, ): ListPlansResponse => { diff --git a/packages/clients/src/api/cockpit/v1/types.gen.ts b/packages/clients/src/api/cockpit/v1/types.gen.ts index cb06e31d9..c62f935ec 100644 --- a/packages/clients/src/api/cockpit/v1/types.gen.ts +++ b/packages/clients/src/api/cockpit/v1/types.gen.ts @@ -18,6 +18,14 @@ export type ListDataSourcesRequestOrderBy = export type ListGrafanaUsersRequestOrderBy = 'login_asc' | 'login_desc' +export type ListManagedAlertsRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + | 'type_asc' + | 'type_desc' + export type ListPlansRequestOrderBy = 'name_asc' | 'name_desc' export type ListTokensRequestOrderBy = @@ -111,6 +119,14 @@ export interface GrafanaUser { password?: string } +export interface Alert { + productFamily: string + product: string + name: string + rule: string + description: string +} + /** Type of pricing plan. */ export interface Plan { /** Name of a given pricing plan. */ @@ -330,6 +346,14 @@ export interface ListGrafanaUsersResponse { grafanaUsers: GrafanaUser[] } +/** Response returned when listing data sources. */ +export interface ListManagedAlertsResponse { + /** Total count of data sources matching the request. */ + totalCount: number + /** Alerts matching the request within the pagination. */ + alerts: Alert[] +} + /** Output returned when listing pricing plans. */ export interface ListPlansResponse { /** Total count of available pricing plans. */ @@ -564,6 +588,26 @@ export type RegionalApiListDataSourcesRequest = { types?: DataSourceType[] } +/** Enable the sending of managed alerts. */ +export type RegionalApiListManagedAlertsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Page number to return, from the paginated results. */ + page?: number + /** Number of data sources to return per page. */ + pageSize?: number + /** Sort order for data sources in the response. */ + orderBy?: ListManagedAlertsRequestOrderBy + /** + * Project ID to filter for, only data sources from this Project will be + * returned. + */ + projectId?: string +} + /** List tokens. */ export type RegionalApiListTokensRequest = { /** diff --git a/packages/clients/src/api/cockpit/v1/validation-rules.gen.ts b/packages/clients/src/api/cockpit/v1/validation-rules.gen.ts index 5ba618da7..129ae7f79 100644 --- a/packages/clients/src/api/cockpit/v1/validation-rules.gen.ts +++ b/packages/clients/src/api/cockpit/v1/validation-rules.gen.ts @@ -37,6 +37,16 @@ export const RegionalApiListDataSourcesRequest = { }, } +export const RegionalApiListManagedAlertsRequest = { + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 1000, + }, +} + export const RegionalApiListTokensRequest = { page: { greaterThanOrEqual: 1,