...

Source file src/github.com/prometheus/alertmanager/cli/silence_expire.go

Documentation: github.com/prometheus/alertmanager/cli

     1  // Copyright 2018 Prometheus Team
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package cli
    15  
    16  import (
    17  	"context"
    18  	"errors"
    19  
    20  	"github.com/go-openapi/strfmt"
    21  	"gopkg.in/alecthomas/kingpin.v2"
    22  
    23  	"github.com/prometheus/alertmanager/api/v2/client/silence"
    24  )
    25  
    26  type silenceExpireCmd struct {
    27  	ids []string
    28  }
    29  
    30  func configureSilenceExpireCmd(cc *kingpin.CmdClause) {
    31  	var (
    32  		c         = &silenceExpireCmd{}
    33  		expireCmd = cc.Command("expire", "expire an alertmanager silence")
    34  	)
    35  	expireCmd.Arg("silence-ids", "Ids of silences to expire").StringsVar(&c.ids)
    36  	expireCmd.Action(execWithTimeout(c.expire))
    37  }
    38  
    39  func (c *silenceExpireCmd) expire(ctx context.Context, _ *kingpin.ParseContext) error {
    40  	if len(c.ids) < 1 {
    41  		return errors.New("no silence IDs specified")
    42  	}
    43  
    44  	amclient := NewAlertmanagerClient(alertmanagerURL)
    45  
    46  	for _, id := range c.ids {
    47  		params := silence.NewDeleteSilenceParams().WithContext(ctx)
    48  		params.SilenceID = strfmt.UUID(id)
    49  		_, err := amclient.Silence.DeleteSilence(params)
    50  		if err != nil {
    51  			return err
    52  		}
    53  	}
    54  
    55  	return nil
    56  }
    57  

View as plain text