2017-04-20 09:04:17 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2018-04-11 09:17:41 +00:00
|
|
|
"context"
|
2017-04-20 09:04:17 +00:00
|
|
|
"errors"
|
|
|
|
|
2018-04-11 09:17:41 +00:00
|
|
|
"github.com/prometheus/client_golang/api"
|
2018-04-24 07:35:15 +00:00
|
|
|
"gopkg.in/alecthomas/kingpin.v2"
|
2018-04-11 09:17:41 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/alertmanager/client"
|
2017-04-20 09:04:17 +00:00
|
|
|
)
|
|
|
|
|
2018-04-13 11:34:16 +00:00
|
|
|
type silenceExpireCmd struct {
|
|
|
|
ids []string
|
|
|
|
}
|
|
|
|
|
2018-04-24 07:35:15 +00:00
|
|
|
func configureSilenceExpireCmd(cc *kingpin.CmdClause) {
|
2018-04-13 11:34:16 +00:00
|
|
|
var (
|
|
|
|
c = &silenceExpireCmd{}
|
|
|
|
expireCmd = cc.Command("expire", "expire an alertmanager silence")
|
|
|
|
)
|
|
|
|
expireCmd.Arg("silence-ids", "Ids of silences to expire").StringsVar(&c.ids)
|
|
|
|
expireCmd.Action(c.expire)
|
2017-12-22 10:17:13 +00:00
|
|
|
}
|
2017-04-20 09:04:17 +00:00
|
|
|
|
2018-04-24 07:35:15 +00:00
|
|
|
func (c *silenceExpireCmd) expire(ctx *kingpin.ParseContext) error {
|
2018-04-13 11:34:16 +00:00
|
|
|
if len(c.ids) < 1 {
|
2017-11-12 16:43:48 +00:00
|
|
|
return errors.New("no silence IDs specified")
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 11:34:16 +00:00
|
|
|
apiClient, err := api.NewClient(api.Config{Address: alertmanagerURL.String()})
|
2018-04-11 09:17:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-13 11:34:16 +00:00
|
|
|
silenceAPI := client.NewSilenceAPI(apiClient)
|
2017-04-20 09:04:17 +00:00
|
|
|
|
2018-04-13 11:34:16 +00:00
|
|
|
for _, id := range c.ids {
|
2018-04-11 10:30:18 +00:00
|
|
|
err := silenceAPI.Expire(context.Background(), id)
|
2017-04-20 09:04:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-04-11 09:17:41 +00:00
|
|
|
|
2017-04-20 09:04:17 +00:00
|
|
|
return nil
|
|
|
|
}
|