#监控 #健康 #HTTP #HTTP请求 #HTTP头 #响应头 #响应体

healthscript

一个简单的DSL,用于通过HTTP、TCP、ICMP(ping)等方式检查服务的健康状态

4个稳定版本

1.0.3 2024年7月6日

#1051网络编程

44 每月下载量
healthscript-cli 中使用

MIT 协议

125KB
1.5K SLoC

Healthscript

一个用于编写健康检查的 领域特定语言

healthcheck example healthcheck example healthcheck example healthcheck example

healthcheck example healthcheck example

要了解语言的最佳方式是查看下面的 示例

语言设计的总体思想如下

  • uri前的标签被视为请求的一部分,而uri后的标签是对响应的期望
  • “元”标签如HTTP动词、HTTP头、状态码和超时使用方括号 []
  • 体标签使用尖括号 <>
  • 对于自定义方案的URL,应使用以表示URL中的协议,例如与 postgres:// URLs类似的URL

HTTP示例

  • https://example.com 发送HTTP GET 请求,并期望返回 200 状态码

    • https://example.com
  • https://httpbin.org/post 发送HTTP POST 请求,带有 User-Agent: curl/7.72.0 头部,并期望返回 200 状态码和一个响应头 server: gunicorn/19.9.0

    • [POST] [User-Agent:curl/7.72.0]https://httpbin.org/post [server: gunicorn/19.9.0]
  • 使用JSON发送HTTP POST请求,并期望返回状态码200以及响应体为匹配jq表达式.json.a == 3

    • [POST] <{ "a": 3 }>https://httpbin.org/post <(.json.a == 3)>
  • https://httpbin.org/post发送带有base64编码字节的HTTP POST请求,并期望返回状态码200

    • [POST] <aHR0cHM6Ly9naXRodWIuY29tL3Job21idXNnZy9oZWFsdGhzY3JpcHQ=>https://httpbin.org/post

错误恢复

解析器将尽可能从错误中恢复,以帮助您编写正确的healthscript。错误信息可以通过CLI查看。

error handling example on the cli

使用以下命令安装CLI:

cargo install healthscript-cli

徽章服务

将healthscript附加到https://healthscript.mbund.dev/的末尾,以便托管服务器对您的服务执行健康检查并生成svg徽章。然后,您可以使用markdown语法将其包含在自己的readme中。

![healthcheck for example.com](https://healthscript.mbund.dev/https://example.com)

healthcheck for example.com

您可能需要将空格进行URL编码为%20

将healthscript集成到您的Rust项目中。为此,请在您的Cargo.toml中添加以下内容

healthscript = "1.0"

或者使用cargo CLI。

cargo add healthscript

TCP示例

  • 通过TCP连接到pwn.osucyber.club13389端口,并期望至少返回一个字节

    • tcp://pwn.osucyber.club:13389
  • 通过TCP连接到pwn.osucyber.club13389端口,并期望响应中包含正则表达式/e./出现在响应中,3秒后超时

    • tcp://pwn.osucyber.club:13389 </e./> [3s]
  • 通过TCP连接到pwn.osucyber.club13389端口,并期望响应以字符串chee开头

    • tcp://pwn.osucyber.club:13389 <"chee">

ping示例

  • ping example.com,并期望收到响应,8秒后超时

    • ping://example.com

DNS示例

  • example.com发送DNS查询并期望收到任何响应

    • dns://example.com
  • 使用DNS服务器1.1.1.1example.com发送DNS查询并期望收到任何响应

    • dns://example.com/1.1.1.1

依赖

~15–28MB
~421K SLoC