小紫 服务巡检插件
v1.0.0 · 运维协作 · 官方
简介
小紫 服务巡检插件 v1.0,AI 一键检查服务是否存活:
- ping_url HTTP/HTTPS 探测:状态码 + 响应时间(ms)
- port_check TCP 端口连通检测
- batch 批量巡检,输出 JSON 或 Markdown 报告
- 无需 pip,标准库即可,适合内网 Web / API / 数据库端口
典型流程:batch 批量扫一遍 → 异常项 ping_url/port_check 单独复查 → 配合日志分析查原因
操作说明
| action | 功能 |
|---|---|
ping_url | 探测 URL 是否可访问,返回状态码与耗时 |
port_check | 检测 TCP 端口是否可达 |
batch | 按列表批量检测并汇总报告 |
ping_url 参数要点:
url目标地址,可省略http://前缀methodHEAD(默认,更快)或GETexpect_status期望状态:2xx(默认)、200、200,201、200-299verify_ssl内网自签证书可设falsetimeout超时秒数,默认 10
port_check 参数要点:
host+port,或target简写如192.168.1.1:3306
batch 参数要点:
targetsJSON 数组字符串,或configfile指向配置文件- 也可在
config/service_check_config.json预设 targets format设markdown额外输出表格报告
targets 示例:
[
{"name": "官网", "type": "url", "url": "https://example.com"},
{"name": "MySQL", "type": "port", "host": "192.168.1.1", "port": 3306},
{"name": "健康检查", "type": "url", "url": "http://192.168.1.100:8080/health", "method": "GET", "expect_status": "200"}
]
安装
- 解压到
D:\xiaozi-plugins\运维协作\服务巡检插件\ - 复制
python/到本目录 - 测试:
run.bat --action ping_url --url https://www.baidu.com
| 文件 | 说明 |
|---|---|
service_check_plugin.py | 主程序 |
run.bat / run.sh | 启动脚本 |
服务巡检插件.md | 用户文档 |
config/service_check.example.json | 配置示例 |
上架文案/ | 商店详情(本文件,不打 zip) |
无需 pip,标准库即可。
命令行
REM HTTP 探测
run.bat --action ping_url --url https://www.baidu.com
REM 健康检查接口
run.bat --action ping_url --url http://192.168.1.100:8080/health --method GET --expect_status 200 --timeout 5
REM 自签名 HTTPS
run.bat --action ping_url --url https://192.168.1.50 --verify_ssl false
REM 端口检测
run.bat --action port_check --host 127.0.0.1 --port 3306
run.bat --action port_check --target 192.168.1.1:6379
REM 批量巡检
run.bat --action batch --configfile D:\xiaozi-plugins\运维协作\服务巡检插件\config\service_check_config.json
REM Markdown 报告
run.bat --action batch --configfile D:\xiaozi-plugins\运维协作\服务巡检插件\config\service_check_config.json --format markdown
注册技能 service_check
名称: service_check
描述: 服务巡检 v1.0:ping_url/port_check/batch。HTTP HTTPS 探活返回状态码响应时间,TCP 端口连通检测,批量巡检输出报告。用户检查网站可用性、端口是否开放、批量巡检内网服务时使用。ping_url 需 url;port_check 需 host+port 或 target;batch 需 targets JSON 或 configfile。
脚本: D:\xiaozi-plugins\运维协作\服务巡检插件\run.bat
参数 JSON:
{
"type": "object",
"properties": {
"action": {"type": "string", "enum": ["ping_url", "port_check", "batch"], "description": "操作类型"},
"url": {"type": "string", "description": "ping_url 目标 URL"},
"host": {"type": "string", "description": "port_check 主机"},
"port": {"type": "string", "description": "port_check 端口"},
"target": {"type": "string", "description": "port_check 简写 host:port"},
"targets": {"type": "string", "description": "batch 目标 JSON 数组"},
"configfile": {"type": "string", "description": "batch 配置文件路径"},
"timeout": {"type": "string", "description": "超时秒数默认10"},
"method": {"type": "string", "description": "HEAD/GET"},
"expect_status": {"type": "string", "description": "期望状态码 2xx/200"},
"verify_ssl": {"type": "string", "description": "HTTPS 校验 true/false"},
"format": {"type": "string", "description": "batch 输出 json/markdown"}
},
"required": ["action"]
}
对话示例
| 场景 | 说法 |
|---|---|
| 探 URL | 检查一下 https://www.example.com 能不能访问 |
| 探端口 | 看看 192.168.1.100 的 3306 端口通不通 |
| 批量 | 按配置文件批量巡检内网服务 |
| 报告 | 批量巡检并生成 Markdown 报告 |
| 内网 HTTPS | 探测 https://192.168.1.50,跳过证书校验 |
小紫 AI 会根据描述选 action 并传 url、host、port、targets 等参数。
常见错误
| 现象 | 处理 |
|---|---|
| 连接超时 | 加大 timeout 或查网络防火墙 |
| HTTPS 证书错误 | 内网自签设 verify_ssl false |
| port 参数无效 | 传 host+port 或 target 192.168.1.1:3306 |
| batch 无目标 | 传 targets JSON 或 configfile |
| 状态码不符 | 调整 expect_status,如 200 或 2xx |
| python folder missing | 复制 python 到插件目录 |
能力边界
| 支持 | 不支持 |
|---|---|
| HTTP/HTTPS HEAD/GET | POST 带 Body 探测 |
| TCP 端口连通 | UDP / ICMP ping |
| 批量 JSON/Markdown | 定时自动巡检调度 |
| 跳过自签证书 | OAuth 等复杂认证 |
与其他插件配合
- 日志分析插件:探活失败后 tail/search 对应服务日志
- 系统基础插件:exec_cmd 查进程、重启服务
- 小紫_push:巡检异常结果推送给同事
推荐顺序:batch 全量扫 → 单项复查 → 日志分析定位
详见包内 服务巡检插件.md。