Skip to content

Commit f36e6d4

Browse files
feat(cockpit): add rule status on ListAlert endpoint (#2630)
Co-authored-by: Jonathan R. <jremy@scaleway.com>
1 parent 8fdf598 commit f36e6d4

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

api/cockpit/v1/cockpit_sdk.go

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,53 @@ func (enum *AlertState) UnmarshalJSON(data []byte) error {
8383
return nil
8484
}
8585

86+
type AlertStatus string
87+
88+
const (
89+
AlertStatusUnknownStatus = AlertStatus("unknown_status")
90+
// The alert is enabled and may trigger based on its conditions.
91+
AlertStatusEnabled = AlertStatus("enabled")
92+
// The alert is disabled. It will never trigger, and will not be evaluated.
93+
AlertStatusDisabled = AlertStatus("disabled")
94+
// The alert has been marked for activation. It will be enabled momentarily.
95+
AlertStatusEnabling = AlertStatus("enabling")
96+
// The alert has been marked for deactivation. It will be disabled momentarily.
97+
AlertStatusDisabling = AlertStatus("disabling")
98+
)
99+
100+
func (enum AlertStatus) String() string {
101+
if enum == "" {
102+
// return default value if empty
103+
return string(AlertStatusUnknownStatus)
104+
}
105+
return string(enum)
106+
}
107+
108+
func (enum AlertStatus) Values() []AlertStatus {
109+
return []AlertStatus{
110+
"unknown_status",
111+
"enabled",
112+
"disabled",
113+
"enabling",
114+
"disabling",
115+
}
116+
}
117+
118+
func (enum AlertStatus) MarshalJSON() ([]byte, error) {
119+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
120+
}
121+
122+
func (enum *AlertStatus) UnmarshalJSON(data []byte) error {
123+
tmp := ""
124+
125+
if err := json.Unmarshal(data, &tmp); err != nil {
126+
return err
127+
}
128+
129+
*enum = AlertStatus(AlertStatus(tmp).String())
130+
return nil
131+
}
132+
86133
type DataSourceOrigin string
87134

88135
const (
@@ -579,8 +626,9 @@ type Alert struct {
579626
// Duration: duration for which the alert must be active before firing. The format of this duration follows the prometheus duration format.
580627
Duration string `json:"duration"`
581628

582-
// Enabled: indicates if the alert is enabled or disabled. Only preconfigured alerts can be disabled.
583-
Enabled bool `json:"enabled"`
629+
// RuleStatus: indicates if the alert is enabled, enabling, disabled or disabling. Preconfigured alerts can have any of these values, whereas custom alerts can only have the status "enabled".
630+
// Default value: unknown_status
631+
RuleStatus AlertStatus `json:"rule_status"`
584632

585633
// State: current state of the alert. Possible states are `inactive`, `pending`, and `firing`.
586634
// Default value: unknown_state
@@ -1343,8 +1391,9 @@ type RegionalAPIListAlertsRequest struct {
13431391
// ProjectID: project ID to filter for, only alerts from this Project will be returned.
13441392
ProjectID string `json:"-"`
13451393

1346-
// IsEnabled: true returns only enabled alerts. False returns only disabled alerts. If omitted, no alert filtering is applied. Other filters may still apply.
1347-
IsEnabled *bool `json:"-"`
1394+
// RuleStatus: returns only alerts with the given activation status. If omitted, no alert filtering is applied. Other filters may still apply.
1395+
// Default value: unknown_status
1396+
RuleStatus *AlertStatus `json:"-"`
13481397

13491398
// 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.
13501399
IsPreconfigured *bool `json:"-"`
@@ -2539,7 +2588,7 @@ func (s *RegionalAPI) ListAlerts(req *RegionalAPIListAlertsRequest, opts ...scw.
25392588

25402589
query := url.Values{}
25412590
parameter.AddToQuery(query, "project_id", req.ProjectID)
2542-
parameter.AddToQuery(query, "is_enabled", req.IsEnabled)
2591+
parameter.AddToQuery(query, "rule_status", req.RuleStatus)
25432592
parameter.AddToQuery(query, "is_preconfigured", req.IsPreconfigured)
25442593
parameter.AddToQuery(query, "state", req.State)
25452594
parameter.AddToQuery(query, "data_source_id", req.DataSourceID)

0 commit comments

Comments
 (0)