M AI 员工技能商店
AI 员工平台 返回商城
返回技能商店

小紫 服务巡检插件

v1.0.0 · 运维协作 · 官方

运维 巡检 探活 端口 HTTP 小紫

简介

小紫 服务巡检插件 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:// 前缀
  • method HEAD(默认,更快)或 GET
  • expect_status 期望状态:2xx(默认)、200、200,201、200-299
  • verify_ssl 内网自签证书可设 false
  • timeout 超时秒数,默认 10

port_check 参数要点:

  • host + port,或 target 简写如 192.168.1.1:3306

batch 参数要点:

  • targets JSON 数组字符串,或 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"}
]

安装

  1. 解压到 D:\xiaozi-plugins\运维协作\服务巡检插件\
  2. 复制 python/ 到本目录
  3. 测试: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/GETPOST 带 Body 探测
TCP 端口连通UDP / ICMP ping
批量 JSON/Markdown定时自动巡检调度
跳过自签证书OAuth 等复杂认证

与其他插件配合

  • 日志分析插件:探活失败后 tail/search 对应服务日志
  • 系统基础插件:exec_cmd 查进程、重启服务
  • 小紫_push:巡检异常结果推送给同事

推荐顺序:batch 全量扫 → 单项复查 → 日志分析定位

详见包内 服务巡检插件.md。