alertmanager/cli/config.go
Simon Pasquier dc5fc02d22 [amtool] use kingpin.v2 (#1330)
* Use default values to store values from config
* fix typo and reserved keywork
* move to long help texts
* add one more unit test for resolver
* update comments

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2018-04-24 09:35:15 +02:00

46 lines
1.1 KiB
Go

package cli
import (
"context"
"errors"
"github.com/prometheus/client_golang/api"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/prometheus/alertmanager/cli/format"
"github.com/prometheus/alertmanager/client"
)
const configHelp = `View current config.
The amount of output is controlled by the output selection flag:
- Simple: Print just the running config
- Extended: Print the running config as well as uptime and all version info
- Json: Print entire config object as json
`
// configCmd represents the config command
func configureConfigCmd(app *kingpin.Application) {
app.Command("config", configHelp).Action(queryConfig).PreAction(requireAlertManagerURL)
}
func queryConfig(ctx *kingpin.ParseContext) error {
c, err := api.NewClient(api.Config{Address: alertmanagerURL.String()})
if err != nil {
return err
}
statusAPI := client.NewStatusAPI(c)
status, err := statusAPI.Get(context.Background())
if err != nil {
return err
}
formatter, found := format.Formatters[output]
if !found {
return errors.New("unknown output formatter")
}
return formatter.FormatConfig(status)
}