alertmanager/cli/silence.go
Binh Le 9b127147bd [amtool] - Add a new silence import command (#1082)
* Add a new `silence import` command to amtool

This command read silences data from a query JSON output and import to
alertmanager. It allows `amtool` to be used as a backup/restore tool for
silences, i.e. #1000

Backup / export:

```
amtool silence -o json > silences.json
```

Restore / import:

```
amtool silence import silences.json
```

* Add a WaitGroup barrier

Move error channel reading to a goroutine to prevent deadlock and thus
add a WaitGroup to synchronize.
2017-12-07 13:12:00 +01:00

36 lines
982 B
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/prometheus/alertmanager/types"
)
//var labels []string
type alertmanagerSilenceResponse struct {
Status string `json:"status"`
Data []types.Silence `json:"data,omitempty"`
ErrorType string `json:"errorType,omitempty"`
Error string `json:"error,omitempty"`
}
// silenceCmd represents the silence command
var silenceCmd = &cobra.Command{
Use: "silence",
Short: "Manage silences",
Long: `Add, expire or view silences. For more information and additional flags see query help`,
Run: CommandWrapper(query),
}
func init() {
RootCmd.AddCommand(silenceCmd)
silenceCmd.PersistentFlags().BoolP("quiet", "q", false, "Only show silence ids")
viper.BindPFlag("quiet", silenceCmd.PersistentFlags().Lookup("quiet"))
silenceCmd.AddCommand(addCmd)
silenceCmd.AddCommand(expireCmd)
silenceCmd.AddCommand(queryCmd)
silenceCmd.AddCommand(importCmd)
}