Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/clients/src/api/cockpit/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
unmarshalGrafana,
unmarshalGrafanaProductDashboard,
unmarshalGrafanaUser,
unmarshalListAlertsResponse,
unmarshalListContactPointsResponse,
unmarshalListDataSourcesResponse,
unmarshalListGrafanaProductDashboardsResponse,
Expand Down Expand Up @@ -60,6 +61,7 @@ import type {
Grafana,
GrafanaProductDashboard,
GrafanaUser,
ListAlertsResponse,
ListContactPointsResponse,
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
Expand All @@ -83,6 +85,7 @@ import type {
RegionalApiGetDataSourceRequest,
RegionalApiGetTokenRequest,
RegionalApiGetUsageOverviewRequest,
RegionalApiListAlertsRequest,
RegionalApiListContactPointsRequest,
RegionalApiListDataSourcesRequest,
RegionalApiListManagedAlertsRequest,
Expand Down Expand Up @@ -868,6 +871,31 @@ export class RegionalAPI extends ParentAPI {
request: Readonly<RegionalApiListManagedAlertsRequest> = {},
) => enrichForPagination('alerts', this.pageOfListManagedAlerts, request)

/**
* List alerts. List preconfigured and/or custom alerts for the specified
* Project.
*
* @param request - The request {@link RegionalApiListAlertsRequest}
* @returns A Promise of ListAlertsResponse
*/
listAlerts = (request: Readonly<RegionalApiListAlertsRequest> = {}) =>
this.client.fetch<ListAlertsResponse>(
{
method: 'GET',
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alerts`,
urlParams: urlParams(
['is_enabled', request.isEnabled],
['is_preconfigured', request.isPreconfigured],
[
'project_id',
request.projectId ?? this.client.settings.defaultProjectId,
],
['state', request.state],
),
},
unmarshalListAlertsResponse,
)

/**
* Enable managed alerts. Enable the sending of managed alerts for the
* specified Project. Managed alerts are predefined alerts that apply to
Expand Down
4 changes: 4 additions & 0 deletions packages/clients/src/api/cockpit/v1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export { GlobalAPI, RegionalAPI } from './api.gen'
export type {
Alert,
AlertManager,
AnyAlert,
AnyAlertState,
ContactPoint,
ContactPointEmail,
DataSource,
Expand All @@ -26,6 +28,7 @@ export type {
GrafanaProductDashboard,
GrafanaUser,
GrafanaUserRole,
ListAlertsResponse,
ListContactPointsResponse,
ListDataSourcesRequestOrderBy,
ListDataSourcesResponse,
Expand Down Expand Up @@ -55,6 +58,7 @@ export type {
RegionalApiGetDataSourceRequest,
RegionalApiGetTokenRequest,
RegionalApiGetUsageOverviewRequest,
RegionalApiListAlertsRequest,
RegionalApiListContactPointsRequest,
RegionalApiListDataSourcesRequest,
RegionalApiListManagedAlertsRequest,
Expand Down
35 changes: 35 additions & 0 deletions packages/clients/src/api/cockpit/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { DefaultValues } from '../../../bridge'
import type {
Alert,
AlertManager,
AnyAlert,
ContactPoint,
ContactPointEmail,
DataSource,
Expand All @@ -22,6 +23,7 @@ import type {
Grafana,
GrafanaProductDashboard,
GrafanaUser,
ListAlertsResponse,
ListContactPointsResponse,
ListDataSourcesResponse,
ListGrafanaProductDashboardsResponse,
Expand Down Expand Up @@ -236,6 +238,39 @@ export const unmarshalGrafana = (data: unknown): Grafana => {
} as Grafana
}

const unmarshalAnyAlert = (data: unknown): AnyAlert => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'AnyAlert' failed as data isn't a dictionary.`,
)
}

return {
annotations: data.annotations,
duration: data.duration,
name: data.name,
preconfigured: data.preconfigured,
region: data.region,
rule: data.rule,
state: data.state,
} as AnyAlert
}

export const unmarshalListAlertsResponse = (
data: unknown,
): ListAlertsResponse => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ListAlertsResponse' failed as data isn't a dictionary.`,
)
}

return {
alerts: unmarshalArrayOfObject(data.alerts, unmarshalAnyAlert),
totalCount: data.total_count,
} as ListAlertsResponse
}

export const unmarshalListContactPointsResponse = (
data: unknown,
): ListContactPointsResponse => {
Expand Down
57 changes: 57 additions & 0 deletions packages/clients/src/api/cockpit/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
// If you have any remark or suggestion do not hesitate to open an issue.
import type { Region as ScwRegion } from '../../../bridge'

export type AnyAlertState =
| 'unknown_state'
| 'disabled'
| 'enabled'
| 'pending'
| 'firing'

export type DataSourceOrigin =
| 'unknown_origin'
| 'scaleway'
Expand Down Expand Up @@ -64,6 +71,20 @@ export interface GetConfigResponseRetention {
defaultDays: number
}

export interface AnyAlert {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region: ScwRegion
preconfigured: boolean
name: string
rule: string
duration: string
state: AnyAlertState
annotations: Record<string, string>
}

/** Contact point. */
export interface ContactPoint {
/**
Expand Down Expand Up @@ -329,6 +350,14 @@ export interface Grafana {
grafanaUrl: string
}

/** Retrieve a list of alerts matching the request. */
export interface ListAlertsResponse {
/** Total count of alerts matching the request. */
totalCount: number
/** List of alerts matching the applied filters. */
alerts: AnyAlert[]
}

/** Response returned when listing contact points. */
export interface ListContactPointsResponse {
/** Total count of contact points associated with the default receiver. */
Expand Down Expand Up @@ -581,6 +610,34 @@ export type RegionalApiGetUsageOverviewRequest = {
interval?: string
}

/** Retrieve a list of alerts. */
export type RegionalApiListAlertsRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: ScwRegion
/** Project ID to filter for, only alerts from this Project will be returned. */
projectId?: string
/**
* True returns only enabled alerts. False returns only disabled alerts. If
* omitted, no alert filtering is applied. Other filters may still apply.
*/
isEnabled?: boolean
/**
* True returns only preconfigured alerts. False returns only custom alerts.
* If omitted, no filtering is applied on alert types. Other filters may still
* apply.
*/
isPreconfigured?: boolean
/**
* Valid values to filter on are `disabled`, `enabled`, `pending` and
* `firing`. If omitted, no filtering is applied on alert states. Other
* filters may still apply.
*/
state?: AnyAlertState
}

/** List contact points. */
export type RegionalApiListContactPointsRequest = {
/**
Expand Down
Loading