Skip to content

Commit

Permalink
Re-introduce prometheus durations in amtool silence creation (#1185)
Browse files Browse the repository at this point in the history
* Fixes #1183

* Update expires comment

The default time is already output thanks to
kingpin.
  • Loading branch information
stuartnelson3 authored Jan 9, 2018
1 parent 3aa7f03 commit 7b787da
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cli/silence_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/alecthomas/kingpin"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
)

type addResponse struct {
Expand All @@ -34,7 +35,7 @@ var (
addCmd = silenceCmd.Command("add", "Add a new alertmanager silence")
author = addCmd.Flag("author", "Username for CreatedBy field").Short('a').Default(username()).String()
requireComment = addCmd.Flag("require-comment", "Require comment to be set").Hidden().Default("true").Bool()
expires = addCmd.Flag("expires", "Duration of silence (100h)").Short('e').Default("1h").Duration()
expires = addCmd.Flag("expires", "Duration of silence").Short('e').Default("1h").String()
expireOn = addCmd.Flag("expire-on", "Expire at a certain time (Overwrites expires) RFC3339 format 2006-01-02T15:04:05Z07:00").String()
comment = addCmd.Flag("comment", "A comment to help describe the silence").Short('c').String()
addArgs = addCmd.Arg("matcher-groups", "Query filter").Strings()
Expand Down Expand Up @@ -86,7 +87,14 @@ func add(element *kingpin.ParseElement, ctx *kingpin.ParseContext) error {
return err
}
} else {
endsAt = time.Now().UTC().Add(*expires)
duration, err := model.ParseDuration(*expires)
if err != nil {
return err
}
if duration == 0 {
return fmt.Errorf("silence duration must be greater than 0")
}
endsAt = time.Now().UTC().Add(time.Duration(duration))
}

if *requireComment && *comment == "" {
Expand Down

0 comments on commit 7b787da

Please sign in to comment.