# go-elasticsearch-alerts
![Test](https://github.com/morningconsult/go-elasticsearch-alerts/workflows/Test/badge.svg) [![Go Documentation](https://img.shields.io/badge/godoc-reference-blue.svg)][godocs] [![Go Report Card](https://goreportcard.com/badge/github.com/morningconsult/go-elasticsearch-alerts)](https://goreportcard.com/report/github.com/morningconsult/go-elasticsearch-alerts)
[godocs]: https://godoc.org/github.com/morningconsult/go-elasticsearch-alerts
A daemon for generating alerts on Elasticsearch data in real-time.
Further details on setup and usage can be found in the [project documentation](https://morningconsult.github.io/go-elasticsearch-alerts).
## Installation
### Manually
You can download your preferred variant of the binary from the [releases page](https://github.com/morningconsult/go-elasticsearch-alerts/releases).
### Using `go get`
You can build the binary via `go get` with
```shell
$ go get github.com/morningconsult/go-elasticsearch-alerts
```
### Using Docker
If you do not have Go installed locally, you can still build the binary if you have Docker installed. Simply clone this repository and run `make docker` to build the binary within a Docker container and output it to the local directory.
You can cross-compile the binary using the `TARGET_GOOS` and `TARGET_GOARCH` environment variables. For example, if you wish to compile the binary for a 64-bit (x86-64) Windows machine, run the following command:
```shell
$ TARGET_GOOS="windows" TARGET_GOARCH="amd64" make docker
```
The binary will be output to `bin` in the local directory.
# Setup
This application requires several configuration files: a [main configuration file](#main-configuration-file) and one or more [rule configuration files](#rule-configuration-files). The main configuration file is used to configure general behavior of the application. The rule files are used to define your alerts (e.g. what queries are executed, when they are executed, where the results shall be sent, etc.).
## Main Configuration File
The main configuration file is used to specify:
* Information pertaining to your Elasticsearch instance;
* How the application will interact with your Elasticsearch instance;
* Whether it is to be run in a distributed fashion; and
* If distributed, how the application will communicate with your Consul instance (used for synchronization).
The application will look for this file at `/etc/go-elasticsearch-alerts/config.json` by default, but if you wish to keep it elsewhere you can specify the location of this file using the `GO_ELASTICSEARCH_ALERTS_CONFIG_FILE` environment variable.
### Example
This example shows a sample main configuration file.
```json
{
"elasticsearch": {
"server": {
"url": "https://my.elasticsearch.com"
},
"client": {
"tls_enabled": true,
"ca_cert": "/tmp/cacert.pem",
"client_cert": "/tmp/client_cert.pem",
"client_key": "/tmp/client_key.pem"
}
},
"distributed": true,
"consul": {
"consul_lock_key": "go-elasticsearch-alerts/leader",
"consul_http_addr": "http://127.0.0.1:8500",
"consul_http_ssl": "true",
"consul_cacert": "/tmp/cacert_consul.pem",
"consul_client_cert": "/tmp/client_cert_consul.pem",
"consul_client_key": "/tmp/client_key_consul.pem"
}
}
```
### Rule Configuration Files
The rule configuration files are used to configure what Elasticsearch queries will be run, how often they will be run, how the data will be transformed, and how the transformed data will be output. These files should be JSON format. The application will look for the rule files at `/etc/go-elasticsearch-alerts/rules` by default, but if you wish to keep them elsewhere you can specify this directory using the `GO_ELASTICSEARCH_ALERTS_RULES_DIR` environment variable.
### Example
```json
{
"name": "Filebeat Errors",
"index": "filebeat-*",
"schedule": "@every 10m",
"body": {
"query": {
"bool": {
"must": [
{ "query_string" : {
"query" : "*",
"fields" : [ "system.syslog.message", "message" ]
} }
]
}
},
"aggs": {
"hostname": {
"terms": {
"field": "system.syslog.hostname",
"min_doc_count": 1
}
}
},
"size": 20,
"_source": "system.syslog"
},
"body_field": "hits.hits._source",
"filters": [
"aggregations.service_name.buckets",
"aggregations.service_name.buckets.program.buckets"
],
"outputs": [
{
"type": "slack",
"config" : {
"webhook": "https://slack.webhooks.foo/asdf",
"channel": "#error-alerts",
"text": "New errors",
"emoji": ":hankey:"
}
},
{
"type": "file",
"config": {
"file": "/tmp/errors.log"
}
}
]
}
```
In the example above, the application would execute the following query (illustrated by the `cURL` request below) to Elasticsearch every ten minutes, group by `aggregations.service_name.buckets` and `aggregations.service_name.buckets.program.buckets`, and write the results to Slack and local disk.
```shell
$ curl http://<your_elasticsearch_host>/filebeat-*/_search \
--header "Content-Type: application/json" \
--data '{
"query": {
"bool": {
"must": [
{ "query_string" : {
"query" : "*",
"fields" : [ "system.syslog.message", "message" ]
} }
]
}
},
"aggs": {
"hostname": {
"terms": {
"field": "system.syslog.hostname",
"min_doc_count": 1
}
}
},
"size": 20,
"_source": "system.syslog"
}'
```
## Usage
Once your configuration files have been setup, to run the program
simply execute the binary
```shell
$ ./go-elasticsearch-alerts
```
没有合适的资源?快使用搜索试试~ 我知道了~
Elasticsearch警报守护进程_Go_Shell_下载.zip
共146个文件
go:32个
png:23个
html:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 36 浏览量
2023-04-05
13:06:13
上传
评论
收藏 932KB ZIP 举报
温馨提示
Elasticsearch警报守护进程_Go_Shell_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
Elasticsearch警报守护进程_Go_Shell_下载.zip (146个子文件)
make.bat 787B
.buildinfo 230B
basic.css 9KB
alabaster.css 9KB
pygments.css 4KB
custom.css 331B
custom.css 331B
Dockerfile 927B
Dockerfile 843B
.dockerignore 30B
setup.doctree 111KB
demo.doctree 22KB
intro.doctree 20KB
usage.doctree 19KB
install.doctree 8KB
index.doctree 8KB
ajax-loader.gif 673B
.gitignore 15B
job_test.go 19KB
job.go 18KB
slack_test.go 12KB
parse_test.go 11KB
transform_test.go 11KB
parse.go 10KB
conditions_test.go 10KB
traverse_test.go 8KB
conditions.go 7KB
email_test.go 7KB
slack.go 6KB
alert.go 6KB
command.go 5KB
email.go 5KB
alert_test.go 5KB
sns_test.go 5KB
handlers.go 4KB
traverse.go 4KB
sns.go 3KB
client.go 3KB
file_test.go 3KB
transform.go 3KB
file.go 3KB
controller.go 3KB
client_test.go 3KB
attachment.go 2KB
client.go 1KB
inventory_test.go 1KB
inventory.go 1KB
lock.go 1KB
main.go 1KB
version.go 879B
setup.html 54KB
demo.html 13KB
usage.html 11KB
intro.html 10KB
index.html 9KB
install.html 7KB
search.html 4KB
genindex.html 4KB
sidebarintro.html 1KB
index.html 70B
objects.inv 403B
jquery.js 278KB
underscore.js 46KB
websupport.js 25KB
searchtools.js 18KB
searchindex.js 8KB
doctools.js 7KB
test-rule.json 824B
test-rule.json 518B
config.json 278B
.keep 0B
.keep 0B
.keep 0B
.keep 0B
.keep 0B
LICENSE 11KB
Makefile 2KB
Makefile 579B
CHANGELOG.md 18KB
README.md 6KB
CONTRIBUTING.md 3KB
bug_report.md 2KB
CHANGELOG.tpl.md 1KB
feature_request.md 431B
PULL_REQUEST_TEMPLATE.md 168B
go.mod 1KB
.nojekyll 0B
key.pem 2KB
cert.pem 1KB
cacert.pem 0B
environment.pickle 19KB
consul-2.png 65KB
consul-2.png 65KB
consul-2.png 65KB
email.png 47KB
email.png 47KB
email.png 47KB
slack.png 46KB
slack.png 46KB
slack1.png 46KB
共 146 条
- 1
- 2
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Docker容器配置进阶
- tensorflow-gpu-2.7.4-cp37-cp37m-manylinux2010-x86-64.whl
- 多段线、 圆、弧转多段线(仅我可见)
- tensorflow-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- yeyue-p8Yi4-ve4a83792.apk
- tensorflow-gpu-2.7.3-cp38-cp38-manylinux2010-x86-64.whl
- 五相感应电机矢量控制模型MATLAB
- RGLED (1) (1).circ
- IMG_20240427_215747.jpg
- python下前端WEB学习笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功