feat: 重构为多类型 checker 通用框架,支持 HTTP 与命令检查
- 引入 typed target 判别联合,支持 http 与 command 两种 checker - expect 重构为有序规则数组,按配置顺序快速失败并生成结构化 failure - 新增 command runner,支持 exec + args 本地命令执行 - 引入全局并发限制 maxConcurrentChecks 和 size 解析 (KB/MB/GB) - HTTP/command 各自独立 expect pipeline,应用领域默认成功语义 - SQLite schema、API、Dashboard 全链路调整为 checker 通用契约 - 补充完整测试覆盖(192 tests),更新 README 与示例配置
This commit is contained in:
@@ -3,34 +3,207 @@ server:
|
||||
port: 3000
|
||||
dataDir: "/tmp/probes_data"
|
||||
|
||||
runtime:
|
||||
maxConcurrentChecks: 20
|
||||
|
||||
defaults:
|
||||
interval: "5s"
|
||||
interval: "30s"
|
||||
timeout: "10s"
|
||||
method: "GET"
|
||||
http:
|
||||
method: GET
|
||||
maxBodyBytes: "10MB"
|
||||
command:
|
||||
maxOutputBytes: "1MB"
|
||||
|
||||
targets:
|
||||
- name: "Baidu"
|
||||
url: "https://www.baidu.com"
|
||||
expect:
|
||||
status: [200]
|
||||
maxLatencyMs: 10000
|
||||
# ========== HTTP targets ==========
|
||||
|
||||
- name: "JSON API 示例"
|
||||
url: "https://httpbin.org/json"
|
||||
- name: "Baidu 首页可用"
|
||||
type: http
|
||||
http:
|
||||
url: "https://www.baidu.com"
|
||||
expect:
|
||||
status: [200]
|
||||
maxDurationMs: 5000
|
||||
|
||||
- name: "JSON API — 完整流水线"
|
||||
type: http
|
||||
interval: "1m"
|
||||
timeout: "15s"
|
||||
http:
|
||||
url: "https://httpbin.org/json"
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
Accept: "application/json"
|
||||
expect:
|
||||
headers:
|
||||
Content-Type:
|
||||
contains: "application/json"
|
||||
maxDurationMs: 8000
|
||||
body:
|
||||
contains: "slideshow"
|
||||
json:
|
||||
$.slideshow.title: "Sample Slide Show"
|
||||
- json:
|
||||
path: "$.slideshow.title"
|
||||
equals: "Sample Slide Show"
|
||||
- json:
|
||||
path: "$.slideshow.slides[0].title"
|
||||
contains: "Wake"
|
||||
- json:
|
||||
path: "$.slideshow.slides[0].type"
|
||||
equals: "all"
|
||||
- regex: '"title"'
|
||||
|
||||
- name: "HTML 页面示例"
|
||||
url: "https://httpbin.org/html"
|
||||
- name: "HTML 页面 — CSS 选择器"
|
||||
type: http
|
||||
http:
|
||||
url: "https://httpbin.org/html"
|
||||
expect:
|
||||
body:
|
||||
- css:
|
||||
selector: "h1"
|
||||
contains: "Moby-Dick"
|
||||
- css:
|
||||
selector: "body"
|
||||
exists: true
|
||||
|
||||
- name: "HTML 页面 — XPath 提取节点文本"
|
||||
type: http
|
||||
http:
|
||||
url: "https://httpbin.org/html"
|
||||
expect:
|
||||
body:
|
||||
- xpath:
|
||||
path: "/html/body/h1/text()"
|
||||
contains: "Melville"
|
||||
|
||||
- name: "POST 接口测试"
|
||||
type: http
|
||||
http:
|
||||
url: "https://httpbin.org/post"
|
||||
method: POST
|
||||
headers:
|
||||
Content-Type: "application/json"
|
||||
body: '{"action":"check","version":1}'
|
||||
expect:
|
||||
status: [200]
|
||||
body:
|
||||
contains: "Moby-Dick"
|
||||
xpath:
|
||||
"/html/body/h1/text()": "Herman Melville - Moby-Dick"
|
||||
- json:
|
||||
path: "$.json.action"
|
||||
equals: "check"
|
||||
- json:
|
||||
path: "$.json.version"
|
||||
gte: 1
|
||||
|
||||
- name: "请求头验证"
|
||||
type: http
|
||||
http:
|
||||
url: "https://httpbin.org/headers"
|
||||
headers:
|
||||
X-Custom-Header: "gateway-checker"
|
||||
expect:
|
||||
status: [200]
|
||||
body:
|
||||
- json:
|
||||
path: "$.headers.X-Custom-Header"
|
||||
equals: "gateway-checker"
|
||||
|
||||
- name: "响应头自定义校验"
|
||||
type: http
|
||||
http:
|
||||
url: "https://httpbin.org/response-headers"
|
||||
headers:
|
||||
accept: "application/json"
|
||||
expect:
|
||||
body:
|
||||
- json:
|
||||
path: "$.Content-Type"
|
||||
equals: "application/json"
|
||||
|
||||
- name: "多状态码允许"
|
||||
type: http
|
||||
http:
|
||||
url: "https://httpbin.org/status/200"
|
||||
expect:
|
||||
status: [200, 201, 204]
|
||||
|
||||
# ========== Command targets ==========
|
||||
|
||||
- name: "uname 输出匹配"
|
||||
type: command
|
||||
command:
|
||||
exec: "uname"
|
||||
args: ["-s"]
|
||||
expect:
|
||||
exitCode: [0]
|
||||
stdout:
|
||||
- match: "^[A-Z][a-z]+$"
|
||||
|
||||
- name: "echo 自定义文本输出"
|
||||
type: command
|
||||
command:
|
||||
exec: "echo"
|
||||
args: ["check ok"]
|
||||
expect:
|
||||
stdout:
|
||||
- equals: "check ok\n"
|
||||
maxDurationMs: 3000
|
||||
|
||||
- name: "ls 目录无 stderr"
|
||||
type: command
|
||||
command:
|
||||
exec: "ls"
|
||||
args: ["/tmp"]
|
||||
cwd: "/"
|
||||
expect:
|
||||
exitCode: [0]
|
||||
stderr:
|
||||
- empty: true
|
||||
|
||||
- name: "date 输出包含年份"
|
||||
type: command
|
||||
command:
|
||||
exec: "date"
|
||||
args: ["+%Y"]
|
||||
expect:
|
||||
stdout:
|
||||
- match: "^20\\d{2}\n?$"
|
||||
|
||||
- name: "wc 行数计数"
|
||||
type: command
|
||||
command:
|
||||
exec: "wc"
|
||||
args: ["-l"]
|
||||
cwd: "/etc"
|
||||
env:
|
||||
LANG: "C"
|
||||
expect:
|
||||
stdout:
|
||||
- match: "\\d+"
|
||||
|
||||
- name: "hostname 非空输出"
|
||||
type: command
|
||||
command:
|
||||
exec: "hostname"
|
||||
expect:
|
||||
stdout:
|
||||
- match: ".+"
|
||||
|
||||
- name: "多规则 stdout 顺序校验"
|
||||
type: command
|
||||
interval: "5m"
|
||||
command:
|
||||
exec: "echo"
|
||||
args: ["version: 2.0.1, status: healthy"]
|
||||
expect:
|
||||
stdout:
|
||||
- contains: "version:"
|
||||
- match: "\\d+\\.\\d+\\.\\d+"
|
||||
- contains: "healthy"
|
||||
|
||||
- name: "stderr 内容检查"
|
||||
type: command
|
||||
command:
|
||||
exec: "ls"
|
||||
args: ["/nonexistent-path-checker-test"]
|
||||
expect:
|
||||
exitCode: [0, 1, 2]
|
||||
stderr:
|
||||
- contains: "No such file"
|
||||
|
||||
Reference in New Issue
Block a user