2017-04-20 09:04:17 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2018-04-11 09:17:41 +00:00
|
|
|
"context"
|
2017-04-20 09:04:17 +00:00
|
|
|
"errors"
|
|
|
|
|
2017-12-22 10:17:13 +00:00
|
|
|
"github.com/alecthomas/kingpin"
|
2018-04-11 09:17:41 +00:00
|
|
|
"github.com/prometheus/client_golang/api"
|
|
|
|
|
2017-04-20 09:04:17 +00:00
|
|
|
"github.com/prometheus/alertmanager/cli/format"
|
2018-04-11 09:17:41 +00:00
|
|
|
"github.com/prometheus/alertmanager/client"
|
2017-04-20 09:04:17 +00:00
|
|
|
)
|
|
|
|
|
2017-12-22 10:17:13 +00:00
|
|
|
// configCmd represents the config command
|
2018-04-13 11:34:16 +00:00
|
|
|
func configureConfigCmd(app *kingpin.Application, longHelpText map[string]string) {
|
|
|
|
app.Command("config", "View the running config").Action(queryConfig)
|
2017-04-20 09:04:17 +00:00
|
|
|
|
2017-12-22 10:17:13 +00:00
|
|
|
longHelpText["config"] = `View current config
|
2017-04-20 09:04:17 +00:00
|
|
|
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
|
2017-12-22 10:17:13 +00:00
|
|
|
- Json: Print entire config object as json`
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 09:17:41 +00:00
|
|
|
func queryConfig(element *kingpin.ParseElement, ctx *kingpin.ParseContext) error {
|
2018-04-13 11:34:16 +00:00
|
|
|
c, err := api.NewClient(api.Config{Address: alertmanagerURL.String()})
|
2017-04-20 09:04:17 +00:00
|
|
|
if err != nil {
|
2018-04-11 09:17:41 +00:00
|
|
|
return err
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|
2018-04-11 09:17:41 +00:00
|
|
|
statusAPI := client.NewStatusAPI(c)
|
|
|
|
status, err := statusAPI.Get(context.Background())
|
2017-04-20 09:04:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-04-13 11:34:16 +00:00
|
|
|
formatter, found := format.Formatters[output]
|
2017-04-20 09:04:17 +00:00
|
|
|
if !found {
|
2017-11-12 16:43:48 +00:00
|
|
|
return errors.New("unknown output formatter")
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 09:17:41 +00:00
|
|
|
return formatter.FormatConfig(status)
|
2017-04-20 09:04:17 +00:00
|
|
|
}
|