Skip to content

Commit df01e5e

Browse files
authored
feat(cockpit): add EnablePreconfiguredAlertRules endpoint (#2014)
1 parent caa520e commit df01e5e

File tree

4 files changed

+151
-2
lines changed

4 files changed

+151
-2
lines changed

packages/clients/src/api/cockpit/v1/api.gen.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import {
1717
marshalRegionalApiCreateTokenRequest,
1818
marshalRegionalApiDeleteContactPointRequest,
1919
marshalRegionalApiDisableAlertManagerRequest,
20+
marshalRegionalApiDisableAlertRulesRequest,
2021
marshalRegionalApiDisableManagedAlertsRequest,
2122
marshalRegionalApiEnableAlertManagerRequest,
23+
marshalRegionalApiEnableAlertRulesRequest,
2224
marshalRegionalApiEnableManagedAlertsRequest,
2325
marshalRegionalApiTriggerTestAlertRequest,
2426
marshalRegionalApiUpdateContactPointRequest,
@@ -75,8 +77,10 @@ import type {
7577
RegionalApiDeleteDataSourceRequest,
7678
RegionalApiDeleteTokenRequest,
7779
RegionalApiDisableAlertManagerRequest,
80+
RegionalApiDisableAlertRulesRequest,
7881
RegionalApiDisableManagedAlertsRequest,
7982
RegionalApiEnableAlertManagerRequest,
83+
RegionalApiEnableAlertRulesRequest,
8084
RegionalApiEnableManagedAlertsRequest,
8185
RegionalApiGetAlertManagerRequest,
8286
RegionalApiGetConfigRequest,
@@ -853,6 +857,46 @@ If you need to receive alerts for other receivers, you can create additional con
853857
unmarshalAlertManager,
854858
)
855859

860+
/**
861+
* Enable preconfigured alert rules. Enable alert rules from the list of available preconfigured rules.. Enable preconfigured alert rules. Enable alert rules from the list of available preconfigured rules.
862+
*
863+
* @param request - The request {@link RegionalApiEnableAlertRulesRequest}
864+
*/
865+
enableAlertRules = (
866+
request: Readonly<RegionalApiEnableAlertRulesRequest> = {},
867+
) =>
868+
this.client.fetch<void>({
869+
body: JSON.stringify(
870+
marshalRegionalApiEnableAlertRulesRequest(
871+
request,
872+
this.client.settings,
873+
),
874+
),
875+
headers: jsonContentHeaders,
876+
method: 'POST',
877+
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/enable-alert-rules`,
878+
})
879+
880+
/**
881+
* Disable preconfigured alert rules. Disable alert rules from the list of available preconfigured rules.. Disable preconfigured alert rules. Disable alert rules from the list of available preconfigured rules.
882+
*
883+
* @param request - The request {@link RegionalApiDisableAlertRulesRequest}
884+
*/
885+
disableAlertRules = (
886+
request: Readonly<RegionalApiDisableAlertRulesRequest> = {},
887+
) =>
888+
this.client.fetch<void>({
889+
body: JSON.stringify(
890+
marshalRegionalApiDisableAlertRulesRequest(
891+
request,
892+
this.client.settings,
893+
),
894+
),
895+
headers: jsonContentHeaders,
896+
method: 'POST',
897+
path: `/cockpit/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/alert-manager/disable-alert-rules`,
898+
})
899+
856900
/**
857901
* Trigger a test alert. Send a test alert to the Alert manager to make sure your contact points get notified.
858902
*

packages/clients/src/api/cockpit/v1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ export type {
4343
ListTokensResponse,
4444
Plan,
4545
PlanName,
46+
PreconfiguredAlertData,
4647
RegionalApiCreateContactPointRequest,
4748
RegionalApiCreateDataSourceRequest,
4849
RegionalApiCreateTokenRequest,
4950
RegionalApiDeleteContactPointRequest,
5051
RegionalApiDeleteDataSourceRequest,
5152
RegionalApiDeleteTokenRequest,
5253
RegionalApiDisableAlertManagerRequest,
54+
RegionalApiDisableAlertRulesRequest,
5355
RegionalApiDisableManagedAlertsRequest,
5456
RegionalApiEnableAlertManagerRequest,
57+
RegionalApiEnableAlertRulesRequest,
5558
RegionalApiEnableManagedAlertsRequest,
5659
RegionalApiGetAlertManagerRequest,
5760
RegionalApiGetConfigRequest,

packages/clients/src/api/cockpit/v1/marshalling.gen.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ import type {
3030
ListPlansResponse,
3131
ListTokensResponse,
3232
Plan,
33+
PreconfiguredAlertData,
3334
RegionalApiCreateContactPointRequest,
3435
RegionalApiCreateDataSourceRequest,
3536
RegionalApiCreateTokenRequest,
3637
RegionalApiDeleteContactPointRequest,
3738
RegionalApiDisableAlertManagerRequest,
39+
RegionalApiDisableAlertRulesRequest,
3840
RegionalApiDisableManagedAlertsRequest,
3941
RegionalApiEnableAlertManagerRequest,
42+
RegionalApiEnableAlertRulesRequest,
4043
RegionalApiEnableManagedAlertsRequest,
4144
RegionalApiTriggerTestAlertRequest,
4245
RegionalApiUpdateContactPointRequest,
@@ -236,6 +239,22 @@ export const unmarshalGrafana = (data: unknown): Grafana => {
236239
} as Grafana
237240
}
238241

242+
const unmarshalPreconfiguredAlertData = (
243+
data: unknown,
244+
): PreconfiguredAlertData => {
245+
if (!isJSONObject(data)) {
246+
throw new TypeError(
247+
`Unmarshalling the type 'PreconfiguredAlertData' failed as data isn't a dictionary.`,
248+
)
249+
}
250+
251+
return {
252+
displayDescription: data.display_description,
253+
displayName: data.display_name,
254+
preconfiguredRuleId: data.preconfigured_rule_id,
255+
} as PreconfiguredAlertData
256+
}
257+
239258
const unmarshalAlert = (data: unknown): Alert => {
240259
if (!isJSONObject(data)) {
241260
throw new TypeError(
@@ -249,6 +268,9 @@ const unmarshalAlert = (data: unknown): Alert => {
249268
enabled: data.enabled,
250269
name: data.name,
251270
preconfigured: data.preconfigured,
271+
preconfiguredData: data.preconfigured_data
272+
? unmarshalPreconfiguredAlertData(data.preconfigured_data)
273+
: undefined,
252274
region: data.region,
253275
rule: data.rule,
254276
state: data.state ? data.state : undefined,
@@ -514,6 +536,14 @@ export const marshalRegionalApiDisableAlertManagerRequest = (
514536
project_id: request.projectId ?? defaults.defaultProjectId,
515537
})
516538

539+
export const marshalRegionalApiDisableAlertRulesRequest = (
540+
request: RegionalApiDisableAlertRulesRequest,
541+
defaults: DefaultValues,
542+
): Record<string, unknown> => ({
543+
project_id: request.projectId ?? defaults.defaultProjectId,
544+
rule_ids: request.ruleIds,
545+
})
546+
517547
export const marshalRegionalApiDisableManagedAlertsRequest = (
518548
request: RegionalApiDisableManagedAlertsRequest,
519549
defaults: DefaultValues,
@@ -528,6 +558,14 @@ export const marshalRegionalApiEnableAlertManagerRequest = (
528558
project_id: request.projectId ?? defaults.defaultProjectId,
529559
})
530560

561+
export const marshalRegionalApiEnableAlertRulesRequest = (
562+
request: RegionalApiEnableAlertRulesRequest,
563+
defaults: DefaultValues,
564+
): Record<string, unknown> => ({
565+
project_id: request.projectId ?? defaults.defaultProjectId,
566+
rule_ids: request.ruleIds,
567+
})
568+
531569
export const marshalRegionalApiEnableManagedAlertsRequest = (
532570
request: RegionalApiEnableManagedAlertsRequest,
533571
defaults: DefaultValues,

packages/clients/src/api/cockpit/v1/types.gen.ts

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ export type TokenScope =
4848

4949
export type UsageUnit = 'unknown_unit' | 'bytes' | 'samples'
5050

51+
/**
52+
* Structure for additional data relative to preconfigured alerts.
53+
*/
54+
export interface PreconfiguredAlertData {
55+
/**
56+
* ID of the preconfigured rule if the alert is preconfigured.
57+
*/
58+
preconfiguredRuleId: string
59+
/**
60+
* Human readable name of the alert.
61+
*/
62+
displayName: string
63+
/**
64+
* Human readable description of the alert.
65+
*/
66+
displayDescription: string
67+
}
68+
5169
export interface ContactPointEmail {
5270
to: string
5371
}
@@ -58,18 +76,46 @@ export interface GetConfigResponseRetention {
5876
defaultDays: number
5977
}
6078

79+
/**
80+
* Structure representing an alert.
81+
*/
6182
export interface Alert {
6283
/**
63-
* Region to target. If none is passed will use default region from the config.
84+
* The region in which the alert is defined.
6485
*/
6586
region: ScwRegion
87+
/**
88+
* Indicates if the alert is preconfigured or custom.
89+
*/
6690
preconfigured: boolean
91+
/**
92+
* Name of the alert.
93+
*/
6794
name: string
95+
/**
96+
* Rule defining the alert condition.
97+
*/
6898
rule: string
99+
/**
100+
* Duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
101+
*/
69102
duration: string
103+
/**
104+
* Indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
105+
*/
70106
enabled: boolean
107+
/**
108+
* Current state of the alert. Possible states are `inactive`, `pending`, and `firing`.
109+
*/
71110
state?: AlertState
111+
/**
112+
* Annotations for the alert, used to provide additional information about the alert.
113+
*/
72114
annotations: Record<string, string>
115+
/**
116+
* Contains additional data for preconfigured alerts, such as the rule ID, display name, and description. Only present if the alert is preconfigured.
117+
*/
118+
preconfiguredData?: PreconfiguredAlertData
73119
}
74120

75121
/**
@@ -765,6 +811,15 @@ export type RegionalApiDisableAlertManagerRequest = {
765811
projectId?: string
766812
}
767813

814+
export type RegionalApiDisableAlertRulesRequest = {
815+
/**
816+
* Region to target. If none is passed will use default region from the config.
817+
*/
818+
region?: ScwRegion
819+
projectId?: string
820+
ruleIds?: string[]
821+
}
822+
768823
/**
769824
* Disable the sending of managed alerts.
770825
*/
@@ -793,6 +848,15 @@ export type RegionalApiEnableAlertManagerRequest = {
793848
projectId?: string
794849
}
795850

851+
export type RegionalApiEnableAlertRulesRequest = {
852+
/**
853+
* Region to target. If none is passed will use default region from the config.
854+
*/
855+
region?: ScwRegion
856+
projectId?: string
857+
ruleIds?: string[]
858+
}
859+
796860
/**
797861
* Enable the sending of managed alerts.
798862
*/
@@ -889,7 +953,7 @@ export type RegionalApiListAlertsRequest = {
889953
*/
890954
isPreconfigured?: boolean
891955
/**
892-
* 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.
956+
* Valid values to filter on are `inactive`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply.
893957
*/
894958
state?: AlertState
895959
}

0 commit comments

Comments
 (0)