Reactor 最初是开源项目 ElastAlert 的一个分支。本项目维护者应密切关注 ElastAlert 的变更(不包括其额外的告警器),并确保任何相关的错误修复被合入、任何有用的功能被移植进来。
Reactor 是一个告警引擎,它接收一组带有自定义过滤器的规则,并在匹配时发出告警。Reactor 会自动用重复告警信息更新已静默的告警。
| 访问日期 | Commit | 备注 |
|---|---|---|
| 2019-10-16 | 325f1dfe7a45f3ca2a2cc00127ab71fcd4f9cead | 回溯到 Reactor 首次创建之前。 |
| 2020-01-09 | ec5d03b95708ea0aa3d29c065f9794fdd95a82a1 | 我们不使用覆盖率。 |
目前 Reactor 支持 ElasticSearch 5.x.x、6.x.x 和 7.x.x。随着 elasticsearch 新版本的发布,Reactor 将更新以提供支持。目前不打算为更旧版本的 ElasticSearch 添加支持。目前,尚未确定移除对旧版 ElasticSearch 支持的日期。如果 ElasticSearch 的 Python 库移除支持,我们很可能会跟进。
根据 ElasticSearch 的 Python 库指南,建议安装与集群主版本相同的库版本。
对于 Elasticsearch 7.0 及更高版本,请使用主版本 7 (elasticsearch<8.0.0,>=7.0.0)。
对于 Elasticsearch 6.0 及更高版本,请使用主版本 6 (elasticsearch<7.0.0,>=6.0.0)。
对于 Elasticsearch 5.0 及更高版本,请使用主版本 5 (elasticsearch<6.0.0,>=5.0.0)。
请注意,ElasticSearch 库的 6.4.0 版本引入了一个 已知错误,该错误已在 7.0.4 中修复,但在主版本 6 中未修复。该错误会将 scroll_id 放入查询参数中,这可能导致 Elasticsearch 对有效的滚动 ID 返回 400 状态码。
你可以使用以下命令在 docker 中启动一个 elasticsearch 实例以进行本地开发:
$ docker run -d -p 9200:9200/tcp --name elasticsearch docker.elastic.co/elasticsearch/elasticsearch:<version>
并在 config.yaml 中进行如下配置:
writeback_index: reactor
alert_alias: reactor_alerts
elasticsearch: &elasticsearch
host: localhost
port: 9200
# Global settings to be applied to every run
rule:
elasticsearch: *elasticsearch
本项目提供 git 钩子以防止用户出错。请运行以下命令:
$ cp .git-hooks-pre-push .git/hooks/pre-push
Reactor 涵盖两种类型的测试:单元测试和集成测试。单元测试用于确保各个函数和逻辑流程正常工作;集成测试用于确保整个系统协同工作。
单元测试使用 PyTest 编写。要运行所有测试,请运行以下命令:
$ py.test
集成测试在 docker 中执行,并且需要项目根目录下的 .env 文件。测试需要在 .env 文件中包含以下内容:
# The ElasticSearch version to be tested, reactor supports >= 5.x.x
ES_VERSION=6.3.2
# Basic configuration information so that reactor can query ElasticSearch
ES_HOST=elasticsearch
ES_USER=elastic
ES_PASSWORD=changeme
集成 Docker Compose 文件 test.docker-compose.yml 包含 3 个环境变量,这些变量是 >= v7.x.x 所必需的,但会破坏旧版本:
node.name=elasticsearch
discovery.seed_hosts=elasticsearch
cluster.initial_master_nodes=elasticsearch
要执行集成测试,请运行以下命令:
$ docker-compose -f docker-compose-test.yml up --abort-on-container-exit --build reactor elasticsearch
以下一组命令(在 ./certs/ 目录中执行)将创建一套 CA 和设备证书,用于在 localhost 上运行模拟集群:
# Only do once: generate the root CA key:
$ openssl genrsa -out transport-ca.key 4096
# Generate the root CA certificate:
## Country Name (2 letter code) []:GB
## State or Province Name (full name) []:.
## Locality Name (eg, city) []:.
## Organization Name (eg, company) []:.
## Organizational Unit Name (eg, section) []:.
## Common Name (eg, fully qualified host name) []:PyRaftLog
## Email Address []:.
$ openssl req -x509 -new -nodes -key transport-ca.key -sha256 -days 1024 -out transport-ca.pem
# Generate device certificates
# Only do once: generate device key:
$ openssl genrsa -out transport-consensus.key 4096
# Generate device certificate signing request:
## Country Name (2 letter code) []:GB
## State or Province Name (full name) []:.
## Locality Name (eg, city) []:.
## Organization Name (eg, company) []:.
## Organizational Unit Name (eg, section) []:.
## Common Name (eg, fully qualified host name) []:localhost
## Email Address []:.
$ openssl req -new -key transport-consensus.key -out transport-consensus.csr
# Generate a signed device certificate:
$ openssl x509 -req -in transport-consensus.csr -CA transport-ca.pem -CAkey transport-ca.key -CAcreateserial -out transport-consensus.crt -days 500 -sha256
要构建文档,请运行以下命令:
$ pip install -r requirements-docs.txt
$ cd docs
$ sphinx-build -b html -d build/doctrees -W source build/html
pip install --upgrade setuptools wheelpip install --upgrade twinepython3 setup.py sdist bdist_wheeltwine check dist/*twine upload --skip-existing dist/* --verbose