mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-27 08:32:15 +00:00
c92ed69ce8
* cli: move commands to cli/cmd * cli: use StatusAPI interface for config command * cli: use SilenceAPI interface for silence commands * cli: use AlertAPI for alert command * cli: move back commands to cli package And move API client code to its own package. * cli: remove unused structs
43 lines
889 B
Go
43 lines
889 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/alecthomas/kingpin"
|
|
"github.com/prometheus/client_golang/api"
|
|
|
|
"github.com/prometheus/alertmanager/client"
|
|
)
|
|
|
|
var (
|
|
expireCmd = silenceCmd.Command("expire", "expire an alertmanager silence")
|
|
expireIds = expireCmd.Arg("silence-ids", "Ids of silences to expire").Strings()
|
|
)
|
|
|
|
func init() {
|
|
expireCmd.Action(expire)
|
|
longHelpText["silence expire"] = `Expire an alertmanager silence`
|
|
}
|
|
|
|
func expire(element *kingpin.ParseElement, ctx *kingpin.ParseContext) error {
|
|
if len(*expireIds) < 1 {
|
|
return errors.New("no silence IDs specified")
|
|
}
|
|
|
|
c, err := api.NewClient(api.Config{Address: (*alertmanagerUrl).String()})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
silenceAPI := client.NewSilenceAPI(c)
|
|
|
|
for _, id := range *expireIds {
|
|
err := silenceAPI.Delete(context.Background(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|