diff --git a/README.md b/README.md index 98512ae..92573e4 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ defaults: timeout: "10s" http: method: GET - maxBodyBytes: "100MB" + maxBodyBytes: "10MB" command: - maxOutputBytes: "100MB" + maxOutputBytes: "1MB" targets: - name: "Baidu" @@ -106,15 +106,17 @@ targets: - `http`: HTTP 类型默认值 - `method`: HTTP 方法,默认 `GET`,必须使用大写枚举值,支持 `GET`、`HEAD`、`POST`、`PUT`、`PATCH`、`DELETE`、`OPTIONS` - `maxBodyBytes`: 响应体最大字节数,默认 `100MB` + - `headers`: 默认请求头(target 中的 headers 会合并覆盖 defaults 中的同名头) - `command`: Command 类型默认值 - `maxOutputBytes`: 输出最大字节数,默认 `100MB` + - `cwd`: 默认工作目录(相对于配置文件所在目录解析,默认 `.`) - **targets**: 拨测目标列表(必填) - `name`: 目标名称(必填,唯一) - `type`: 目标类型,`http` 或 `command`(必填) - `group`: 分组名称(可选,默认 `"default"`) - `http`: HTTP 拨测配置(type 为 http 时必填) - `url`: 目标 URL - - `method`、`headers`、`body`: 请求参数 + - `method`、`headers`、`body`: 请求参数(`headers` 会与 `defaults.http.headers` 合并,target 优先) - `ignoreSSL`: 是否忽略 HTTPS 证书校验,默认 `false`,用于自签名或私有证书服务 - `maxRedirects`: 最大重定向跟随次数,默认 `0`(不跟随重定向) - `command`: 命令行拨测配置(type 为 command 时必填) @@ -124,17 +126,26 @@ targets: - `cwd`: 工作目录(可选,相对于配置文件所在目录解析,默认 `.`) - `interval`、`timeout`: 覆盖全局默认值 - `expect`: 期望校验 - - `status`: 可接受的状态码列表(HTTP),支持精确状态码和范围模式(如 `"2xx"`)混合配置 - - `exitCode`: 可接受的退出码列表(Command) - - `headers`: 响应头校验(HTTP,支持 `equals`、`contains` 等操作符) - - `maxDurationMs`: 最大耗时阈值(毫秒),HTTP 类型覆盖完整执行(含重定向、响应体读取和 expect 校验) + - `status`: 可接受的状态码列表(HTTP),支持精确状态码和范围模式(如 `"2xx"`)混合配置;未指定时默认 `[200]` + - `exitCode`: 可接受的退出码列表(Command);未指定时不校验退出码 + - `headers`: 响应头校验(HTTP,支持字符串精确匹配或操作符对象) + - `maxDurationMs`: 最大耗时阈值(毫秒) + - HTTP:覆盖完整执行(含重定向、响应体读取和 expect 校验) + - Command:覆盖命令执行耗时(含 stdout/stderr 读取) - `body`: HTTP 响应体校验(数组,可组合使用) - `contains`: 响应体包含的文本 - `regex`: 响应体匹配的正则表达式 - - `json`: JSONPath 提取值比较(`path` + 比较操作符) + - `json`: JSONPath 提取值比较 + - `path`: JSONPath 表达式(必填,如 `$.slideshow.title`) + - 比较操作符(可选,无操作符时仅检查路径对应值是否存在) - `css`: CSS 选择器提取 HTML 元素比较 + - `selector`: CSS 选择器(必填) + - `attr`: 提取元素属性值而非文本内容(可选,如 `href`、`class`) + - 比较操作符(可选,无操作符时仅检查元素是否存在) - `xpath`: XPath 提取 XML/HTML 节点比较 - - `stdout` / `stderr`: Command 输出校验(数组,同 body 格式) + - `path`: XPath 表达式(必填,如 `/html/body/h1/text()`) + - 比较操作符(可选,无操作符时仅检查节点是否存在) + - `stdout` / `stderr`: Command 输出校验(数组,每项为一个操作符对象) - 比较操作符:`equals`(默认)、`contains`、`match`(正则)、`empty`、`exists`、`gte`、`lte`、`gt`、`lt` 大小说明:`maxBodyBytes` 和 `maxOutputBytes` 支持单位 `KB`、`MB`、`GB`,也可直接使用数字(非负安全整数字节数)。 @@ -145,7 +156,7 @@ targets: JSON Schema:仓库根目录导出 `probe-config.schema.json`,可在 YAML 文件顶部添加 `# yaml-language-server: $schema=./probe-config.schema.json` 获取编辑器提示和静态校验。该 schema 由运行期契约 fragments 生成,提交前可用 `bun run schema:check` 检查同步。 -时长格式支持:`30s`、`5m`、`500ms` +时长格式支持:`500ms`、`30s`、`5m`、`2h`、`7d` ## API 端点 @@ -167,7 +178,7 @@ JSON Schema:仓库根目录导出 `probe-config.schema.json`,可在 YAML 文 **CheckResult**: `timestamp`、`matched`、`durationMs`、`statusDetail`、`failure` -**CheckFailure**: `kind`(error/mismatch)、`phase`、`path`、`expected`、`actual`、`message` +**CheckFailure**: `kind`(error/mismatch)、`phase`、`path`、`message`、`expected?`(仅 mismatch)、`actual?`(仅 mismatch) **TargetStats**: `totalChecks`、`availability` @@ -201,7 +212,7 @@ CLI 只接受一个参数:YAML 配置文件路径。 单层判定模型,适用于 HTTP 和 Command 两种类型: -- **matched**: 是否符合 expect 规则(HTTP 无 expect 时默认检查 status 200) +- **matched**: 是否符合 expect 规则(HTTP 未指定 `expect.status` 时默认检查 `[200]`) - **UP** = matched - **DOWN** = NOT matched