diff --git a/Makefile b/Makefile index 5ce4e8048..361736fee 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ NAME := unsee VERSION := $(shell git describe --tags --always --dirty='-dev') # Alertmanager instance used when running locally, points to mock data -MOCK_PATH := $(CURDIR)/mock/0.7.1 -ALERTMANAGER_URI := "localfs:file://$(MOCK_PATH) local2:file://$(CURDIR)/mock/0.7.0" +MOCK_PATH := $(CURDIR)/mock/0.7.1 +ALERTMANAGER_URIS := mock:file://$(MOCK_PATH) # Listen port when running locally PORT := 8080 @@ -49,7 +49,7 @@ clean: .PHONY: run run: $(NAME) - ALERTMANAGER_URI=$(ALERTMANAGER_URI) \ + ALERTMANAGER_URIS=$(ALERTMANAGER_URIS) \ COLOR_LABELS_UNIQUE="@receiver instance cluster" \ COLOR_LABELS_STATIC="job" \ DEBUG="$(GIN_DEBUG)" \ @@ -68,7 +68,7 @@ run-docker: docker-image --name $(NAME) \ $(DOCKER_ARGS) \ -v $(MOCK_PATH):$(MOCK_PATH) \ - -e ALERTMANAGER_URI=$(ALERTMANAGER_URI) \ + -e ALERTMANAGER_URIS=$(ALERTMANAGER_URIS) \ -e COLOR_LABELS_UNIQUE="instance cluster" \ -e COLOR_LABELS_STATIC="job" \ -e DEBUG="$(GIN_DEBUG)" \ diff --git a/README.md b/README.md index 55ed86b4f..de17b8f12 100644 --- a/README.md +++ b/README.md @@ -63,22 +63,22 @@ To finally compile `unsee` the binary run: ## Running `unsee` is configured via environment variables or command line flags. -Environment variable `ALERTMANAGER_URI` or cli flag `-alertmanager.uri` is the +Environment variable `ALERTMANAGER_URIS` or cli flag `-alertmanager.uris` is the only option required to run. See [Environment variables](#environment-variables) section below for the full list of supported environment variables. Examples: - ALERTMANAGER_URI=https://alertmanager.example.com unsee - unsee -alertmanager.uri https://alertmanager.example.com + ALERTMANAGER_URIS=default:https://alertmanager.example.com unsee + unsee -alertmanager.uris default:https://alertmanager.example.com There is a make target which will compile and run unsee: make run By default it will listen on port `8080` and Alertmanager mock data will be -used, to override Alertmanager URI set `ALERTMANAGER_URI` and/or `PORT` make +used, to override Alertmanager URI set `ALERTMANAGER_URIS` and/or `PORT` make variables. Example: - make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run + make PORT=5000 ALERTMANAGER_URIS=default:https://alertmanager.example.com run ## Docker @@ -96,14 +96,14 @@ Images are built automatically for: To start a release image run: - docker run -e ALERTMANAGER_URI=https://alertmanager.example.com cloudflare/unsee:vX.Y.Z + docker run -e ALERTMANAGER_URIS=default:https://alertmanager.example.com cloudflare/unsee:vX.Y.Z Latest release details can be found on [GitHub](https://github.com/cloudflare/unsee/releases). To start docker image build from lastet master branch run: - docker run -e ALERTMANAGER_URI=https://alertmanager.example.com cloudflare/unsee:latest + docker run -e ALERTMANAGER_URIS=default:https://alertmanager.example.com cloudflare/unsee:latest Note that latest master branch might have bugs or breaking changes. Using release images is strongly recommended for any production use. @@ -121,7 +121,7 @@ This will build a Docker image from sources. Will run locally built Docker image. Same defaults and override variables apply as with `make run`. Example: - make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run-docker + make PORT=5000 ALERTMANAGER_URIS=default:https://alertmanager.example.com run-docker ## Environment variables @@ -159,14 +159,19 @@ The UI has a watchdog that tracks the timestamp of the last pull. If the UI does not receive updates for more than 15 minutes it will print an error and reload the page. -#### ALERTMANAGER_URI +#### ALERTMANAGER_URIS -URI of the Alertmanager instance, unsee will use it to pull alert groups and -silences. Endpoints in use: +List of Alertmanager instances URI, unsee will use it to pull alert groups and +silences from all defined instances and deduplicate all alerts. +API endpoints in use: * ${ALERTMANAGER_URI}/api/v1/alerts/groups * ${ALERTMANAGER_URI}/api/v1/silences +Expected syntax: + + ${name1}:${uri} ${name2}:{uri} + Supported URI schemes: * http:// @@ -178,11 +183,11 @@ target. Example: - ALERTMANAGER_URI=https://alertmanager.example.com + ALERTMANAGER_URIS="prod:https://prod.alertmanager.example.com staging:https://staging.alertmanager.example.com" -This option can also be set using `-alertmanager.uri` flag. Example: +This option can also be set using `-alertmanager.uris` flag. Example: - $ unsee -alertmanager.uri https://alertmanager.example.com + $ unsee -alertmanager.uris "prod:https://prod.alertmanager.example.com staging:https://staging.alertmanager.example.com" This variable is required and there is no default value. diff --git a/alertmanager/version.go b/alertmanager/version.go index 6daac1f65..466879d42 100644 --- a/alertmanager/version.go +++ b/alertmanager/version.go @@ -3,7 +3,6 @@ package alertmanager import ( "time" - "github.com/cloudflare/unsee/config" "github.com/cloudflare/unsee/transport" log "github.com/Sirupsen/logrus" @@ -27,7 +26,7 @@ func GetVersion(uri string, timeout time.Duration) string { url, err := transport.JoinURL(uri, "api/v1/status") if err != nil { - log.Errorf("Failed to join url '%s' and path 'api/v1/status': %s", config.Config.AlertmanagerURI, err.Error()) + log.Errorf("Failed to join url '%s' and path 'api/v1/status': %s", uri, err.Error()) return defaultVersion } ver := alertmanagerVersion{} diff --git a/config/config.go b/config/config.go index 621f13e6b..f6e5aac1e 100644 --- a/config/config.go +++ b/config/config.go @@ -25,7 +25,7 @@ func (mvd *spaceSeparatedList) Decode(value string) error { type configEnvs struct { AlertmanagerTimeout time.Duration `envconfig:"ALERTMANAGER_TIMEOUT" default:"40s" help:"Timeout for all request send to Alertmanager"` AlertmanagerTTL time.Duration `envconfig:"ALERTMANAGER_TTL" default:"1m" help:"TTL for Alertmanager alerts and silences"` - AlertmanagerURI spaceSeparatedList `envconfig:"ALERTMANAGER_URI" required:"true" help:"Alertmanager URIs"` + AlertmanagerURIs spaceSeparatedList `envconfig:"ALERTMANAGER_URIS" required:"true" help:"List of Alertmanager URIs (name:uri)"` ColorLabelsStatic spaceSeparatedList `envconfig:"COLOR_LABELS_STATIC" help:"List of label names that should have the same (but distinct) color"` ColorLabelsUnique spaceSeparatedList `envconfig:"COLOR_LABELS_UNIQUE" help:"List of label names that should have unique color"` Debug bool `envconfig:"DEBUG" default:"false" help:"Enable debug mode"` diff --git a/config/config_test.go b/config/config_test.go index b801b366e..b3717a75f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -30,7 +30,7 @@ func TestMakeFlagName(t *testing.T) { func TestReadConfig(t *testing.T) { os.Setenv("ALERTMANAGER_TTL", "1s") - os.Setenv("ALERTMANAGER_URI", "http://localhost") + os.Setenv("ALERTMANAGER_URIS", "default:http://localhost") os.Setenv("DEBUG", "true") os.Setenv("COLOR_LABELS_STATIC", "a bb ccc") Config.Read() diff --git a/main.go b/main.go index 0ae59cac2..bf0b7a3c8 100644 --- a/main.go +++ b/main.go @@ -53,7 +53,7 @@ func setupRouter(router *gin.Engine) { } func setupUpstreams() { - for _, s := range config.Config.AlertmanagerURI { + for _, s := range config.Config.AlertmanagerURIs { z := strings.SplitN(s, ":", 2) if len(z) != 2 { log.Fatalf("Invalid Alertmanager URI '%s', expected format 'name:uri'", s) diff --git a/views_test.go b/views_test.go index d3707f8b2..48b24c952 100644 --- a/views_test.go +++ b/views_test.go @@ -23,7 +23,7 @@ import ( func mockConfig() { log.SetLevel(log.ErrorLevel) - os.Setenv("ALERTMANAGER_URI", "default:http://localhost") + os.Setenv("ALERTMANAGER_URIS", "default:http://localhost") os.Setenv("COLOR_LABELS_UNIQUE", "alertname") config.Config.Read() setupUpstreams()