Skip to content

Commit

Permalink
Add Incident resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbeals committed Nov 17, 2023
1 parent 98d3898 commit de74eb2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/incidents/resolve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package incidents

import (
"github.com/spf13/cobra"

"github.com/uptime-cli/uptimectl/pkg/betteruptime"
)

// deleteCmd represents the get command
var resolveCmd = &cobra.Command{
Use: "resolve",
Short: "Resolve an incident",
Aliases: []string{"res"},
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client := betteruptime.NewClient()

for _, incidentID := range args {
err := client.ResolveIncident(incidentID, acknowledgedBy)
if err != nil {
return err
}
}
return nil
},
}

func init() {
IncidentsCmd.AddCommand(resolveCmd)
resolveCmd.Flags().StringVar(&acknowledgedBy, "acknowledged-by", "uptimectl", "User e-mail or a custom identifier of the entity that acknowledged the incident")
}
21 changes: 21 additions & 0 deletions pkg/betteruptime/incidents.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ func (c *client) AcknowledgeIncident(ctx context.Context, incidentID, acknowledg
return nil
}

func (c *client) ResolveIncident(incidentID string, acknowledgedBy string) error {
endpoint := fmt.Sprintf("%s/%s/%s/resolve", contextmanager.APIEndpoint(), incidentsEndpoint, incidentID)

resp, err := c.rest.R().
SetBody(Acknowledge{
AcknowledgedBy: acknowledgedBy,
}).
Post(endpoint)
if err != nil {
return err
}
if resp.StatusCode() == http.StatusNotFound {
return fmt.Errorf("incident not found")
}

if resp.StatusCode() != http.StatusOK {
return fmt.Errorf("incorrect status response from api")
}
return nil
}

type Acknowledge struct {
AcknowledgedBy string `json:"acknowledged_by"`
}
Expand Down

0 comments on commit de74eb2

Please sign in to comment.