alertmanager/cli/silence_expire.go
Simon Pasquier c92ed69ce8 Split cli package (#1314)
* 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
2018-04-11 11:17:41 +02:00

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
}