mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-29 17:52:53 +00:00
Allow 'd', 'w', 'y' to be specified at time suffix when creating silence (#1091)
The time.ParseDuration refused to parse them with the reason that a day can be shorter or longer than 24 hours. But they are already accepted in Prometheus range query and a custom parser is included in Prometheus common package so there's no reason amtool cannot use that. This will be handy in cases you need to create silence for longer periods, which are unfortunately common.
This commit is contained in:
parent
fdee5fcbfc
commit
ea9a584e8d
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/spf13/cobra"
|
||||
flag "github.com/spf13/pflag"
|
||||
"github.com/spf13/viper"
|
||||
@ -18,7 +19,7 @@ import (
|
||||
|
||||
type addResponse struct {
|
||||
Status string `json:"status"`
|
||||
Data struct {
|
||||
Data struct {
|
||||
SilenceID string `json:"silenceId"`
|
||||
} `json:"data,omitempty"`
|
||||
ErrorType string `json:"errorType,omitempty"`
|
||||
@ -102,11 +103,14 @@ func add(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
duration, err := time.ParseDuration(expires)
|
||||
duration, err := model.ParseDuration(expires)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
endsAt = time.Now().UTC().Add(duration)
|
||||
if duration == 0 {
|
||||
return fmt.Errorf("silence duration must be greater than 0")
|
||||
}
|
||||
endsAt = time.Now().UTC().Add(time.Duration(duration))
|
||||
}
|
||||
|
||||
author := viper.GetString("author")
|
||||
|
Loading…
Reference in New Issue
Block a user