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

UpdateAlert #139

Merged
merged 4 commits into from Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions alerts.go
Expand Up @@ -42,6 +42,7 @@ type Alert struct {
Reason string `json:"reason,omitempty"`
OpenedAt int64 `json:"openedAt,omitempty"`
ClosedAt int64 `json:"closedAt,omitempty"`
Memo string `json:"memo,omitempty"`
}

// AlertsResp includes alert and next id
Expand All @@ -50,6 +51,16 @@ type AlertsResp struct {
NextID string `json:"nextId,omitempty"`
}

// UpdateAlertParam is for UpdateAlert
type UpdateAlertParam struct {
Memo string `json:"memo,omitempty"`
}

// UpdateAlertResponse is for UpdateAlert
type UpdateAlertResponse struct {
Memo string `json:"memo,omitempty"`
}

func (c *Client) findAlertsWithParam(v url.Values) (*AlertsResp, error) {
var d AlertsResp
u := c.urlFor("/api/v0/alerts")
Expand Down Expand Up @@ -138,3 +149,20 @@ func (c *Client) CloseAlert(alertID string, reason string) (*Alert, error) {

return data, nil
}

// UpdateAlert updates an Alert
func (c *Client) UpdateAlert(alertID string, param UpdateAlertParam) (*UpdateAlertResponse, error) {
resp, err := c.PutJSON(fmt.Sprintf("/api/v0/alerts/%s", alertID), param)
defer closeResponse(resp)
if err != nil {
return nil, err
}

var data UpdateAlertResponse
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
return nil, err
}

return &data, nil
}