Skip to content

Commit

Permalink
feat: moved to elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
vfoucault committed Dec 10, 2020
1 parent a9ad8d3 commit 036fd5c
Show file tree
Hide file tree
Showing 16 changed files with 1,521 additions and 242 deletions.
9 changes: 9 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# .goreleaser.yml
builds:
- binary: grafana-annotation
goos:
- linux
- darwin
goarch:
- amd64
28 changes: 0 additions & 28 deletions Gopkg.lock

This file was deleted.

38 changes: 0 additions & 38 deletions Gopkg.toml

This file was deleted.

89 changes: 89 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# git options
GIT_COMMIT ?= $(shell git rev-parse HEAD)
GIT_TAG ?= $(shell git tag --points-at HEAD)
DIST_TYPE ?= snapshot
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

PROJECT_NAME := grafana-annotation
PKG_ORG := Contentsquare
PKG := grafana-annotation
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
BINARY_NAME := grafana-annotation

M = $(shell printf "\033[34;1m▶\033[0m")

GO := go
GOFMT := gofmt
OS := $(shell uname -s)
GOOS ?= $(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
GOARCH ?= amd64

BUILD_CONSTS = -X main.buildRevision=$(GIT_COMMIT) -X main.buildTag=$(GIT_TAG)
BUILD_OPTS = -ldflags="$(BUILD_CONSTS)" -gcflags="-trimpath=$(GOPATH)/src"

tidy:
$(info ===== $@ =====)
GO111MODULE=on go mod tidy

deps:
$(info ===== $@ =====)
GO111MODULE=on go mod vendor

format:
$(info ===== $@ =====)
$(GOFMT) -w -s $(GO_FILES)

build:
$(info ===== $@ =====)
GO111MODULE=on GOOS=$(GOOS) $(GO) build -tags static -o $(BINARY_NAME) $(BUILD_OPTS)

test:
$(info ===== $@ =====)
$(GO) test -v -race -cover -coverprofile=coverage.out ./...

fmt:
$(info ===== gofmt =====)
$(GOFMT) -d -e -s $(GO_FILES)

#lint:
# $(info ===== $@ =====)
# $(GO) vet $(PKG_LIST)
# $(GO) list ./... | grep -Ev /vendor/ | sed -e 's/${PROJECT_NAME}/./' | xargs -L1 golint -set_exit_status
#

lint:
$(info ===== $@ =====)
golangci-lint run . -v

tarball: version
$(info ===== $@ =====)
ifneq ($(GIT_TAG),)
tar czf $(BINARY_NAME)-$(GOOS)-$(GOARCH)-$(GIT_TAG).tar.gz $(BINARY_NAME)
else
tar czf $(BINARY_NAME)-$(GOOS)-$(GOARCH)-$(VERSION_FILE).tar.gz $(BINARY_NAME)
endif

version:
$(info ===== $@ =====)
ifneq ($(GIT_TAG),)
$(eval VERSION := $(GIT_TAG))
$(eval VERSION_FILE := $(GIT_TAG))
else
$(eval VERSION := $(subst /,-,$(BRANCH)))
$(eval VERSION_FILE := $(GIT_COMMIT)-SNAPSHOT)
endif
@test -n "$(VERSION)"
$(info Building $(VERSION)/$(VERSION_FILE) on sha1 $(GIT_COMMIT))

get_version: version
$(info $(VERSION_FILE))

.PHONY: tidy \
deps \
format \
build \
test \
fmt \
lint \
tarball
54 changes: 21 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
grafana-annotation: Post graphite annotation to grafana 5+.
grafana-annotation: Post annotation to Elastic Search

# Install

go get -d "github.com/contentsquare/grafana-annotation"

# Build

```shell
make build
```

# Configure

Will work with a configuration file (default to `~/.grafana-anotation-poster.yml`)

## Configuration file

```yaml
grafanaUri: https://some-grafana-host.tld
bearerToken: BearerTokenFromGrafana
region: eu-west-1
env: dev
provider: aws
role: testproject
elasticsearch:
bootstrap_servers:
- http://localhost:9200
index_name: "test_index.2006.02"
```
## Create a Bearer Token
[Read the Docs](http://docs.grafana.org/http_api/auth/)
# Build
```
go build
```
# Call
## Example usage
## Options
```
Usage of grafana-annotation:
-config-file string
Configuration File (default "~/.grafana-anotation-poster.yml")
-data string
Additional data.
-tag value
Tags. may be repeated multiple times
-verbose
Be Verbose.
-what string
The What item to post. (default "$(hostname)")
```shell script
~# grafana-annotation --config-file resources/config-test.yml post --tags systemd --tags stop --tags kafka service kafka is stopped
Using config file: resources/config-test.yml
[2020-12-10 13:27:29] INFO Annotation successfully posted to elasticsearch. tags=[systemd stop kafka eu-west-1 testproject dev aws Vianneys-MacBook-Pro.local]
~#
```

## Example call

```
~$ grafana-annotation -data "Details on this event" -tag foo \
-tag bar -what "Something happened on system foo with bar event"
```

143 changes: 0 additions & 143 deletions annotation-poster.go

This file was deleted.

Loading

0 comments on commit 036fd5c

Please sign in to comment.