26 个版本 (4 个稳定版)
1.0.4 | 2022年10月2日 |
---|---|
1.0.1 | 2022年5月13日 |
0.10.11 | 2021年8月8日 |
0.10.10 | 2021年7月15日 |
0.6.6 | 2019年3月30日 |
#105 in 异步
每月70 次下载
用于 krecik-cli
605KB
2.5K SLoC
Krecik
异步、并行外部服务检查器(带有 Slack 通知),使用行业标准库:Curl、ngHTTP2 和 OpenSSL。
作者
Daniel (@dmilith) Dettlaff
特性
-
默认为异步和多线程。
-
检查(输入)和产品(输出)都使用 JSON 格式。
-
使用 OpenSSL 1.1.1a+ 以提供 "TLS-cert 过期检查" 功能。
-
默认使用 HTTP2。
工作原理
Krecik 默认循环运行。每个循环迭代从所有定义的检查中加载组合的页面和域名。每个迭代在 /tmp 下生成 json 历史文件。当有超过 3 个历史文件可用时,Krecik 执行结果验证。当它检测到 3 次连续的任何类型的失败时,它将使用定义的通知器(Slack webhook)发送失败通知。
性能
检查 750+ 页面(每个检查 3 个预期),750+ 域名(每个检查 1 个预期)大约需要每个迭代 20-30 秒来完成。
软件要求
- Rust >= 1.50.0
- Curl >= 7.x
- OpenSSL >= 1.1.1a
- NgHTTP2 >= 1.36.0
额外的构建要求
- Clang >= 6.x
- Make >= 3.x
- Cmake >= 3.16
- Perl >= 5.x
- 符合 POSIX 的基本系统(在以下系统上测试过:FreeBSD/ HardenedBSD/ Darwin 和 Linux)
配置
默认情况下,Krecik 在以下位置查找配置:
- /etc/krecik/krecik.conf
- /Services/Krecik/service.conf
- /Projects/krecik/krecik.conf
- krecik.conf
Krecik 动态配置文件格式
{
"success_emoji": ":krecik-success:",
"failure_emoji": ":krecik-failure:",
"ok_message": "All services are UP as they should.",
"notifiers": [
{
"name": "notifier-name",
"slack_webhook": "https://hooks.slack.com/services/1111111111/222222222/3333333333333"
},
{
"name": "notifier-other-name",
"slack_webhook": "https://hooks.slack.com/services/1111111111/222222222/3333333333333"
}
]
}
字段说明
-
ok_message
- 当所有检查都成功时将发送的通知消息(每个通知器)。 -
notifiers
- 每个检查定义按名称使用的 Slack 通知器列表。
功能丰富的 Krecik 检查文件示例
{
"domains": [
{
"name": "some-page.com",
"expects": [
{
"ValidExpiryPeriod": 10
}
]
},
{
"name": "some-other-domain.com",
"expects": [
{
"ValidExpiryPeriod": 90
}
]
}
],
"pages": [
{
"url": "https://some-page.com/",
"expects": [
{
"ValidAddress": "https://some-page.com/after/for/example/302/redirect"
},
{
"ValidCode": 200
},
{
"ValidContent": "Some content"
},
{
"ValidContent": "<title"
},
{
"ValidContent": "and this thing"
},
{
"ValidLength": 100000
}
],
"options": {
"timeout": 15,
"connection_timeout": 30,
"verbose": false,
"ssl_verify_host": true,
"ssl_verify_peer": true,
"follow_redirects": true,
"headers": [
"zala: takiheder",
"atala: header123",
"oitrala: 1"
],
"cookies": [
"ala: 123",
"tala: aye sensei",
"trala: 6"
],
"agent": "Krtecek-Underground-Agent",
"method": "Post",
"post_data": [
"some: value",
"{\"more\": \"data\"}"
]
}
},
{
"url": "http://google.com/fdgrtjkgengjkdfnglksfdgsdfg",
"expects": [
{
"ValidCode": 404
}
]
},
{
"url": "https://rust-lang.net.cn/",
"expects": [
{
"ValidCode": 200
}
]
}
],
"notifier": "notifier-name"
}
默认预期
-
域名检查期望:
ValidExpiryPeriod(14)
(每个域名至少有效14天)。 -
页面检查期望:
ValidCode(200)
(HTTP错误代码为200)+ValidLength(128)
(内容长度至少128字节)+ValidContent("body")
(内容包含"body")
运行时日志级别控制
Krecik在运行时通过处理SIGUSR1信号来触发日志级别的变化。根据接收到的SIGUSR1信号次数,将在"info"、"debug"和"trace"日志级别之间循环。
开发
构建调试版本
懒惰开发者模式(使用cargo-watch
+ cargo-clippy
,警告:启用,监视等待代码更改以进行首次运行)
bin/devel
渴望的开发者模式(使用cargo-watch
+ cargo-clippy
,警告:启用,监视立即编译代码)
bin/devel dev
构建发布版本
bin/build
运行
启动"dev"环境
bin/run dev
启动"release"环境
bin/run
测试
注意:如果启动了上述提到的服务器之一……,下面的脚本将在HTTP2-Check-API上执行内置测试的额外一轮。
bin/test
映射远程配置资源
目前,定义的唯一远程资源类型是:"PongoHost"。要配置Pongo API资源,创建文件:checks/remotes/yourname.json
,内容如下:
{
"url": "https://pongo-api.your.domain.tld/api/ping?token=your-secret-token",
"notifier": "notifier-id"
}
支持外部JSON资源库
-
使用定义检查的JSON文件创建新库。检查文件格式示例可在:
checks/tests/*.json
中找到。提交您的检查。 -
现在在
krecik
仓库中执行:cd krecik/checks
。 -
克隆您的检查资源库,这里我称其为"frontends":
git clone git@github.com:my-company-id/krecik-frontends.git frontends
。 -
以开发模式启动
krecik
网络服务器:bin/run dev
(在开发模式下启动得更快)。
为svdOS系统构建需求
对于使用Sofin的svdOS(定制的HardenedBSD x86_64)服务器
使用以下命令安装构建需求:
s i Openssl Rust Perl Make
然后使用以下命令将设置发布到环境中:
s env+Openssl+Rust+Perl+Make
构建后,使用以下命令恢复动态环境设置:
s env reset
为什么叫"Krecik"?
这是我最喜欢的卡通……也是对Zdeněk Miler先生的小小致敬 :)。
许可
-
BSD
-
MIT
依赖
~33–48MB
~896K SLoC