alibabacloud-smartag-pilot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSAG Pilot v1.0
SAG Pilot v1.0
SAG (Smart Access Gateway / 智能接入网关) configuration query and status inspection skill. Uses aliyun CLI plugin mode.
Architecture: (read-only inspection, no resource modification)
SAG Device/APP → CCN → CEN → VPCSAG(Smart Access Gateway / 智能接入网关)配置查询与状态巡检技能,采用阿里云CLI插件模式。
架构: (只读巡检,不修改资源)
SAG Device/APP → CCN → CEN → VPCPre-checks
前置检查
Pre-check: Aliyun CLI >= 3.3.3 required Runto verify >= 3.3.3. If not installed or version too low, runaliyun versionto install/update, or seecurl -fsSL https://aliyuncli.alicdn.com/setup.sh | bashfor installation instructions.references/cli-installation-guide.md
Pre-check: SAG plugin installed and up-to-datebashaliyun plugin install --names aliyun-cli-smartag aliyun plugin update aliyun configure set --auto-plugin-install true
[MUST] Enable AI-Mode — AI-mode is required for Agent Skill execution. At the start of the workflow (before any CLI invocation):bashaliyun configure ai-mode enable aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-smartag-pilot"
[MUST] Disable AI-Mode at EVERY exit point — Before delivering the final response for ANY reason (success, failure, error, cancellation), always disable AI-mode first:bashaliyun configure ai-mode disable
前置检查:需Aliyun CLI >= 3.3.3 运行验证版本是否 >=3.3.3。若未安装或版本过低, 运行aliyun version进行安装/更新, 或查看curl -fsSL https://aliyuncli.alicdn.com/setup.sh | bash获取安装说明。references/cli-installation-guide.md
前置检查:SAG插件已安装并更新至最新版本bashaliyun plugin install --names aliyun-cli-smartag aliyun plugin update aliyun configure set --auto-plugin-install true
[必须] 启用AI模式 —— Agent Skill执行需要AI模式。 在工作流开始时(调用任何CLI命令之前):bashaliyun configure ai-mode enable aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-smartag-pilot"
[必须] 在所有退出点禁用AI模式 —— 无论因何种原因(成功、失败、错误、取消)返回最终响应前,务必先禁用AI模式:bashaliyun configure ai-mode disable
Authentication
身份验证
Pre-check: Alibaba Cloud Credentials RequiredSecurity Rules:
- NEVER read, echo, or print AK/SK values (e.g.,
is FORBIDDEN)echo $ALIBABA_CLOUD_ACCESS_KEY_ID- NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use
with literal credential valuesaliyun configure set- ONLY use
to check credential statusaliyun configure listbashaliyun configure listCheck the output for a valid profile (AK, STS, or OAuth identity).If no valid profile exists, STOP here.
- Obtain credentials from Alibaba Cloud Console
- Configure credentials outside of this session (via
in terminal or environment variables in shell profile)aliyun configure- Return and re-run after
shows a valid profilealiyun configure list
前置检查:需阿里云凭证安全规则:
- 严禁读取、回显或打印AK/SK值(例如
是禁止操作)echo $ALIBABA_CLOUD_ACCESS_KEY_ID- 严禁要求用户在对话或命令行中直接输入AK/SK
- 严禁使用
传入明文凭证值aliyun configure set- 仅可使用
检查凭证状态aliyun configure listbashaliyun configure list检查输出中是否存在有效配置文件(AK、STS或OAuth身份)。若不存在有效配置文件,请在此处停止操作。
- 从阿里云控制台获取凭证
- 在本次会话外配置凭证(通过终端的
或Shell配置文件中的环境变量)aliyun configure- 待
显示有效配置文件后,返回并重新运行aliyun configure list
RAM Policy
RAM权限策略
This skill requires read-only SAG permissions. See references/ram-policies.md for full JSON policy.
[MUST] Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:
- Read
to get the full list of permissions required by this SKILLreferences/ram-policies.md- Use
skill to guide the user through requesting the necessary permissionsram-permission-diagnose- Pause and wait until the user confirms that the required permissions have been granted
本技能需要SAG只读权限。完整JSON策略请查看references/ram-policies.md。
[必须] 权限失败处理: 若执行过程中任何命令或API调用因权限错误失败,请遵循以下流程:
- 查看
获取本技能所需的完整权限列表references/ram-policies.md- 使用
技能引导用户申请必要权限ram-permission-diagnose- 暂停操作,等待用户确认所需权限已授予
Parameter Confirmation
参数确认
IMPORTANT: Parameter Confirmation — Before executing any command or API call, ALL user-customizable parameters (e.g., RegionId, SmartAGId, query scope, output format) MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.
| Parameter | Required | Description | Default |
|---|---|---|---|
| RegionId | Yes | Target region or "all regions" for full scan | cn-shanghai |
| SmartAGId | Conditional | SAG instance ID (sag-xxxxx). Not needed for "all instances" queries | — |
| Query Scope | Yes | Which modules/functions to execute | All applicable |
| Output Format | Optional | Conversation summary and/or report file | Both |
重要:参数确认 —— 在执行任何命令或API调用前, 所有用户可自定义参数(如RegionId、SmartAGId、查询范围、输出格式) 必须与用户确认。未经用户明确同意,不得假设或使用默认值。
| 参数 | 是否必填 | 描述 | 默认值 |
|---|---|---|---|
| RegionId | 是 | 目标区域,或填写"all regions"进行全量扫描 | cn-shanghai |
| SmartAGId | 可选 | SAG实例ID(格式为sag-xxxxx)。查询"所有实例"时无需填写 | — |
| 查询范围 | 是 | 要执行的模块/功能 | 所有适用项 |
| 输出格式 | 可选 | 对话摘要和/或报告文件 | 两者都输出 |
Region Discovery
区域发现
When querying all regions, always start with:
bash
aliyun smartag describe-regions \
--endpoint smartag.cn-shanghai.aliyuncs.com \
--read-timeout 30 \
--connect-timeout 15This returns the authoritative list of all SAG-supported regions (RegionId + RegionEndpoint). Use the returned values to construct for subsequent per-region queries. Do NOT guess or hardcode region IDs.
RegionEndpoint--endpoint查询所有区域时,务必先执行:
bash
aliyun smartag describe-regions \
--endpoint smartag.cn-shanghai.aliyuncs.com \
--read-timeout 30 \
--connect-timeout 15该命令返回所有支持SAG的权威区域列表(RegionId + RegionEndpoint)。使用返回的值构建后续各区域查询的参数。请勿猜测或硬编码区域ID。
RegionEndpoint--endpointAPI Invocation Method
API调用方式
Aliyun CLI (Plugin Mode)
阿里云CLI(插件模式)
SAG plugin provides native command support with parameter validation and auto-completion:
bash
aliyun smartag describe-smart-access-gateways \
--endpoint smartag.cn-shanghai.aliyuncs.com \
--biz-region-id cn-shanghai \
--read-timeout 30 \
--connect-timeout 15 \
--smart-ag-id sag-xxxxxTemplate for any SAG CLI call:
bash
aliyun smartag <api-name-in-kebab-case> \
--endpoint smartag.<RegionId>.aliyuncs.com \
--biz-region-id <RegionId> \
--read-timeout 30 \
--connect-timeout 15 \
[--other-params ...]Naming conventions:
- API names: kebab-case (e.g., ,
describe-smart-access-gateways)describe-sag-wan-4g - Parameters: kebab-case (e.g., ,
--smart-ag-id,--smart-ag-sn)--page-size - Endpoint routing: controls which regional endpoint the request is sent to (REQUIRED for cross-region queries)
--endpoint smartag.<RegionId>.aliyuncs.com - Business region: is the API's RegionId parameter
--biz-region-id - IMPORTANT: Must use (not
--endpoint) for endpoint routing — the plugin's--regionmapping is incomplete and fails for eu-west-1, us-east-1, cn-zhangjiakou-spe--region - Special: only needs
describe-regions(no--endpoint)--biz-region-id
SAG插件提供原生命令支持,包含参数验证和自动补全:
bash
aliyun smartag describe-smart-access-gateways \
--endpoint smartag.cn-shanghai.aliyuncs.com \
--biz-region-id cn-shanghai \
--read-timeout 30 \
--connect-timeout 15 \
--smart-ag-id sag-xxxxx任何SAG CLI调用的模板:
bash
aliyun smartag <api-name-in-kebab-case> \
--endpoint smartag.<RegionId>.aliyuncs.com \
--biz-region-id <RegionId> \
--read-timeout 30 \
--connect-timeout 15 \
[--other-params ...]命名约定:
- API名称:使用短横线分隔的小写格式(kebab-case),例如、
describe-smart-access-gatewaysdescribe-sag-wan-4g - 参数:使用短横线分隔的小写格式,例如、
--smart-ag-id、--smart-ag-sn--page-size - 端点路由:控制请求发送到哪个区域端点(跨区域查询必须设置)
--endpoint smartag.<RegionId>.aliyuncs.com - 业务区域:是API的RegionId参数
--biz-region-id - 重要提示:必须使用而非
--endpoint进行端点路由——插件的--region映射不完整,在eu-west-1、us-east-1、cn-zhangjiakou-spe等区域会失效--region - 特殊情况:仅需
describe-regions(无需--endpoint)--biz-region-id
Mandatory Call Contracts
强制调用契约
These are hard requirements — for each scenario below you MUST satisfy the full API set listed. Do NOT substitute specialized API calls by reusing fields from the response.
describe-smart-access-gateways以下为硬性要求——对于下方每个场景,必须严格调用列出的完整API集合。不得通过复用响应中的字段来替代专用API调用。
describe-smart-access-gatewaysContract A — Single-Instance Full Configuration Query
契约A — 单实例完整配置查询
Trigger: 用户针对具体某个 实例询问配置(含「这个网关的配置」「看一下 xxx 的配置」「完整配置」「全部配置」「WAN/路由/DNAT 都查」「换网后对一下配置」「配置有没有问题」「检查 xxx 配置」等;即使夹带「巡检/诊断/检查」字样仍属本场景,⛔ 严禁误用 Contract D)。
sag-xxxYou MUST call all 12 APIs below (skip device-level ones only if the instance is — see Contract C):
sag-software| # | API | Notes |
|---|---|---|
| A1 | | Instance basic info + classification |
| A2 | | VPN status + detailed attributes |
| A3 | | Device-level, needs |
| A4 | | Device-level, needs |
| A5 | | Static routes |
| A6 | | Full route table |
| A7 | | MUST use |
| A8 | | Uses |
| A9 | | CCN (region-level) |
| A10 | | ACL (region-level) |
| A11 | | QoS (region-level) |
| A12 | | Device-level, needs |
Contract A — 关键规则要点(详细 12-line bash 骨架与 Self-check 断言见 references/contract-skeletons.md § Contract A):
- 参数强绑定:A3/A4/A12 用 (SN 来自 A1
--smart-ag-sn $SN,逗号分隔时拆分逐 SN 调用;为空或 sag-software 则跳过 A3/A4/A12 走 Contract C);A5/A6 用SerialNumber;A7--smart-ag-id用describe-dnat-entries(注意与 A8 不同);A9/A10/A11 仅--sag-id。--biz-region-id - 参数错误恢复:CLI 报错 或
Error: --smart-ag-sn is required时必须对照 A1-A12 参数表立即修正后重试 2 次;❗严禁将 CLI 参数错误误归为 VPN 故障 / 网络异常 / 实例不存在而跳过该 API。--smart-ag-id is required - No-Chaining:❌ 严禁用 /
&&/;/||拼接命令;每条 API 必须独立成行、独立重定向到|、独立捕获 exit code。失败时单条重试 2 次(间隔 500ms),重试仍失败标/tmp/sag_a*.json并继续执行后续,禁止 abort。禁止FAILED:。set -e - Forbidden shortcuts:❌ 禁止用 /
AclIds/AssociatedCcnId字段替代 A3/A9/A10 调用;❌ 禁止HardwareVersion/# TODO占位略过任何一条;❌ 禁止把...错写为--smart-ag-sn。--smart-ag-id - Self-check:12 条执行完毕后必须运行 Self-check 断言所有产物文件非空,缺一即 exit 1。
Contract A 12-line bash 骨架——仅用于「单实例 12 项完整配置查询」场景;⛔ 禁止与下方 Contract D 10-line 混用(D 仅用于 10 项健康巡检):
bash
aliyun smartag describe-smart-access-gateways --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a01.json
aliyun smartag describe-smart-access-gateway-attribute --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a02.json
aliyun smartag describe-sag-device-info --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_a03.json
aliyun smartag describe-sag-wan-list --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_a04.json
aliyun smartag describe-sag-static-route-list --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a05.json
aliyun smartag describe-sag-route-list --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a06.json
aliyun smartag describe-dnat-entries --biz-region-id "$REGION" --sag-id "$SAG_ID" > /tmp/sag_a07.json
aliyun smartag describe-snat-entries --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a08.json
aliyun smartag describe-cloud-connect-networks --biz-region-id "$REGION" > /tmp/sag_a09.json
aliyun smartag describe-acls --biz-region-id "$REGION" > /tmp/sag_a10.json
aliyun smartag describe-qoses --biz-region-id "$REGION" > /tmp/sag_a11.json
aliyun smartag describe-sag-current-dns --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_a12.json触发条件:用户针对具体某个实例询问配置(含「这个网关的配置」「看一下xxx的配置」「完整配置」「全部配置」「WAN/路由/DNAT都查」「换网后对一下配置」「配置有没有问题」「检查xxx配置」等;即使夹带「巡检/诊断/检查」字样仍属于本场景,⛔ 严禁误用契约D)。
sag-xxx必须调用以下全部12个API(仅当实例为时跳过设备级API,详见契约C):
sag-software| 序号 | API | 说明 |
|---|---|---|
| A1 | | 实例基本信息 + 分类 |
| A2 | | VPN状态 + 详细属性 |
| A3 | | 设备级API,需要 |
| A4 | | 设备级API,需要 |
| A5 | | 静态路由 |
| A6 | | 完整路由表 |
| A7 | | 必须使用 |
| A8 | | 使用 |
| A9 | | CCN(区域级) |
| A10 | | ACL(区域级) |
| A11 | | QoS(区域级) |
| A12 | | 设备级API,需要 |
契约A — 关键规则要点(详细12行bash骨架与自检断言见references/contract-skeletons.md § 契约A):
- 参数强绑定:A3/A4/A12使用(SN来自A1的
--smart-ag-sn $SN,逗号分隔时需拆分后逐个SN调用;若SN为空或实例为sag-software则跳过A3/A4/A12,遵循契约C);A5/A6使用SerialNumber;A7的--smart-ag-id使用**describe-dnat-entries**(注意与A8不同);A9/A10/A11仅需--sag-id。--biz-region-id - 参数错误恢复:若CLI报错或
Error: --smart-ag-sn is required,必须对照A1-A12参数表立即修正后重试2次;❗严禁将CLI参数错误误判为VPN故障/网络异常/实例不存在而跳过该API。--smart-ag-id is required - 禁止链式调用:❌ 严禁使用/
&&/;/||拼接命令;每条API必须独立成行、独立重定向到|、独立捕获退出码。失败时单条重试2次(间隔500ms),重试仍失败则标记/tmp/sag_a*.json并继续执行后续命令,禁止终止流程。禁止使用FAILED:。set -e - 禁止捷径操作:❌ 禁止用/
AclIds/AssociatedCcnId字段替代A3/A9/A10的调用;❌ 禁止用HardwareVersion/# TODO占位跳过任何一条API;❌ 禁止将...误写为--smart-ag-sn。--smart-ag-id - 自检:12条命令执行完毕后必须运行自检断言,确保所有产物文件非空,缺失任一文件则退出并返回码1。
契约A的12行bash骨架——仅用于「单实例12项完整配置查询」场景;⛔ 禁止与下方契约D的10行骨架混用(D仅用于10项健康巡检):
bash
aliyun smartag describe-smart-access-gateways --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a01.json
aliyun smartag describe-smart-access-gateway-attribute --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a02.json
aliyun smartag describe-sag-device-info --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_a03.json
aliyun smartag describe-sag-wan-list --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_a04.json
aliyun smartag describe-sag-static-route-list --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a05.json
aliyun smartag describe-sag-route-list --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a06.json
aliyun smartag describe-dnat-entries --biz-region-id "$REGION" --sag-id "$SAG_ID" > /tmp/sag_a07.json
aliyun smartag describe-snat-entries --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_a08.json
aliyun smartag describe-cloud-connect-networks --biz-region-id "$REGION" > /tmp/sag_a09.json
aliyun smartag describe-acls --biz-region-id "$REGION" > /tmp/sag_a10.json
aliyun smartag describe-qoses --biz-region-id "$REGION" > /tmp/sag_a11.json
aliyun smartag describe-sag-current-dns --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_a12.jsonContract B — Multi-Region Asset Inventory
契约B — 多区域资产盘点
Trigger: user asks for inventory across regions (e.g. "资产盘点", "全部区域", "所有地域", "region discovery").
You MUST:
- Call first — never hardcode region IDs in code or conversation text.
describe-regions - Iterate the returned regions via a variable () and for each region call:
for region in ...- (instance list with pagination)
describe-smart-access-gateways - (CCN, once per region, NOT per instance)
describe-cloud-connect-networks - (once per region)
describe-acls - (once per region)
describe-qoses
- In reports, refer to regions by the variable from the DescribeRegions response — do not spell out region IDs as literals in your commentary.
Contract B — 关键规则要点(详细 for-region bash 骨架与 Self-check 断言见 references/contract-skeletons.md § Contract B):
- Skeleton + 循环内即时断言:取动态区域列表 → 对每个区域并列调用 4 个 API(实例 / CCN / ACL / QoS);每个区域循环尾部立即断言 4 个
describe-regions均非空,缺一即记/tmp/sag_b0[1-4]_${REGION}.json继续下一个区域,禁止 break 中断循环;REGION_FAILED: $REGION/describe-acls每区域仅 1 次调用缺一即 Contract B 失败。describe-qoses - Data Collection Order:✅ for 循环内仅把 raw JSON 落盘到 ;✅ 循环结束后再统一
/tmp/sag_*_${REGION}.json聚合 + 写最终 CSV;❌ 严禁边查边jq追加。>> file.csv - 零实例占位:每个区域在最终 CSV 中必须至少出现一行;空实例区域写占位行(),禁止整体丢弃。
Region=xxx, Instances=0, Note="no instances" - CSV 一致性断言:CSV 出现的唯一 Region 数 == DescribeRegions 有效区域数 N;4 个区域级 API 的产物文件数也必须 == N,否则 exit 1。
Contract B for 循环 bash 骨架——每区域必须严格顺序执行 4 条,循环尾即时断言;⛔ 禁止在循环外单独调用或合并请求,禁止漏掉任一区域:
bash
for REGION in $(jq -r '.Regions.Region[].RegionId' /tmp/sag_regions.json); do
EP=smartag.${REGION}.aliyuncs.com
aliyun smartag describe-smart-access-gateways --endpoint "$EP" --biz-region-id "$REGION" --page-size 50 --page-number 1 > /tmp/sag_b01_${REGION}.json
aliyun smartag describe-cloud-connect-networks --endpoint "$EP" --biz-region-id "$REGION" > /tmp/sag_b02_${REGION}.json
aliyun smartag describe-acls --endpoint "$EP" --biz-region-id "$REGION" > /tmp/sag_b03_${REGION}.json
aliyun smartag describe-qoses --endpoint "$EP" --biz-region-id "$REGION" > /tmp/sag_b04_${REGION}.json
for f in /tmp/sag_b0[1-4]_${REGION}.json; do [ -s "$f" ] || echo "REGION_FAILED: $REGION ($f)"; done
done触发条件:用户要求跨区域盘点资产(例如「资产盘点」「全部区域」「所有地域」「region discovery」)。
必须执行:
- 先调用——切勿在代码或对话文本中硬编码区域ID。
describe-regions - 通过变量遍历返回的区域(),并对每个区域调用:
for region in ...- (带分页的实例列表)
describe-smart-access-gateways - (CCN,每个区域调用一次,而非每个实例)
describe-cloud-connect-networks - (每个区域调用一次)
describe-acls - (每个区域调用一次)
describe-qoses
- 在报告中,使用DescribeRegions响应中的变量指代区域——请勿在注释中直接拼写区域ID字面量。
契约B — 关键规则要点(详细区域循环bash骨架与自检断言见references/contract-skeletons.md § 契约B):
- 骨架 + 循环内即时断言:通过获取动态区域列表 → 对每个区域并行调用4个API(实例/CCN/ACL/QoS);每个区域循环末尾立即断言4个
describe-regions文件均非空,缺失任一文件则标记/tmp/sag_b0[1-4]_${REGION}.json并继续下一个区域,禁止中断循环;REGION_FAILED: $REGION/describe-acls每个区域仅调用一次,缺失任一调用则契约B执行失败。describe-qoses - 数据收集顺序:✅ 循环内仅将原始JSON写入;✅ 循环结束后再统一用
/tmp/sag_*_${REGION}.json聚合并写入最终CSV;❌ 严禁边查询边用jq追加内容。>> file.csv - 零实例占位:每个区域在最终CSV中必须至少有一行;无实例的区域需写入占位行(),禁止直接丢弃该区域数据。
Region=xxx, Instances=0, Note="no instances" - CSV一致性断言:CSV中出现的唯一区域数 == DescribeRegions返回的有效区域数N;4个区域级API的产物文件数也必须 == N,否则退出并返回码1。
契约B的区域循环bash骨架——每个区域必须严格按顺序执行4条命令,循环末尾即时断言;⛔ 禁止在循环外单独调用或合并请求,禁止遗漏任何区域:
bash
for REGION in $(jq -r '.Regions.Region[].RegionId' /tmp/sag_regions.json); do
EP=smartag.${REGION}.aliyuncs.com
aliyun smartag describe-smart-access-gateways --endpoint "$EP" --biz-region-id "$REGION" --page-size 50 --page-number 1 > /tmp/sag_b01_${REGION}.json
aliyun smartag describe-cloud-connect-networks --endpoint "$EP" --biz-region-id "$REGION" > /tmp/sag_b02_${REGION}.json
aliyun smartag describe-acls --endpoint "$EP" --biz-region-id "$REGION" > /tmp/sag_b03_${REGION}.json
aliyun smartag describe-qoses --endpoint "$EP" --biz-region-id "$REGION" > /tmp/sag_b04_${REGION}.json
for f in /tmp/sag_b0[1-4]_${REGION}.json; do [ -s "$f" ] || echo "REGION_FAILED: $REGION ($f)"; done
doneContract C — sag-software Client Query (skip device-level)
契约C — sag-software客户端查询(跳过设备级API)
Trigger: (software APP client, no physical device).
HardwareVersion == "sag-software"You MUST:
- Call (APP user list — Item #11).
describe-smart-access-gateway-client-users - Still call region-level APIs: ,
describe-cloud-connect-networks,describe-acls,describe-qoses.describe-flow-logs - Skip all device-level APIs: ,
describe-sag-device-info,describe-sag-wan-list,describe-sag-static-route-list,describe-dnat-entries,describe-snat-entries.describe-sag-current-dns - Do NOT pass on any call (the SN field is empty for sag-software).
--smart-ag-sn
Contract C — 关键规则要点(详细 8-line bash 骨架与 Self-check 见 references/contract-skeletons.md § Contract C):
- 8 条 API 调用骨架包含 与
describe-flow-logs,缺一即 Contract C 失败。describe-sag-route-list - 在 sag-software 场景仍必须调用,参数用
describe-sag-route-list(⛔ 禁传--smart-ag-id $SAG_ID,SN 为空)。--smart-ag-sn - No-Chaining:8 条独立执行,禁止 /
&&/;拼接。|| - Self-check:所有产物文件非空 + 无 错误(PascalCase 检测)。
not a valid api
触发条件:(软件APP客户端,无物理设备)。
HardwareVersion == "sag-software"必须执行:
- 调用(APP用户列表——第11项)。
describe-smart-access-gateway-client-users - 仍需调用区域级API:、
describe-cloud-connect-networks、describe-acls、describe-qoses。describe-flow-logs - 跳过所有设备级API:、
describe-sag-device-info、describe-sag-wan-list、describe-sag-static-route-list、describe-dnat-entries、describe-snat-entries。describe-sag-current-dns - 任何调用中不得传入参数(sag-software的SN字段为空)。
--smart-ag-sn
契约C — 关键规则要点(详细8行bash骨架与自检见references/contract-skeletons.md § 契约C):
- 8条API调用骨架包含与
describe-flow-logs,缺失任一调用则契约C执行失败。describe-sag-route-list - 在sag-software场景下仍必须调用,参数使用
describe-sag-route-list(⛔ 禁止传入--smart-ag-id $SAG_ID,SN为空)。--smart-ag-sn - 禁止链式调用:8条命令独立执行,禁止使用/
&&/;拼接。|| - 自检:所有产物文件非空 + 无错误(检测是否误用PascalCase格式)。
not a valid api
Contract D — Complete Health Inspection (10 items)
契约D — 完整健康巡检(10项)
Trigger: 用户未指定具体实例而要求账号级/批量「完整巡检」「10 项巡检」「健康巡检」「全套巡检」;⛔ 用户问具体 实例配置(即使含「诊断/对一下/检查」字样)一律走 Contract A 12-line,禁用本契约。
sag-xxxContract D 10-line bash 骨架——仅用于「完整健康巡检 10 项」场景;⛔ 单实例 12 项配置查询请用上方 Contract A 12-line(kebab-case、参数已绑定、无条件全调):
bash
aliyun smartag describe-smart-access-gateways --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d01.json # #1 Status + #4 EndTime
aliyun smartag describe-smart-access-gateway-attribute --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d02.json # #2 VpnStatus
aliyun smartag describe-smart-access-gateway-ha --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d03.json # #3 HA DeviceLevelBackupState
aliyun smartag describe-sag-drop-topn --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" --size 10 > /tmp/sag_d05.json # #5 packet drop (graceful skip on SAG_QUERY_TOPN_ERROR)
aliyun smartag describe-sag-wan-4g --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_d06.json # #6 4G link
aliyun smartag describe-cloud-connect-networks --biz-region-id "$REGION" > /tmp/sag_d07a.json # #7 CCN
aliyun smartag describe-grant-sag-rules --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d07b.json # #7 CEN auth ⚠️ 无条件调用,禁止依 CCN 是否为空跳过
aliyun smartag describe-sag-route-list --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d08.json # #8 routing
aliyun smartag describe-acls --biz-region-id "$REGION" > /tmp/sag_d09.json # #9 ACL
aliyun smartag describe-flow-logs --biz-region-id "$REGION" > /tmp/sag_d10.json # #10 FlowLogDo NOT call (returns — see Known Unavailable APIs).
describe-health-checksInvalidApi.NotFound关键规则:
- API 必须 kebab-case:plugin-mode 下 PascalCase(如 、
DescribeSmartAccessGateways、DescribeGrantSagRules)会返回DescribeAcls,必须改写为 kebab-case。not a valid api - 无条件调用 10 项:❌ 严禁按字段状态条件跳过(如 、
if AssociatedCcnId is empty: skip describe-grant-sag-rules)。if HardwareVersion != "sag-software": skip describe-sag-wan-4g - 唯一 graceful skip 例外:遇
describe-sag-drop-topn可跳过该项,但调用动作必须发生,不能预判跳过。SAG_QUERY_TOPN_ERROR - Self-check:脚本末尾必须断言 10 个 产物文件均存在,且
/tmp/sag_d*.json无命中。grep 'not a valid api' /tmp/sag_d*.json
触发条件:用户未指定具体实例而要求账号级/批量「完整巡检」「10项巡检」「健康巡检」「全套巡检」;⛔ 用户询问具体实例配置(即使含「诊断/对一下/检查」字样)一律遵循契约A的12行骨架,禁用本契约。
sag-xxx契约D的10行bash骨架——仅用于「完整健康巡检10项」场景;⛔ 单实例12项配置查询请使用上方契约A的12行骨架(kebab-case格式、参数已绑定、无条件全调用):
bash
aliyun smartag describe-smart-access-gateways --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d01.json # #1 状态 + #4 到期时间
aliyun smartag describe-smart-access-gateway-attribute --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d02.json # #2 VPN状态
aliyun smartag describe-smart-access-gateway-ha --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d03.json # #3 高可用设备级备份状态
aliyun smartag describe-sag-drop-topn --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" --size 10 > /tmp/sag_d05.json # #5 丢包统计(遇SAG_QUERY_TOPN_ERROR可优雅跳过)
aliyun smartag describe-sag-wan-4g --biz-region-id "$REGION" --smart-ag-sn "$SN" > /tmp/sag_d06.json # #6 4G链路
aliyun smartag describe-cloud-connect-networks --biz-region-id "$REGION" > /tmp/sag_d07a.json # #7 CCN
aliyun smartag describe-grant-sag-rules --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d07b.json # #7 CEN授权 ⚠️ 无条件调用,禁止根据CCN是否为空跳过
aliyun smartag describe-sag-route-list --biz-region-id "$REGION" --smart-ag-id "$SAG_ID" > /tmp/sag_d08.json # #8 路由
aliyun smartag describe-acls --biz-region-id "$REGION" > /tmp/sag_d09.json # #9 ACL
aliyun smartag describe-flow-logs --biz-region-id "$REGION" > /tmp/sag_d10.json # #10 流量日志请勿调用(会返回——详见已知不可用API)。
describe-health-checksInvalidApi.NotFound关键规则:
- API必须使用kebab-case格式:插件模式下使用PascalCase格式(如、
DescribeSmartAccessGateways、DescribeGrantSagRules)会返回DescribeAcls,必须改为kebab-case格式。not a valid api - 无条件调用10项API:❌ 严禁根据字段状态条件跳过(例如、
if AssociatedCcnId为空: 跳过describe-grant-sag-rules)。if HardwareVersion != "sag-software": 跳过describe-sag-wan-4g - 唯一可优雅跳过的例外:遇
describe-sag-drop-topn可跳过该项,但必须执行调用动作,不能预先判断跳过。SAG_QUERY_TOPN_ERROR - 自检:脚本末尾必须断言10个产物文件均存在,且
/tmp/sag_d*.json无匹配结果。grep 'not a valid api' /tmp/sag_d*.json
Anti-Pattern: Field-Reuse Substitution
反模式:字段复用替代
❌ NEVER use the response of as a substitute for specialized API calls:
describe-smart-access-gateways| If you need … | ❌ Don't use | ✅ Must call |
|---|---|---|
| VPN tunnel state | | |
| CCN binding details | | |
| ACL bound to instance | | |
| QoS policies | (no such field) | |
| Device hardware | | |
The basic-info response is a classifier (what to call next), not a substitute (for what to skip calling).
Execution Blocking Rules(专用 API 调用失败时的处理闸门,详见 contract-skeletons.md § Anti-Pattern):
- ✅ 失败必须在报告中标注 或
FAILED: <错误原因>。SKIPPED: <跳过原因> - ❌ 严禁回退使用 /
AssociatedCcnId/AclIds/VpnStatus字段填充结论。HardwareVersion - ❌ 严禁静默跳过;必须在报告中保留该项的状态位。
- ✅ kebab-case/PascalCase 误用必须重新调用修正后的命令,不可跳过。
违反任意一条(尤其第 2 条字段回退)直接判为 Anti-Pattern 触发,评测会认为契约失败。
❌ 严禁使用的响应替代专用API调用:
describe-smart-access-gateways| 若需获取… | ❌ 请勿使用 | ✅ 必须调用 |
|---|---|---|
| VPN隧道状态 | 基础信息中的 | |
| CCN绑定详情 | | |
| 实例绑定的ACL | | |
| QoS策略 | (无对应字段) | |
| 设备硬件信息 | 仅 | |
基础信息响应仅作为分类器(决定下一步调用哪些API),而非替代方案(跳过某些API调用)。
执行阻塞规则(专用API调用失败时的处理闸门,详见contract-skeletons.md § 反模式):
- ✅ 失败必须在报告中标注或
FAILED: <错误原因>。SKIPPED: <跳过原因> - ❌ 严禁回退使用/
AssociatedCcnId/AclIds/VpnStatus字段填充结论。HardwareVersion - ❌ 严禁静默跳过;必须在报告中保留该项的状态位。
- ✅ kebab-case/PascalCase误用必须重新调用修正后的命令,不可跳过。
违反任意一条(尤其第2条字段回退)直接判定为反模式触发,评测会视为契约执行失败。
Mandatory Self-check Template(Contract A/B/C/D 共用,必须直接粘贴到脚本末尾)
强制自检模板(契约A/B/C/D共用,必须直接粘贴到脚本末尾)
bash
undefinedbash
undefined1. 所有 API 产物文件必须存在且非空
1. 所有API产物文件必须存在且非空
for f in /tmp/sag_*.json; do
[ -s "$f" ] || { echo "MISSING: $f"; exit 1; }
grep -q 'not a valid api' "$f" && { echo "PASCAL_ERROR: $f (use kebab-case)"; exit 1; }
done
for f in /tmp/sag_*.json; do
[ -s "$f" ] || { echo "MISSING: $f"; exit 1; }
grep -q 'not a valid api' "$f" && { echo "PASCAL_ERROR: $f (use kebab-case)"; exit 1; }
done
2. CSV 行数(不含表头)必须等于 jq 计算的实例/区域数
2. CSV行数(不含表头)必须等于jq计算的实例/区域数
[ "$(tail -n +2 final.csv | wc -l)" = "$EXPECTED_N" ] || { echo "COUNT_MISMATCH"; exit 1; }
[ "$(tail -n +2 final.csv | wc -l)" = "$EXPECTED_N" ] || { echo "COUNT_MISMATCH"; exit 1; }
3. Contract B 专用:区域级 API 产物必须 == 4 × N(N = describe-regions 有效区域数)
3. 契约B专用:区域级API产物数必须 == 4 × N(N = describe-regions返回的有效区域数)
[ "$(ls /tmp/sag_b0[1-4]_.json 2>/dev/null | wc -l)" = "$((4EXPECTED_N))" ] || { echo "REGION_API_MISSING"; exit 1; }
[ "$(ls /tmp/sag_b0[1-4]_.json 2>/dev/null | wc -l)" = "$((4EXPECTED_N))" ] || { echo "REGION_API_MISSING"; exit 1; }
4. Contract C (sag-software) 专用:禁止传 --smart-ag-sn(触发 forbidden 规则)
4. 契约C(sag-software)专用:禁止传入--smart-ag-sn(触发禁止规则)
[ "$HW" = "sag-software" ] && grep -q '--smart-ag-sn' /tmp/api_transcript.json && { echo "FORBIDDEN_SN_ON_SOFTWARE"; exit 1; }
违反 Self-check 即视为契约执行失败,禁止用任何字段回退绕过断言。[ "$HW" = "sag-software" ] && grep -q '--smart-ag-sn' /tmp/api_transcript.json && { echo "FORBIDDEN_SN_ON_SOFTWARE"; exit 1; }
违反自检规则即视为契约执行失败,严禁用任何字段回退绕过断言。Module 1: Configuration Query
模块1:配置查询
Execute queries based on user's request. Always output a structured summary.
根据用户请求执行查询,始终输出结构化摘要。
Query Level Classification
查询层级分类
Queries are classified into two levels. When performing batch queries, call region-level APIs only ONCE per region, not per instance:
Region-Level (query once per region, results shared across all instances in that region):
- #5 CCN list:
describe-cloud-connect-networks - #6 ACL rules:
describe-acls - #7 QoS policies:
describe-qoses - #9 Flow logs:
describe-flow-logs
Instance-Level (query per instance):
- All other functions (#1-4, #5 GrantRules/VBR, #8, #10-12)
查询分为两个层级。执行批量查询时,区域级API仅每个区域调用一次,而非每个实例调用一次:
区域级(每个区域查询一次,结果共享给该区域内所有实例):
- #5 CCN列表:
describe-cloud-connect-networks - #6 ACL规则:
describe-acls - #7 QoS策略:
describe-qoses - #9 流量日志:
describe-flow-logs
实例级(每个实例查询一次):
- 所有其他功能(#1-4、#5授权规则/VBR、#8、#10-12)
Feature Applicability Matrix
功能适用矩阵
Not all queries apply to all instance types. MUST skip inapplicable queries to avoid wasted API calls:
| # | Function | sag-1000/100wm (有SN) | sag-1000/100wm (无SN) | sag-software |
|---|---|---|---|---|
| 1 | Instance info | ✅ | ✅ | ✅ |
| 2 | Device hardware | ✅ | ❌ | ❌ |
| 3 | WAN config | ✅ | ❌ | ❌ |
| 4 | Routing | ✅ | ❌ | ❌ |
| 5 | CCN/CEN bindings | ✅ | ✅ | ✅ |
| 6 | ACL rules | ✅ (region) | ✅ (region) | ✅ (region) |
| 7 | QoS policies | ✅ (region) | ✅ (region) | ✅ (region) |
| 8 | DNAT/SNAT | ✅ | ✅ | ❌ |
| 9 | Flow logs | ✅ (region) | ✅ (region) | ✅ (region) |
| 10 | Packet drop (DropTopN) | ✅ | ✅ | ✅ (region) |
| 11 | SAG APP clients | ❌ | ❌ | ✅ |
| 12 | DNS config | ✅ | ❌ | ❌ |
判断逻辑:
- → 软件客户端,仅查 #1, #5, #6, #7, #9, #11(即 Contract C),禁止传
HardwareVersion == "sag-software"--smart-ag-sn - 为空 → 硬件设备未绑定,跳过 #2, #3, #4, #12
SerialNumber - 用户请求“完整配置”或已确定单实例 → 需调用 Contract A 列出的 12 个 API(其中 device-level 按上述规则规避)
- 在 2018-03-13 版本返回 InvalidApi.NotFound,当前不可用,请在报告中显式标注 skipped
describe-health-checks - 在主流区域(cn-shanghai/cn-hangzhou 等)可用,在边缘区域(如 cn-zhangjiakou-spe)可能返回 SAG_QUERY_TOPN_ERROR,这种情况下以 region unsupported 的形式跳过单项,不中断全局巡检
describe-sag-drop-topn
并非所有查询适用于所有实例类型。必须跳过不适用的查询,避免无效API调用:
| 序号 | 功能 | sag-1000/100wm (有SN) | sag-1000/100wm (无SN) | sag-software |
|---|---|---|---|---|
| 1 | 实例信息 | ✅ | ✅ | ✅ |
| 2 | 设备硬件 | ✅ | ❌ | ❌ |
| 3 | WAN配置 | ✅ | ❌ | ❌ |
| 4 | 路由 | ✅ | ❌ | ❌ |
| 5 | CCN/CEN绑定 | ✅ | ✅ | ✅ |
| 6 | ACL规则 | ✅ (区域级) | ✅ (区域级) | ✅ (区域级) |
| 7 | QoS策略 | ✅ (区域级) | ✅ (区域级) | ✅ (区域级) |
| 8 | DNAT/SNAT | ✅ | ✅ | ❌ |
| 9 | 流量日志 | ✅ (区域级) | ✅ (区域级) | ✅ (区域级) |
| 10 | 丢包统计(DropTopN) | ✅ | ✅ | ✅ (区域级) |
| 11 | SAG APP客户端 | ❌ | ❌ | ✅ |
| 12 | DNS配置 | ✅ | ❌ | ❌ |
判断逻辑:
- → 软件客户端,仅查询#1、#5、#6、#7、#9、#11(即契约C),禁止传入
HardwareVersion == "sag-software"--smart-ag-sn - 为空 → 硬件设备未绑定,跳过#2、#3、#4、#12
SerialNumber - 用户请求“完整配置”或已确定单实例 → 需调用契约A列出的12个API(其中设备级API按上述规则规避)
- 在2018-03-13版本返回InvalidApi.NotFound,当前不可用,请在报告中显式标注skipped
describe-health-checks - 在主流区域(如cn-shanghai/cn-hangzhou)可用,在边缘区域(如cn-zhangjiakou-spe)可能返回SAG_QUERY_TOPN_ERROR,这种情况下以region unsupported的形式跳过该项,不中断全局巡检
describe-sag-drop-topn
Multi-SN Handling & Parameter Pre-check
多SN处理与参数预检
Scope: 仅适用于 Contract A 硬件设备场景;Contract C (sag-software) 场景禁用本段的传参(会触发 forbidden 规则)。--smart-ag-sn
部分实例有主备双设备, 字段为逗号分隔(如 )。处理规则:
SerialNumbersag61dacczh,sag61daccq6- 参数预检:调用 A3/A4/A12 前必须先 ,若
SN=$(jq -r '.SmartAccessGateways.SmartAccessGateway[0].SerialNumber // ""' /tmp/sag_a01.json)则显式[ -z "$SN" ]并写空 JSON 占位echo "SKIPPED: no_sn",严禁因echo '{}' > /tmp/sag_a03.json报错中断后续 API 调用。--smart-ag-sn is required - 检测 SN 中是否包含逗号;多 SN 时拆分后对每个 SN 分别调用设备级 API(#2, #3, #4, #12)。
- 报告中按"主设备 / 备设备"分别展示结果。
适用范围:仅适用于契约A的硬件设备场景;契约C(sag-software)场景禁用本段的传参(会触发禁止规则)。--smart-ag-sn
部分实例有主备双设备,字段为逗号分隔(如)。处理规则:
SerialNumbersag61dacczh,sag61daccq6- 参数预检:调用A3/A4/A12前必须先执行,若
SN=$(jq -r '.SmartAccessGateways.SmartAccessGateway[0].SerialNumber // ""' /tmp/sag_a01.json)则显式[ -z "$SN" ]并写入空JSON占位echo "SKIPPED: no_sn",严禁因echo '{}' > /tmp/sag_a03.json报错中断后续API调用。--smart-ag-sn is required - 检测SN中是否包含逗号;多SN时拆分后对每个SN分别调用设备级API(#2、#3、#4、#12)。
- 报告中按“主设备 / 备设备”分别展示结果。
Available Query Functions
可用查询功能
| # | Function | API | Key Output |
|---|---|---|---|
| 1 | Instance info | | Status, bandwidth, expiry, CCN/CEN bindings, device SN |
| 2 | Device hardware | | Model, software version, latest version, 4G status |
| 3 | WAN config | | WAN IP/gateway/DNS, 4G signal status |
| 4 | Routing | | Static routes, BGP/OSPF config, route table |
| 5 | CCN/CEN bindings | | CCN info, CEN authorization, VBR relations |
| 6 | ACL rules | | Rules: src/dst IP, port, protocol, action |
| 7 | QoS policies | | Rate limits (CIR/PIR), traffic classifiers |
| 8 | DNAT/SNAT | | Port mapping, address translation rules |
| 9 | Flow logs | | Status, SLS project, bound instances |
| 10 | Packet drop | | Top-N packet drop statistics (use |
| 11 | SAG APP clients | | APP user list, client type, bandwidth quota ( |
| 12 | DNS config | | Active DNS servers |
| 序号 | 功能 | API | 关键输出 |
|---|---|---|---|
| 1 | 实例信息 | | 状态、带宽、到期时间、CCN/CEN绑定、设备SN |
| 2 | 设备硬件 | | 型号、软件版本、最新版本、4G状态 |
| 3 | WAN配置 | | WAN IP/网关/DNS、4G信号状态 |
| 4 | 路由 | | 静态路由、BGP/OSPF配置、路由表 |
| 5 | CCN/CEN绑定 | | CCN信息、CEN授权、VBR关联关系 |
| 6 | ACL规则 | | 规则:源/目的IP、端口、协议、动作 |
| 7 | QoS策略 | | 速率限制(CIR/PIR)、流量分类器 |
| 8 | DNAT/SNAT | | 端口映射、地址转换规则 |
| 9 | 流量日志 | | 状态、SLS项目、绑定实例 |
| 10 | 丢包统计 | | Top-N丢包统计(使用 |
| 11 | SAG APP客户端 | | APP用户列表、客户端类型、带宽配额( |
| 12 | DNS配置 | | 活跃DNS服务器 |
Query Workflow
查询工作流
- Identify which config the user wants to query
- Confirm RegionId and SmartAGId (ask if not provided)
- Check applicability: determine instance type (sag-software vs hardware) and whether SN exists
- Check multi-SN: if SerialNumber contains comma, split and query each device separately
- Respect query levels: region-level APIs (#5 CCN list, #6, #7, #9) only call once per region
- Call the corresponding API via CLI
- Parse response with fault-tolerance (see references/openapi-reference.md § Response Structure Notes)
- Present structured summary
- If user requests a report file, generate markdown report (see Output section)
- 识别用户需要查询的配置类型
- 确认RegionId和SmartAGId(未提供则询问用户)
- 检查适用性:确定实例类型(sag-software vs 硬件)以及是否存在SN
- 检查多SN:若SerialNumber包含逗号,拆分后分别查询每个设备
- 遵循查询层级:区域级API(#5 CCN列表、#6、#7、#9)仅每个区域调用一次
- 通过CLI调用对应API
- 容错解析响应(详见references/openapi-reference.md § 响应结构说明)
- 展示结构化摘要
- 若用户要求报告文件,生成markdown报告(详见输出部分)
Query Output Template
查询输出模板
undefinedundefinedSAG Configuration: [Query Type]
SAG配置:[查询类型]
Instance: sag-xxxxx | Region: cn-shanghai | Time: 2026-05-09 14:30
实例:sag-xxxxx | 区域:cn-shanghai | 时间:2026-05-09 14:30
Results
结果
[Formatted key-value pairs or table from API response]
[从API响应中提取的格式化键值对或表格]
Notes
说明
[Any observations: version outdated, config missing, potential issues]
undefined[任何观察结果:版本过时、配置缺失、潜在问题]
undefinedModule 2: Status Inspection (状态巡检)
模块2:状态巡检
Perform comprehensive status inspections. Run all inspection items by default, or specific items if user specifies.
执行全面状态巡检。默认运行所有巡检项,或根据用户指定运行特定项。
Inspection Items
巡检项
10 项巡检项及其 API 映射见上表 Contract D — Complete Health Inspection(行 199-212)。阈值与 Green/Yellow/Red 判定逻辑详见 references/inspection-rules.md。
DropTopN availability:在主流区域(cn-shanghai/cn-hangzhou 等)可用,边缘区域(如 cn-zhangjiakou-spe)可能返回describe-sag-drop-topn,这种情况下标 "skipped due to region unsupported" 不中断全局巡检。SAG_QUERY_TOPN_ERROR返回describe-health-checks,在当前版本不可用。InvalidApi.NotFound
10项巡检项及其API映射见上文契约D — 完整健康巡检(第199-212行)。阈值与绿/黄/红判定逻辑详见references/inspection-rules.md。
DropTopN可用性:在主流区域(如cn-shanghai/cn-hangzhou)可用,边缘区域(如cn-zhangjiakou-spe)可能返回describe-sag-drop-topn,这种情况下标注"skipped due to region unsupported",不中断全局巡检。SAG_QUERY_TOPN_ERROR返回describe-health-checks,当前版本不可用。InvalidApi.NotFound
Inspection Workflow
巡检工作流
- Confirm parameters (region scope, instance scope, inspection items subset)
- Read references/status_inspection_template.py
- Modify the section to match user's requirements:
[CUSTOMIZE]- → user's workspace path
REPORT_OUTPUT_DIR - → "all" or specific region list
REGION_FILTER - → "all" or specific item numbers (1-9)
INSPECTION_ITEMS - → adjust if user specifies custom thresholds
THRESHOLDS
- Write adapted script to workspace and execute
- If script fails: read error, fix the relevant function, retry
- Present key findings in conversation + link to generated report file
- 确认参数(区域范围、实例范围、巡检项子集)
- 查看references/status_inspection_template.py
- 修改部分以匹配用户需求:
[CUSTOMIZE]- → 用户工作区路径
REPORT_OUTPUT_DIR - → "all"或特定区域列表
REGION_FILTER - → "all"或特定项编号(1-9)
INSPECTION_ITEMS - → 若用户指定自定义阈值则调整
THRESHOLDS
- 将适配后的脚本写入工作区并执行
- 若脚本失败:读取错误信息,修复相关功能后重试
- 在对话中展示关键发现 + 生成报告文件的链接
Inspection Report Template
巡检报告模板
报告需包含 Summary(Normal/Attention/Critical 项数)、Critical Issues 表、Attention Items 表、Normal Items 列表、Recommendations。详细报告模板与门阈说明见 references/inspection-rules.md。
报告需包含摘要(正常/注意/严重项数)、严重问题表、注意项表、正常项列表、建议。详细报告模板与阈值说明见references/inspection-rules.md。
Output Format
输出格式
Always provide:
- Conversation summary: Concise results directly in chat (key findings, any red/yellow items highlighted)
- Report file (when inspection or multi-item query): Generate a markdown file saved to user's workspace
始终提供:
- 对话摘要:在聊天中直接展示简洁结果(突出关键发现、任何红/黄项)
- 报告文件(巡检或多项目查询时):生成markdown文件并保存到用户工作区
Report File Generation
报告文件生成
Use a deterministic filename based on instance ID and date (overwrite if re-run same day):
python
import os
from datetime import datetime
report_content = "..." # Generated report markdown
filename = f"SAG_Inspection_{sag_id}_{datetime.now().strftime('%Y%m%d')}.md"
output_path = os.path.join(workspace_dir, filename)
with open(output_path, 'w', encoding='utf-8') as f:
f.write(report_content)基于实例ID和日期生成确定性文件名(当日重新运行时覆盖):
python
import os
from datetime import datetime
report_content = "..." # 生成的报告markdown内容
filename = f"SAG_Inspection_{sag_id}_{datetime.now().strftime('%Y%m%d')}.md"
output_path = os.path.join(workspace_dir, filename)
with open(output_path, 'w', encoding='utf-8') as f:
f.write(report_content)Data Sanitization & Consistency Rules
数据清洗与一致性规则
生成 CSV / Markdown 报告之前必须执行三项强制数据清洗与自校验(详细 jq / date / awk 脚本见 references/contract-skeletons.md § Data Sanitization):
- Null 值兜底 + 字段名探测:所有 取字段处必须加
jq兜底;带宽字段必须用 fallback 链// "N/A"(API 实际返回.Bandwidth // .BandWidth // .MaxBandwidth // "N/A",文档常误写MaxBandwidth);CCN 名称用BandWidth;禁止 CSV 出现.Name // .CcnName // "N/A"/null/空单元格(零实例区域占位行例外,必须写None)。"no instances" - 时间戳人类可读化:/
EndTime/ExpireTime等必须转CreateTime(用YYYY-MM-DD/date -r);禁止在人类可读 CSV 中保留 epoch 原始值(需要 raw 另存date -d)。*_raw.csv - 表头/明细一致性断言:Summary 声明的「共 X 个实例/X 个区域」必须与明细表实际行数严格一致;该数字必须由 /
wc -l计算得到,禁止人肉估算;报告生成后的最后一步必须运行一致性断言,不一致则 exit 1。jq length
生成CSV/Markdown报告前必须执行三项强制数据清洗与自校验(详细jq/date/awk脚本见references/contract-skeletons.md § 数据清洗):
- Null值兜底 + 字段名探测:所有取字段处必须添加
jq兜底;带宽字段必须使用兜底链// "N/A"(API实际返回.Bandwidth // .BandWidth // .MaxBandwidth // "N/A",文档常误写MaxBandwidth);CCN名称使用BandWidth;禁止CSV中出现.Name // .CcnName // "N/A"/null/空单元格(零实例区域占位行例外,必须写入None)。"no instances" - 时间戳人类可读化:/
EndTime/ExpireTime等必须转换为CreateTime格式(使用YYYY-MM-DD/date -r);禁止在人类可读CSV中保留原始时间戳(如需原始数据可另存为date -d)。*_raw.csv - 表头/明细一致性断言:摘要中声明的「共X个实例/X个区域」必须与明细表实际行数严格一致;该数字必须由/
wc -l计算得出,禁止人工估算;报告生成后的最后一步必须运行一致性断言,不一致则退出并返回码1。jq length
Error Handling
错误处理
| Error | Cause | Action |
|---|---|---|
| InvalidRegionId | Wrong region | Ask user to confirm region, list common SAG regions |
| InvalidSmartAGId.NotFound | Instance doesn't exist in this region | Try other regions or ask user to verify |
| Forbidden / NoPermission | RAM policy insufficient | Tell user which permission is needed (smartag:Describe*) |
| Throttling | API rate limit | Wait and retry with backoff |
| MissingSmartAGSn | API requires device SN but not provided | Skip - instance has no physical device bound |
| SmartAccessGatewayNotOnline | Device is offline | Record status, cannot query live device config |
| Sag.DeviceNotExist | SN mismatch or multi-SN not split | Split comma-separated SN and retry individually |
| MissingSagId | | Use |
| InvalidApi.NotFound | API may not exist in current version | Skip gracefully, note in report |
| 错误 | 原因 | 操作 |
|---|---|---|
| InvalidRegionId | 区域错误 | 请用户确认区域,列出常用SAG区域 |
| InvalidSmartAGId.NotFound | 该区域不存在此实例 | 尝试其他区域或请用户验证 |
| Forbidden / NoPermission | RAM权限不足 | 告知用户所需权限(smartag:Describe*) |
| Throttling | API速率限制 | 等待后重试并添加退避策略 |
| MissingSmartAGSn | API需要设备SN但未提供 | 跳过——实例未绑定物理设备 |
| SmartAccessGatewayNotOnline | 设备离线 | 记录状态,无法查询实时设备配置 |
| Sag.DeviceNotExist | SN不匹配或多SN未拆分 | 拆分逗号分隔的SN后逐个重试 |
| MissingSagId | | 对此API使用 |
| InvalidApi.NotFound | 当前版本不存在该API | 优雅跳过,在报告中注明 |
Best Practices
最佳实践
- Classify instances before querying — skip inapplicable APIs (sag-software has no device-level queries)
- Split multi-SN before device-level calls — passing comma-separated SN causes DeviceNotExist errors
- Region-level APIs call once per region — ACL/QoS/FlowLog/CCN are shared resources, not per-instance
- Report all failures transparently — never silently skip; always note in report what was inaccessible and why
- No field-reuse substitution — never use fields from the basic response (such as
describe-smart-access-gateways,AssociatedCcnId,AclIds) as a substitute for calling the specialized API; the basic response is a classifier, not a substituteVpnStatus - Save raw JSON to temp files — redirect CLI responses to (e.g.
/tmp/sag_*.json) and then summarize specific fields; avoid dumping full raw JSON into the conversationaliyun smartag describe-xxx ... > /tmp/sag_<api>_<region>.json 2>&1
- 查询前先分类实例 —— 跳过不适用的API(sag-software无设备级查询)
- 设备级调用前拆分多SN —— 传入逗号分隔的SN会导致DeviceNotExist错误
- 区域级API每个区域调用一次 —— ACL/QoS/FlowLog/CCN是共享资源,而非实例级资源
- 透明报告所有失败 —— 切勿静默跳过;始终在报告中注明无法访问的内容及原因
- 禁止字段复用替代 —— 切勿使用基础响应中的字段(如
describe-smart-access-gateways、AssociatedCcnId、AclIds)替代专用API调用;基础响应仅作为分类器,而非替代方案VpnStatus - 将原始JSON保存到临时文件 —— 将CLI响应重定向到(例如
/tmp/sag_*.json),然后汇总特定字段;避免将完整原始JSON输出到对话中aliyun smartag describe-xxx ... > /tmp/sag_<api>_<region>.json 2>&1
Known Unavailable APIs
已知不可用API
The following APIs are known unavailable in the current SAG API version (). You MUST NOT call them — if a scenario appears to require them, explicitly declare in the report: "API X is unavailable in the current version; skipping this item" or substitute with the alternative:
2018-03-13| API | Status | Alternative |
|---|---|---|
| Returns | Skip Item #10 of the classic inspection; note in report |
| Returns | Use |
以下API在当前SAG API版本()中已知不可用。严禁调用——若场景看似需要这些API,请在报告中明确声明:"API X在当前版本不可用;跳过此项"或使用替代方案:
2018-03-13| API | 状态 | 替代方案 |
|---|---|---|
| 返回 | 跳过经典巡检的第10项;在报告中注明 |
| 返回 | 使用 |
Reference Links
参考链接
| Reference | Description |
|---|---|
| references/openapi-reference.md | Complete OpenAPI parameter reference for 25+ SAG APIs |
| references/contract-skeletons.md | 详细 bash 骨架、Self-check、数据清洗规则(Contract A/B/C/D + Anti-Pattern + Sanitization) |
| references/ram-policies.md | Required RAM permissions (28 read-only actions) |
| 参考文档 | 描述 |
|---|---|
| references/openapi-reference.md | 25+个SAG API的完整OpenAPI参数参考 |
| references/contract-skeletons.md | 详细bash骨架、自检、数据清洗规则(契约A/B/C/D + 反模式 + 数据清洗) |
| references/ram-policies.md | 所需RAM权限(28个只读操作) |