Skip to content

Commit 9e1b2cb

Browse files
authored
feat(cockpit): add EnablePreconfiguredAlertRules endpoint (#2519)
1 parent 839939d commit 9e1b2cb

File tree

1 file changed

+116
-4
lines changed

1 file changed

+116
-4
lines changed

api/cockpit/v1/cockpit_sdk.go

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,18 @@ func (enum *UsageUnit) UnmarshalJSON(data []byte) error {
518518
return nil
519519
}
520520

521+
// PreconfiguredAlertData: Structure for additional data relative to preconfigured alerts.
522+
type PreconfiguredAlertData struct {
523+
// PreconfiguredRuleID: ID of the preconfigured rule if the alert is preconfigured.
524+
PreconfiguredRuleID string `json:"preconfigured_rule_id"`
525+
526+
// DisplayName: human readable name of the alert.
527+
DisplayName string `json:"display_name"`
528+
529+
// DisplayDescription: human readable description of the alert.
530+
DisplayDescription string `json:"display_description"`
531+
}
532+
521533
// ContactPointEmail: contact point email.
522534
type ContactPointEmail struct {
523535
To string `json:"to"`
@@ -532,25 +544,35 @@ type GetConfigResponseRetention struct {
532544
DefaultDays uint32 `json:"default_days"`
533545
}
534546

535-
// Alert: alert.
547+
// Alert: Structure representing an alert.
536548
type Alert struct {
537-
// Region: region to target. If none is passed will use default region from the config.
549+
// Region: the region in which the alert is defined.
538550
Region scw.Region `json:"region"`
539551

552+
// Preconfigured: indicates if the alert is preconfigured or custom.
540553
Preconfigured bool `json:"preconfigured"`
541554

555+
// Name: name of the alert.
542556
Name string `json:"name"`
543557

558+
// Rule: rule defining the alert condition.
544559
Rule string `json:"rule"`
545560

561+
// Duration: duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
546562
Duration string `json:"duration"`
547563

564+
// Enabled: indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
548565
Enabled bool `json:"enabled"`
549566

550-
// State: default value: unknown_state
567+
// State: current state of the alert. Possible states are `inactive`, `pending`, and `firing`.
568+
// Default value: unknown_state
551569
State *AlertState `json:"state"`
552570

571+
// Annotations: annotations for the alert, used to provide additional information about the alert.
553572
Annotations map[string]string `json:"annotations"`
573+
574+
// PreconfiguredData: contains additional data for preconfigured alerts, such as the rule ID, display name, and description. Only present if the alert is preconfigured.
575+
PreconfiguredData *PreconfiguredAlertData `json:"preconfigured_data"`
554576
}
555577

556578
// ContactPoint: Contact point.
@@ -1165,6 +1187,16 @@ type RegionalAPIDisableAlertManagerRequest struct {
11651187
ProjectID string `json:"project_id"`
11661188
}
11671189

1190+
// RegionalAPIDisableAlertRulesRequest: regional api disable alert rules request.
1191+
type RegionalAPIDisableAlertRulesRequest struct {
1192+
// Region: region to target. If none is passed will use default region from the config.
1193+
Region scw.Region `json:"-"`
1194+
1195+
ProjectID string `json:"project_id"`
1196+
1197+
RuleIDs []string `json:"rule_ids"`
1198+
}
1199+
11681200
// RegionalAPIDisableManagedAlertsRequest: Disable the sending of managed alerts.
11691201
type RegionalAPIDisableManagedAlertsRequest struct {
11701202
// Region: region to target. If none is passed will use default region from the config.
@@ -1183,6 +1215,16 @@ type RegionalAPIEnableAlertManagerRequest struct {
11831215
ProjectID string `json:"project_id"`
11841216
}
11851217

1218+
// RegionalAPIEnableAlertRulesRequest: regional api enable alert rules request.
1219+
type RegionalAPIEnableAlertRulesRequest struct {
1220+
// Region: region to target. If none is passed will use default region from the config.
1221+
Region scw.Region `json:"-"`
1222+
1223+
ProjectID string `json:"project_id"`
1224+
1225+
RuleIDs []string `json:"rule_ids"`
1226+
}
1227+
11861228
// RegionalAPIEnableManagedAlertsRequest: Enable the sending of managed alerts.
11871229
type RegionalAPIEnableManagedAlertsRequest struct {
11881230
// Region: region to target. If none is passed will use default region from the config.
@@ -1249,7 +1291,7 @@ type RegionalAPIListAlertsRequest struct {
12491291
// IsPreconfigured: true returns only preconfigured alerts. False returns only custom alerts. If omitted, no filtering is applied on alert types. Other filters may still apply.
12501292
IsPreconfigured *bool `json:"-"`
12511293

1252-
// State: 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.
1294+
// State: valid values to filter on are `inactive`, `pending` and `firing`. If omitted, no filtering is applied on alert states. Other filters may still apply.
12531295
// Default value: unknown_state
12541296
State *AlertState `json:"-"`
12551297
}
@@ -2502,6 +2544,76 @@ func (s *RegionalAPI) DisableManagedAlerts(req *RegionalAPIDisableManagedAlertsR
25022544
return &resp, nil
25032545
}
25042546

2547+
// EnableAlertRules: Enable preconfigured alert rules. Enable alert rules from the list of available preconfigured rules.
2548+
func (s *RegionalAPI) EnableAlertRules(req *RegionalAPIEnableAlertRulesRequest, opts ...scw.RequestOption) error {
2549+
var err error
2550+
2551+
if req.Region == "" {
2552+
defaultRegion, _ := s.client.GetDefaultRegion()
2553+
req.Region = defaultRegion
2554+
}
2555+
2556+
if req.ProjectID == "" {
2557+
defaultProjectID, _ := s.client.GetDefaultProjectID()
2558+
req.ProjectID = defaultProjectID
2559+
}
2560+
2561+
if fmt.Sprint(req.Region) == "" {
2562+
return errors.New("field Region cannot be empty in request")
2563+
}
2564+
2565+
scwReq := &scw.ScalewayRequest{
2566+
Method: "POST",
2567+
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/alert-manager/enable-alert-rules",
2568+
}
2569+
2570+
err = scwReq.SetBody(req)
2571+
if err != nil {
2572+
return err
2573+
}
2574+
2575+
err = s.client.Do(scwReq, nil, opts...)
2576+
if err != nil {
2577+
return err
2578+
}
2579+
return nil
2580+
}
2581+
2582+
// DisableAlertRules: Disable preconfigured alert rules. Disable alert rules from the list of available preconfigured rules.
2583+
func (s *RegionalAPI) DisableAlertRules(req *RegionalAPIDisableAlertRulesRequest, opts ...scw.RequestOption) error {
2584+
var err error
2585+
2586+
if req.Region == "" {
2587+
defaultRegion, _ := s.client.GetDefaultRegion()
2588+
req.Region = defaultRegion
2589+
}
2590+
2591+
if req.ProjectID == "" {
2592+
defaultProjectID, _ := s.client.GetDefaultProjectID()
2593+
req.ProjectID = defaultProjectID
2594+
}
2595+
2596+
if fmt.Sprint(req.Region) == "" {
2597+
return errors.New("field Region cannot be empty in request")
2598+
}
2599+
2600+
scwReq := &scw.ScalewayRequest{
2601+
Method: "POST",
2602+
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/alert-manager/disable-alert-rules",
2603+
}
2604+
2605+
err = scwReq.SetBody(req)
2606+
if err != nil {
2607+
return err
2608+
}
2609+
2610+
err = s.client.Do(scwReq, nil, opts...)
2611+
if err != nil {
2612+
return err
2613+
}
2614+
return nil
2615+
}
2616+
25052617
// TriggerTestAlert: Send a test alert to the Alert manager to make sure your contact points get notified.
25062618
func (s *RegionalAPI) TriggerTestAlert(req *RegionalAPITriggerTestAlertRequest, opts ...scw.RequestOption) error {
25072619
var err error

0 commit comments

Comments
 (0)