2018-05-14 12:36:24 +00:00
|
|
|
// Copyright 2018 Prometheus Team
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
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
|
|
|
|
}
|