Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cockpit): add received_resolved field #2412

Merged
merged 1 commit into from
Feb 5, 2025
Merged
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
61 changes: 60 additions & 1 deletion api/cockpit/v1/cockpit_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,11 @@ type ContactPoint struct {
// Precisely one of Email must be set.
Email *ContactPointEmail `json:"email,omitempty"`

// Region: region to target. If none is passed will use default region from the config.
// Region: region.
Region scw.Region `json:"region"`

// ReceiveResolvedNotifications: send an email notification when an alert is marked as resolved.
ReceiveResolvedNotifications bool `json:"receive_resolved_notifications"`
}

// DataSource: Data source.
Expand Down Expand Up @@ -1076,6 +1079,9 @@ type RegionalAPICreateContactPointRequest struct {
// Email: email address of the contact point to create.
// Precisely one of Email must be set.
Email *ContactPointEmail `json:"email,omitempty"`

// ReceiveResolvedNotifications: send an email notification when an alert is marked as resolved.
ReceiveResolvedNotifications *bool `json:"receive_resolved_notifications,omitempty"`
}

// RegionalAPICreateDataSourceRequest: Create a data source.
Expand Down Expand Up @@ -1313,6 +1319,22 @@ type RegionalAPITriggerTestAlertRequest struct {
ProjectID string `json:"project_id"`
}

// RegionalAPIUpdateContactPointRequest: Update a contact point.
type RegionalAPIUpdateContactPointRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Region scw.Region `json:"-"`

// ProjectID: ID of the Project containing the contact point to update.
ProjectID string `json:"project_id"`

// Email: email address of the contact point to update.
// Precisely one of Email must be set.
Email *ContactPointEmail `json:"email,omitempty"`

// ReceiveResolvedNotifications: enable or disable notifications when alert is resolved.
ReceiveResolvedNotifications *bool `json:"receive_resolved_notifications,omitempty"`
}

// RegionalAPIUpdateDataSourceRequest: Update a data source name.
type RegionalAPIUpdateDataSourceRequest struct {
// Region: region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -2287,6 +2309,43 @@ func (s *RegionalAPI) ListContactPoints(req *RegionalAPIListContactPointsRequest
return &resp, nil
}

// UpdateContactPoint:
func (s *RegionalAPI) UpdateContactPoint(req *RegionalAPIUpdateContactPointRequest, opts ...scw.RequestOption) (*ContactPoint, error) {
var err error

if req.Region == "" {
defaultRegion, _ := s.client.GetDefaultRegion()
req.Region = defaultRegion
}

if req.ProjectID == "" {
defaultProjectID, _ := s.client.GetDefaultProjectID()
req.ProjectID = defaultProjectID
}

if fmt.Sprint(req.Region) == "" {
return nil, errors.New("field Region cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "PATCH",
Path: "/cockpit/v1/regions/" + fmt.Sprint(req.Region) + "/alert-manager/contact-points",
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp ContactPoint

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// DeleteContactPoint: Delete a contact point associated with the default receiver.
func (s *RegionalAPI) DeleteContactPoint(req *RegionalAPIDeleteContactPointRequest, opts ...scw.RequestOption) error {
var err error
Expand Down