Skip to content

Go 语言实现简单的 ELK Watcher,对接钉钉通知,定时请求 ES API 数据

License

Notifications You must be signed in to change notification settings

la3rence/elk-watcher

Repository files navigation

GitHub release (latest by date) Build docker image

ELK watcher by Go

This project calls the REST API of Elastic Search, especially the index data, at regular intervals. It may look like the paid features in the ELK stack -- watcher.

go build
chmod +x ./elk-watcher

Export environment variable

Before starting this app, the following env variables need to be set.

export ELASTIC_USERNAME="username"
export ELASTIC_PASSWORD="password"
# URL for ElasticSearch REST API
export ELASTIC_URL="http://elastic_hostname/index_name/_search"
export DINGTALK_TOKEN="access_token"
export DINGTALK_SECRET="dingtalk_secret"
# interval (pattern with `10s`, `1m`, `3h`)
export DURATION="60s"

Run it by this command:

./elk-watcher

Run as container

docker run --name=watcher -itd -e ELASTIC_USERNAME="username" \
  ELASTIC_PASSWORD="password" \
  ELASTIC_URL="http://elastic_hostname/index_name/_search" \
  DINGTALK_TOKEN="access_token" \
  DINGTALK_SECRET="dingtalk_secret"
  DURATION="60s" \
  lawrence2018/watcher:latest

Of course, we can deploy this with Kubernetes.

kubectl apply -f deployment.yml