Skip to content

Commit

Permalink
Fix alertmanager subcommand and path for the configuration API (#72)
Browse files Browse the repository at this point in the history
* Fix the alertmanager subcommand

Seems like it got unregistered as we renamed it.

* Use the new alertmanager API path.

In accordance with what is currently part of upstream Cortex.

* Add a changelog entry
  • Loading branch information
gotjosh authored Aug 10, 2020
1 parent a454a6d commit 9f00599
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased / master

* [BUGFIX] Fix alertmanager registration subcommand and path for the configuration API #72

## v0.2.3

* [FEATURE] Added `alerts verify` command, which can be used to compare `ALERTS` series in Cortex to verify if Prometheus and Cortex Ruler are firing the same alerts
Expand Down
12 changes: 7 additions & 5 deletions cmd/cortextool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import (
)

var (
ruleCommand commands.RuleCommand
alertCommand commands.AlertCommand
logConfig commands.LoggerConfig
pushGateway commands.PushGatewayConfig
loadgenCommand commands.LoadgenCommand
ruleCommand commands.RuleCommand
alertCommand commands.AlertCommand
alertmanagerCommand commands.AlertmanagerCommand
logConfig commands.LoggerConfig
pushGateway commands.PushGatewayConfig
loadgenCommand commands.LoadgenCommand
)

func main() {
kingpin.Version("0.1.3")
app := kingpin.New("cortextool", "A command-line tool to manage cortex.")
logConfig.Register(app)
alertCommand.Register(app)
alertmanagerCommand.Register(app)
ruleCommand.Register(app)
pushGateway.Register(app)
loadgenCommand.Register(app)
Expand Down
8 changes: 5 additions & 3 deletions pkg/client/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"gopkg.in/yaml.v2"
)

const alertmanagerAPIPath = "/api/v1/alerts"

type configCompat struct {
TemplateFiles map[string]string `yaml:"template_files"`
AlertmanagerConfig string `yaml:"alertmanager_config"`
Expand All @@ -24,19 +26,19 @@ func (r *CortexClient) CreateAlertmanagerConfig(ctx context.Context, cfg string,
return err
}

_, err = r.doRequest("/alertmanager/alerts", "POST", payload)
_, err = r.doRequest(alertmanagerAPIPath, "POST", payload)
return err
}

// DeleteAlermanagerConfig deletes the users alertmanagerconfig
func (r *CortexClient) DeleteAlermanagerConfig(ctx context.Context) error {
_, err := r.doRequest("/alertmanager/alerts", "DELETE", nil)
_, err := r.doRequest(alertmanagerAPIPath, "DELETE", nil)
return err
}

// GetAlertmanagerConfig retrieves a rule group
func (r *CortexClient) GetAlertmanagerConfig(ctx context.Context) (string, map[string]string, error) {
res, err := r.doRequest("/alertmanager/alerts", "GET", nil)
res, err := r.doRequest(alertmanagerAPIPath, "GET", nil)
if err != nil {
log.Debugln("no alert config present in response")
return "", nil, err
Expand Down

0 comments on commit 9f00599

Please sign in to comment.