alibabacloud-smartag-pilot

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SAG Pilot v1.0

SAG Pilot v1.0

SAG (Smart Access Gateway / 智能接入网关) configuration query and status inspection skill. Uses aliyun CLI plugin mode.
Architecture:
SAG Device/APP → CCN → CEN → VPC
(read-only inspection, no resource modification)
SAG(Smart Access Gateway / 智能接入网关)配置查询与状态巡检技能,采用阿里云CLI插件模式。
架构:
SAG Device/APP → CCN → CEN → VPC
(只读巡检,不修改资源)

Pre-checks

前置检查

Pre-check: Aliyun CLI >= 3.3.3 required Run
aliyun version
to verify >= 3.3.3. If not installed or version too low, run
curl -fsSL https://aliyuncli.alicdn.com/setup.sh | bash
to install/update, or see
references/cli-installation-guide.md
for installation instructions.
Pre-check: SAG plugin installed and up-to-date
bash
aliyun 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):
bash
aliyun 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:
bash
aliyun configure ai-mode disable
前置检查:需Aliyun CLI >= 3.3.3 运行
aliyun version
验证版本是否 >=3.3.3。若未安装或版本过低, 运行
curl -fsSL https://aliyuncli.alicdn.com/setup.sh | bash
进行安装/更新, 或查看
references/cli-installation-guide.md
获取安装说明。
前置检查:SAG插件已安装并更新至最新版本
bash
aliyun plugin install --names aliyun-cli-smartag
aliyun plugin update
aliyun configure set --auto-plugin-install true
[必须] 启用AI模式 —— Agent Skill执行需要AI模式。 在工作流开始时(调用任何CLI命令之前):
bash
aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-smartag-pilot"
[必须] 在所有退出点禁用AI模式 —— 无论因何种原因(成功、失败、错误、取消)返回最终响应前,务必先禁用AI模式:
bash
aliyun configure ai-mode disable

Authentication

身份验证

Pre-check: Alibaba Cloud Credentials Required
Security Rules:
  • NEVER read, echo, or print AK/SK values (e.g.,
    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    is FORBIDDEN)
  • NEVER ask the user to input AK/SK directly in the conversation or command line
  • NEVER use
    aliyun configure set
    with literal credential values
  • ONLY use
    aliyun configure list
    to check credential status
bash
aliyun configure list
Check the output for a valid profile (AK, STS, or OAuth identity).
If no valid profile exists, STOP here.
  1. Obtain credentials from Alibaba Cloud Console
  2. Configure credentials outside of this session (via
    aliyun configure
    in terminal or environment variables in shell profile)
  3. Return and re-run after
    aliyun configure list
    shows a valid profile
前置检查:需阿里云凭证
安全规则:
  • 严禁读取、回显或打印AK/SK值(例如
    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    是禁止操作)
  • 严禁要求用户在对话或命令行中直接输入AK/SK
  • 严禁使用
    aliyun configure set
    传入明文凭证值
  • 仅可使用
    aliyun configure list
    检查凭证状态
bash
aliyun configure list
检查输出中是否存在有效配置文件(AK、STS或OAuth身份)。
若不存在有效配置文件,请在此处停止操作。
  1. 阿里云控制台获取凭证
  2. 本次会话外配置凭证(通过终端的
    aliyun configure
    或Shell配置文件中的环境变量)
  3. 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:
  1. Read
    references/ram-policies.md
    to get the full list of permissions required by this SKILL
  2. Use
    ram-permission-diagnose
    skill to guide the user through requesting the necessary permissions
  3. Pause and wait until the user confirms that the required permissions have been granted
本技能需要SAG只读权限。完整JSON策略请查看references/ram-policies.md
[必须] 权限失败处理: 若执行过程中任何命令或API调用因权限错误失败,请遵循以下流程:
  1. 查看
    references/ram-policies.md
    获取本技能所需的完整权限列表
  2. 使用
    ram-permission-diagnose
    技能引导用户申请必要权限
  3. 暂停操作,等待用户确认所需权限已授予

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.
ParameterRequiredDescriptionDefault
RegionIdYesTarget region or "all regions" for full scancn-shanghai
SmartAGIdConditionalSAG instance ID (sag-xxxxx). Not needed for "all instances" queries
Query ScopeYesWhich modules/functions to executeAll applicable
Output FormatOptionalConversation summary and/or report fileBoth
重要:参数确认 —— 在执行任何命令或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 15
This returns the authoritative list of all SAG-supported regions (RegionId + RegionEndpoint). Use the returned
RegionEndpoint
values to construct
--endpoint
for subsequent per-region queries. Do NOT guess or hardcode region IDs.
查询所有区域时,务必先执行:
bash
aliyun smartag describe-regions \
  --endpoint smartag.cn-shanghai.aliyuncs.com \
  --read-timeout 30 \
  --connect-timeout 15
该命令返回所有支持SAG的权威区域列表(RegionId + RegionEndpoint)。使用返回的
RegionEndpoint
值构建后续各区域查询的
--endpoint
参数。请勿猜测或硬编码区域ID。

API 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-xxxxx
Template 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:
    --endpoint smartag.<RegionId>.aliyuncs.com
    controls which regional endpoint the request is sent to (REQUIRED for cross-region queries)
  • Business region:
    --biz-region-id
    is the API's RegionId parameter
  • IMPORTANT: Must use
    --endpoint
    (not
    --region
    ) for endpoint routing — the plugin's
    --region
    mapping is incomplete and fails for eu-west-1, us-east-1, cn-zhangjiakou-spe
  • Special:
    describe-regions
    only needs
    --endpoint
    (no
    --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-gateways
    describe-sag-wan-4g
  • 参数:使用短横线分隔的小写格式,例如
    --smart-ag-id
    --smart-ag-sn
    --page-size
  • 端点路由:
    --endpoint smartag.<RegionId>.aliyuncs.com
    控制请求发送到哪个区域端点(跨区域查询必须设置)
  • 业务区域:
    --biz-region-id
    是API的RegionId参数
  • 重要提示:必须使用
    --endpoint
    而非
    --region
    进行端点路由——插件的
    --region
    映射不完整,在eu-west-1、us-east-1、cn-zhangjiakou-spe等区域会失效
  • 特殊情况:
    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
describe-smart-access-gateways
response.
以下为硬性要求——对于下方每个场景,必须严格调用列出的完整API集合。不得通过复用
describe-smart-access-gateways
响应中的字段来替代专用API调用。

Contract A — Single-Instance Full Configuration Query

契约A — 单实例完整配置查询

Trigger: 用户针对具体某个
sag-xxx
实例
询问配置(含「这个网关的配置」「看一下 xxx 的配置」「完整配置」「全部配置」「WAN/路由/DNAT 都查」「换网后对一下配置」「配置有没有问题」「检查 xxx 配置」等;即使夹带「巡检/诊断/检查」字样仍属本场景,⛔ 严禁误用 Contract D)。
You MUST call all 12 APIs below (skip device-level ones only if the instance is
sag-software
— see Contract C):
#APINotes
A1
describe-smart-access-gateways
Instance basic info + classification
A2
describe-smart-access-gateway-attribute
VPN status + detailed attributes
A3
describe-sag-device-info
Device-level, needs
--smart-ag-sn
A4
describe-sag-wan-list
Device-level, needs
--smart-ag-sn
A5
describe-sag-static-route-list
Static routes
A6
describe-sag-route-list
Full route table
A7
describe-dnat-entries
MUST use
--sag-id
(NOT
--smart-ag-id
)
A8
describe-snat-entries
Uses
--smart-ag-id
A9
describe-cloud-connect-networks
CCN (region-level)
A10
describe-acls
ACL (region-level)
A11
describe-qoses
QoS (region-level)
A12
describe-sag-current-dns
Device-level, needs
--smart-ag-sn
Contract A — 关键规则要点(详细 12-line bash 骨架与 Self-check 断言见 references/contract-skeletons.md § Contract A
  1. 参数强绑定:A3/A4/A12 用
    --smart-ag-sn $SN
    (SN 来自 A1
    SerialNumber
    ,逗号分隔时拆分逐 SN 调用;为空或 sag-software 则跳过 A3/A4/A12 走 Contract C);A5/A6 用
    --smart-ag-id
    ;A7
    describe-dnat-entries
    --sag-id
    (注意与 A8 不同);A9/A10/A11 仅
    --biz-region-id
  2. 参数错误恢复:CLI 报错
    Error: --smart-ag-sn is required
    --smart-ag-id is required
    时必须对照 A1-A12 参数表立即修正后重试 2 次;❗严禁将 CLI 参数错误误归为 VPN 故障 / 网络异常 / 实例不存在而跳过该 API。
  3. No-Chaining:❌ 严禁用
    &&
    /
    ;
    /
    ||
    /
    |
    拼接命令;每条 API 必须独立成行、独立重定向到
    /tmp/sag_a*.json
    、独立捕获 exit code。失败时单条重试 2 次(间隔 500ms),重试仍失败标
    FAILED:
    继续执行后续,禁止 abort。禁止
    set -e
  4. Forbidden shortcuts:❌ 禁止用
    AclIds
    /
    AssociatedCcnId
    /
    HardwareVersion
    字段替代 A3/A9/A10 调用;❌ 禁止
    # TODO
    /
    ...
    占位略过任何一条;❌ 禁止把
    --smart-ag-sn
    错写为
    --smart-ag-id
  5. 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
触发条件:用户针对具体某个
sag-xxx
实例
询问配置(含「这个网关的配置」「看一下xxx的配置」「完整配置」「全部配置」「WAN/路由/DNAT都查」「换网后对一下配置」「配置有没有问题」「检查xxx配置」等;即使夹带「巡检/诊断/检查」字样仍属于本场景,⛔ 严禁误用契约D)。
必须调用以下全部12个API(仅当实例为
sag-software
时跳过设备级API,详见契约C):
序号API说明
A1
describe-smart-access-gateways
实例基本信息 + 分类
A2
describe-smart-access-gateway-attribute
VPN状态 + 详细属性
A3
describe-sag-device-info
设备级API,需要
--smart-ag-sn
参数
A4
describe-sag-wan-list
设备级API,需要
--smart-ag-sn
参数
A5
describe-sag-static-route-list
静态路由
A6
describe-sag-route-list
完整路由表
A7
describe-dnat-entries
必须使用
--sag-id
(不可用
--smart-ag-id
A8
describe-snat-entries
使用
--smart-ag-id
参数
A9
describe-cloud-connect-networks
CCN(区域级)
A10
describe-acls
ACL(区域级)
A11
describe-qoses
QoS(区域级)
A12
describe-sag-current-dns
设备级API,需要
--smart-ag-sn
参数
契约A — 关键规则要点(详细12行bash骨架与自检断言见references/contract-skeletons.md § 契约A
  1. 参数强绑定:A3/A4/A12使用
    --smart-ag-sn $SN
    (SN来自A1的
    SerialNumber
    ,逗号分隔时需拆分后逐个SN调用;若SN为空或实例为sag-software则跳过A3/A4/A12,遵循契约C);A5/A6使用
    --smart-ag-id
    ;A7的
    describe-dnat-entries
    使用**
    --sag-id
    **(注意与A8不同);A9/A10/A11仅需
    --biz-region-id
  2. 参数错误恢复:若CLI报错
    Error: --smart-ag-sn is required
    --smart-ag-id is required
    ,必须对照A1-A12参数表立即修正后重试2次;❗严禁将CLI参数错误误判为VPN故障/网络异常/实例不存在而跳过该API。
  3. 禁止链式调用:❌ 严禁使用
    &&
    /
    ;
    /
    ||
    /
    |
    拼接命令;每条API必须独立成行、独立重定向到
    /tmp/sag_a*.json
    、独立捕获退出码。失败时单条重试2次(间隔500ms),重试仍失败则标记
    FAILED:
    继续执行后续命令,禁止终止流程。禁止使用
    set -e
  4. 禁止捷径操作:❌ 禁止用
    AclIds
    /
    AssociatedCcnId
    /
    HardwareVersion
    字段替代A3/A9/A10的调用;❌ 禁止用
    # TODO
    /
    ...
    占位跳过任何一条API;❌ 禁止将
    --smart-ag-sn
    误写为
    --smart-ag-id
  5. 自检: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.json

Contract B — Multi-Region Asset Inventory

契约B — 多区域资产盘点

Trigger: user asks for inventory across regions (e.g. "资产盘点", "全部区域", "所有地域", "region discovery").
You MUST:
  1. Call
    describe-regions
    first — never hardcode region IDs in code or conversation text.
  2. Iterate the returned regions via a variable (
    for region in ...
    ) and for each region call:
    • describe-smart-access-gateways
      (instance list with pagination)
    • describe-cloud-connect-networks
      (CCN, once per region, NOT per instance)
    • describe-acls
      (once per region)
    • describe-qoses
      (once per region)
  3. 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
  1. Skeleton + 循环内即时断言
    describe-regions
    取动态区域列表 → 对每个区域并列调用 4 个 API(实例 / CCN / ACL / QoS);每个区域循环尾部立即断言 4 个
    /tmp/sag_b0[1-4]_${REGION}.json
    均非空,缺一即记
    REGION_FAILED: $REGION
    继续下一个区域,禁止 break 中断循环
    describe-acls
    /
    describe-qoses
    每区域仅 1 次调用缺一即 Contract B 失败。
  2. Data Collection Order:✅ for 循环内仅把 raw JSON 落盘到
    /tmp/sag_*_${REGION}.json
    ;✅ 循环结束后再统一
    jq
    聚合 + 写最终 CSV;❌ 严禁边查边
    >> file.csv
    追加。
  3. 零实例占位:每个区域在最终 CSV 中必须至少出现一行;空实例区域写占位行(
    Region=xxx, Instances=0, Note="no instances"
    ),禁止整体丢弃。
  4. 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」)。
必须执行:
  1. 先调用
    describe-regions
    ——切勿在代码或对话文本中硬编码区域ID。
  2. 通过变量遍历返回的区域(
    for region in ...
    ),并对每个区域调用:
    • describe-smart-access-gateways
      (带分页的实例列表)
    • describe-cloud-connect-networks
      (CCN,每个区域调用一次,而非每个实例)
    • describe-acls
      每个区域调用一次
    • describe-qoses
      每个区域调用一次
  3. 在报告中,使用DescribeRegions响应中的变量指代区域——请勿在注释中直接拼写区域ID字面量。
契约B — 关键规则要点(详细区域循环bash骨架与自检断言见references/contract-skeletons.md § 契约B
  1. 骨架 + 循环内即时断言:通过
    describe-regions
    获取动态区域列表 → 对每个区域并行调用4个API(实例/CCN/ACL/QoS);每个区域循环末尾立即断言4个
    /tmp/sag_b0[1-4]_${REGION}.json
    文件均非空,缺失任一文件则标记
    REGION_FAILED: $REGION
    并继续下一个区域,禁止中断循环
    describe-acls
    /
    describe-qoses
    每个区域仅调用一次,缺失任一调用则契约B执行失败。
  2. 数据收集顺序:✅ 循环内仅将原始JSON写入
    /tmp/sag_*_${REGION}.json
    ;✅ 循环结束后再统一用
    jq
    聚合并写入最终CSV;❌ 严禁边查询边用
    >> file.csv
    追加内容。
  3. 零实例占位:每个区域在最终CSV中必须至少有一行;无实例的区域需写入占位行(
    Region=xxx, Instances=0, Note="no instances"
    ),禁止直接丢弃该区域数据。
  4. 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
done

Contract C — sag-software Client Query (skip device-level)

契约C — sag-software客户端查询(跳过设备级API)

Trigger:
HardwareVersion == "sag-software"
(software APP client, no physical device).
You MUST:
  1. Call
    describe-smart-access-gateway-client-users
    (APP user list — Item #11).
  2. Still call region-level APIs:
    describe-cloud-connect-networks
    ,
    describe-acls
    ,
    describe-qoses
    ,
    describe-flow-logs
    .
  3. 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
    .
  4. Do NOT pass
    --smart-ag-sn
    on any call (the SN field is empty for sag-software).
Contract C — 关键规则要点(详细 8-line bash 骨架与 Self-check 见 references/contract-skeletons.md § Contract C
  • 8 条 API 调用骨架包含
    describe-flow-logs
    describe-sag-route-list
    ,缺一即 Contract C 失败。
  • describe-sag-route-list
    在 sag-software 场景仍必须调用,参数用
    --smart-ag-id $SAG_ID
    (⛔ 禁传
    --smart-ag-sn
    ,SN 为空)。
  • No-Chaining:8 条独立执行,禁止
    &&
    /
    ;
    /
    ||
    拼接。
  • Self-check:所有产物文件非空 + 无
    not a valid api
    错误(PascalCase 检测)。
触发条件:
HardwareVersion == "sag-software"
(软件APP客户端,无物理设备)。
必须执行:
  1. 调用
    describe-smart-access-gateway-client-users
    (APP用户列表——第11项)。
  2. 仍需调用区域级API:
    describe-cloud-connect-networks
    describe-acls
    describe-qoses
    describe-flow-logs
  3. 跳过所有设备级API
    describe-sag-device-info
    describe-sag-wan-list
    describe-sag-static-route-list
    describe-dnat-entries
    describe-snat-entries
    describe-sag-current-dns
  4. 任何调用中不得传入
    --smart-ag-sn
    参数
    (sag-software的SN字段为空)。
契约C — 关键规则要点(详细8行bash骨架与自检见references/contract-skeletons.md § 契约C
  • 8条API调用骨架包含
    describe-flow-logs
    describe-sag-route-list
    ,缺失任一调用则契约C执行失败。
  • 在sag-software场景下仍必须调用
    describe-sag-route-list
    ,参数使用
    --smart-ag-id $SAG_ID
    (⛔ 禁止传入
    --smart-ag-sn
    ,SN为空)。
  • 禁止链式调用:8条命令独立执行,禁止使用
    &&
    /
    ;
    /
    ||
    拼接。
  • 自检:所有产物文件非空 + 无
    not a valid api
    错误(检测是否误用PascalCase格式)。

Contract D — Complete Health Inspection (10 items)

契约D — 完整健康巡检(10项)

Trigger: 用户未指定具体实例而要求账号级/批量「完整巡检」「10 项巡检」「健康巡检」「全套巡检」;⛔ 用户问具体
sag-xxx
实例配置(即使含「诊断/对一下/检查」字样)一律走 Contract A 12-line,禁用本契约
Contract 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 FlowLog
Do NOT call
describe-health-checks
(returns
InvalidApi.NotFound
— see Known Unavailable APIs).
关键规则
  1. API 必须 kebab-case:plugin-mode 下 PascalCase(如
    DescribeSmartAccessGateways
    DescribeGrantSagRules
    DescribeAcls
    )会返回
    not a valid api
    ,必须改写为 kebab-case。
  2. 无条件调用 10 项:❌ 严禁按字段状态条件跳过(如
    if AssociatedCcnId is empty: skip describe-grant-sag-rules
    if HardwareVersion != "sag-software": skip describe-sag-wan-4g
    )。
  3. 唯一 graceful skip 例外
    describe-sag-drop-topn
    SAG_QUERY_TOPN_ERROR
    可跳过该项,但调用动作必须发生,不能预判跳过。
  4. Self-check:脚本末尾必须断言 10 个
    /tmp/sag_d*.json
    产物文件均存在,且
    grep 'not a valid api' /tmp/sag_d*.json
    无命中。
触发条件:用户未指定具体实例而要求账号级/批量「完整巡检」「10项巡检」「健康巡检」「全套巡检」;⛔ 用户询问具体
sag-xxx
实例配置(即使含「诊断/对一下/检查」字样)一律遵循契约A的12行骨架,禁用本契约
契约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 流量日志
请勿调用
describe-health-checks
(会返回
InvalidApi.NotFound
——详见已知不可用API)。
关键规则
  1. API必须使用kebab-case格式:插件模式下使用PascalCase格式(如
    DescribeSmartAccessGateways
    DescribeGrantSagRules
    DescribeAcls
    )会返回
    not a valid api
    ,必须改为kebab-case格式。
  2. 无条件调用10项API:❌ 严禁根据字段状态条件跳过(例如
    if AssociatedCcnId为空: 跳过describe-grant-sag-rules
    if HardwareVersion != "sag-software": 跳过describe-sag-wan-4g
    )。
  3. 唯一可优雅跳过的例外
    describe-sag-drop-topn
    SAG_QUERY_TOPN_ERROR
    可跳过该项,但必须执行调用动作,不能预先判断跳过。
  4. 自检:脚本末尾必须断言10个
    /tmp/sag_d*.json
    产物文件均存在,且
    grep 'not a valid api' /tmp/sag_d*.json
    无匹配结果。

Anti-Pattern: Field-Reuse Substitution

反模式:字段复用替代

NEVER use the response of
describe-smart-access-gateways
as a substitute for specialized API calls:
If you need …❌ Don't use✅ Must call
VPN tunnel state
Status
from basic info
describe-smart-access-gateway-attribute
VpnStatus
CCN binding details
AssociatedCcnId
field
describe-cloud-connect-networks
ACL bound to instance
AclIds
field
describe-acls
QoS policies(no such field)
describe-qoses
Device hardware
HardwareVersion
alone
describe-sag-device-info
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
  1. ✅ 失败必须在报告中标注
    FAILED: <错误原因>
    SKIPPED: <跳过原因>
  2. ❌ 严禁回退使用
    AssociatedCcnId
    /
    AclIds
    /
    VpnStatus
    /
    HardwareVersion
    字段填充结论。
  3. ❌ 严禁静默跳过;必须在报告中保留该项的状态位。
  4. ✅ kebab-case/PascalCase 误用必须重新调用修正后的命令,不可跳过。
违反任意一条(尤其第 2 条字段回退)直接判为 Anti-Pattern 触发,评测会认为契约失败。
严禁使用
describe-smart-access-gateways
的响应替代专用API调用:
若需获取…❌ 请勿使用✅ 必须调用
VPN隧道状态基础信息中的
Status
字段
describe-smart-access-gateway-attribute
VpnStatus
CCN绑定详情
AssociatedCcnId
字段
describe-cloud-connect-networks
实例绑定的ACL
AclIds
字段
describe-acls
QoS策略(无对应字段)
describe-qoses
设备硬件信息
HardwareVersion
字段
describe-sag-device-info
基础信息响应仅作为分类器(决定下一步调用哪些API),而非替代方案(跳过某些API调用)。
执行阻塞规则(专用API调用失败时的处理闸门,详见contract-skeletons.md § 反模式
  1. ✅ 失败必须在报告中标注
    FAILED: <错误原因>
    SKIPPED: <跳过原因>
  2. ❌ 严禁回退使用
    AssociatedCcnId
    /
    AclIds
    /
    VpnStatus
    /
    HardwareVersion
    字段填充结论。
  3. ❌ 严禁静默跳过;必须在报告中保留该项的状态位。
  4. ✅ kebab-case/PascalCase误用必须重新调用修正后的命令,不可跳过。
违反任意一条(尤其第2条字段回退)直接判定为反模式触发,评测会视为契约执行失败。

Mandatory Self-check Template(Contract A/B/C/D 共用,必须直接粘贴到脚本末尾)

强制自检模板(契约A/B/C/D共用,必须直接粘贴到脚本末尾)

bash
undefined
bash
undefined

1. 所有 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:
#Functionsag-1000/100wm (有SN)sag-1000/100wm (无SN)sag-software
1Instance info
2Device hardware
3WAN config
4Routing
5CCN/CEN bindings
6ACL rules✅ (region)✅ (region)✅ (region)
7QoS policies✅ (region)✅ (region)✅ (region)
8DNAT/SNAT
9Flow logs✅ (region)✅ (region)✅ (region)
10Packet drop (DropTopN)✅ (region)
11SAG APP clients
12DNS config
判断逻辑:
  • HardwareVersion == "sag-software"
    → 软件客户端,仅查 #1, #5, #6, #7, #9, #11(即 Contract C),禁止传
    --smart-ag-sn
  • SerialNumber
    为空 → 硬件设备未绑定,跳过 #2, #3, #4, #12
  • 用户请求“完整配置”或已确定单实例 → 需调用 Contract A 列出的 12 个 API(其中 device-level 按上述规则规避)
  • describe-health-checks
    在 2018-03-13 版本返回 InvalidApi.NotFound,当前不可用,请在报告中显式标注 skipped
  • describe-sag-drop-topn
    在主流区域(cn-shanghai/cn-hangzhou 等)可用,在边缘区域(如 cn-zhangjiakou-spe)可能返回 SAG_QUERY_TOPN_ERROR,这种情况下以 region unsupported 的形式跳过单项,不中断全局巡检
并非所有查询适用于所有实例类型。必须跳过不适用的查询,避免无效API调用:
序号功能sag-1000/100wm (有SN)sag-1000/100wm (无SN)sag-software
1实例信息
2设备硬件
3WAN配置
4路由
5CCN/CEN绑定
6ACL规则✅ (区域级)✅ (区域级)✅ (区域级)
7QoS策略✅ (区域级)✅ (区域级)✅ (区域级)
8DNAT/SNAT
9流量日志✅ (区域级)✅ (区域级)✅ (区域级)
10丢包统计(DropTopN)✅ (区域级)
11SAG APP客户端
12DNS配置
判断逻辑:
  • HardwareVersion == "sag-software"
    → 软件客户端,仅查询#1、#5、#6、#7、#9、#11(即契约C),禁止传入
    --smart-ag-sn
  • SerialNumber
    为空 → 硬件设备未绑定,跳过#2、#3、#4、#12
  • 用户请求“完整配置”或已确定单实例 → 需调用契约A列出的12个API(其中设备级API按上述规则规避)
  • describe-health-checks
    在2018-03-13版本返回InvalidApi.NotFound,当前不可用,请在报告中显式标注skipped
  • describe-sag-drop-topn
    在主流区域(如cn-shanghai/cn-hangzhou)可用,在边缘区域(如cn-zhangjiakou-spe)可能返回SAG_QUERY_TOPN_ERROR,这种情况下以region unsupported的形式跳过该项,不中断全局巡检

Multi-SN Handling & Parameter Pre-check

多SN处理与参数预检

Scope: 仅适用于 Contract A 硬件设备场景;Contract C (sag-software) 场景禁用本段的
--smart-ag-sn
传参(会触发 forbidden 规则)。
部分实例有主备双设备,
SerialNumber
字段为逗号分隔(如
sag61dacczh,sag61daccq6
)。处理规则:
  1. 参数预检:调用 A3/A4/A12 前必须先
    SN=$(jq -r '.SmartAccessGateways.SmartAccessGateway[0].SerialNumber // ""' /tmp/sag_a01.json)
    ,若
    [ -z "$SN" ]
    则显式
    echo "SKIPPED: no_sn"
    并写空 JSON 占位
    echo '{}' > /tmp/sag_a03.json
    严禁因
    --smart-ag-sn is required
    报错中断
    后续 API 调用。
  2. 检测 SN 中是否包含逗号;多 SN 时拆分后对每个 SN 分别调用设备级 API(#2, #3, #4, #12)。
  3. 报告中按"主设备 / 备设备"分别展示结果。
适用范围:仅适用于契约A的硬件设备场景;契约C(sag-software)场景禁用本段的
--smart-ag-sn
传参(会触发禁止规则)。
部分实例有主备双设备,
SerialNumber
字段为逗号分隔(如
sag61dacczh,sag61daccq6
)。处理规则:
  1. 参数预检:调用A3/A4/A12前必须先执行
    SN=$(jq -r '.SmartAccessGateways.SmartAccessGateway[0].SerialNumber // ""' /tmp/sag_a01.json)
    ,若
    [ -z "$SN" ]
    则显式
    echo "SKIPPED: no_sn"
    并写入空JSON占位
    echo '{}' > /tmp/sag_a03.json
    严禁因
    --smart-ag-sn is required
    报错中断
    后续API调用。
  2. 检测SN中是否包含逗号;多SN时拆分后对每个SN分别调用设备级API(#2、#3、#4、#12)。
  3. 报告中按“主设备 / 备设备”分别展示结果。

Available Query Functions

可用查询功能

#FunctionAPIKey Output
1Instance info
describe-smart-access-gateways
/
describe-smart-access-gateway-attribute
Status, bandwidth, expiry, CCN/CEN bindings, device SN
2Device hardware
describe-sag-device-info
/
describe-smart-access-gateway-versions
Model, software version, latest version, 4G status
3WAN config
describe-sag-wan-list
/
describe-sag-wan-4g
WAN IP/gateway/DNS, 4G signal status
4Routing
describe-sag-static-route-list
/
describe-sag-route-list
/
describe-sag-route-protocol-bgp
/
describe-sag-route-protocol-ospf
Static routes, BGP/OSPF config, route table
5CCN/CEN bindings
describe-cloud-connect-networks
/
describe-grant-sag-rules
/
describe-sag-vbr-relations
CCN info, CEN authorization, VBR relations
6ACL rules
describe-acls
+ rule queries
Rules: src/dst IP, port, protocol, action
7QoS policies
describe-qoses
+ rule queries
Rate limits (CIR/PIR), traffic classifiers
8DNAT/SNAT
describe-dnat-entries
/
describe-snat-entries
Port mapping, address translation rules
9Flow logs
describe-flow-logs
Status, SLS project, bound instances
10Packet drop
describe-sag-drop-topn
Top-N packet drop statistics (use
--size 10
, graceful skip on
SAG_QUERY_TOPN_ERROR
)
11SAG APP clients
describe-smart-access-gateway-client-users
APP user list, client type, bandwidth quota (
describe-sag-online-client-statistics
is deprecated — do not call)
12DNS config
describe-sag-current-dns
Active DNS servers
序号功能API关键输出
1实例信息
describe-smart-access-gateways
/
describe-smart-access-gateway-attribute
状态、带宽、到期时间、CCN/CEN绑定、设备SN
2设备硬件
describe-sag-device-info
/
describe-smart-access-gateway-versions
型号、软件版本、最新版本、4G状态
3WAN配置
describe-sag-wan-list
/
describe-sag-wan-4g
WAN IP/网关/DNS、4G信号状态
4路由
describe-sag-static-route-list
/
describe-sag-route-list
/
describe-sag-route-protocol-bgp
/
describe-sag-route-protocol-ospf
静态路由、BGP/OSPF配置、路由表
5CCN/CEN绑定
describe-cloud-connect-networks
/
describe-grant-sag-rules
/
describe-sag-vbr-relations
CCN信息、CEN授权、VBR关联关系
6ACL规则
describe-acls
+ 规则查询
规则:源/目的IP、端口、协议、动作
7QoS策略
describe-qoses
+ 规则查询
速率限制(CIR/PIR)、流量分类器
8DNAT/SNAT
describe-dnat-entries
/
describe-snat-entries
端口映射、地址转换规则
9流量日志
describe-flow-logs
状态、SLS项目、绑定实例
10丢包统计
describe-sag-drop-topn
Top-N丢包统计(使用
--size 10
,遇
SAG_QUERY_TOPN_ERROR
可优雅跳过)
11SAG APP客户端
describe-smart-access-gateway-client-users
APP用户列表、客户端类型、带宽配额(
describe-sag-online-client-statistics
已废弃——请勿调用)
12DNS配置
describe-sag-current-dns
活跃DNS服务器

Query Workflow

查询工作流

  1. Identify which config the user wants to query
  2. Confirm RegionId and SmartAGId (ask if not provided)
  3. Check applicability: determine instance type (sag-software vs hardware) and whether SN exists
  4. Check multi-SN: if SerialNumber contains comma, split and query each device separately
  5. Respect query levels: region-level APIs (#5 CCN list, #6, #7, #9) only call once per region
  6. Call the corresponding API via CLI
  7. Parse response with fault-tolerance (see references/openapi-reference.md § Response Structure Notes)
  8. Present structured summary
  9. If user requests a report file, generate markdown report (see Output section)
  1. 识别用户需要查询的配置类型
  2. 确认RegionId和SmartAGId(未提供则询问用户)
  3. 检查适用性:确定实例类型(sag-software vs 硬件)以及是否存在SN
  4. 检查多SN:若SerialNumber包含逗号,拆分后分别查询每个设备
  5. 遵循查询层级:区域级API(#5 CCN列表、#6、#7、#9)仅每个区域调用一次
  6. 通过CLI调用对应API
  7. 容错解析响应(详见references/openapi-reference.md § 响应结构说明)
  8. 展示结构化摘要
  9. 若用户要求报告文件,生成markdown报告(详见输出部分)

Query Output Template

查询输出模板

undefined
undefined

SAG 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
[任何观察结果:版本过时、配置缺失、潜在问题]
undefined

Module 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:
describe-sag-drop-topn
在主流区域(cn-shanghai/cn-hangzhou 等)可用,边缘区域(如 cn-zhangjiakou-spe)可能返回
SAG_QUERY_TOPN_ERROR
,这种情况下标 "skipped due to region unsupported" 不中断全局巡检。
describe-health-checks
返回
InvalidApi.NotFound
,在当前版本不可用。
10项巡检项及其API映射见上文契约D — 完整健康巡检(第199-212行)。阈值与绿/黄/红判定逻辑详见references/inspection-rules.md
DropTopN可用性
describe-sag-drop-topn
在主流区域(如cn-shanghai/cn-hangzhou)可用,边缘区域(如cn-zhangjiakou-spe)可能返回
SAG_QUERY_TOPN_ERROR
,这种情况下标注"skipped due to region unsupported",不中断全局巡检。
describe-health-checks
返回
InvalidApi.NotFound
,当前版本不可用。

Inspection Workflow

巡检工作流

  1. Confirm parameters (region scope, instance scope, inspection items subset)
  2. Read references/status_inspection_template.py
  3. Modify the
    [CUSTOMIZE]
    section to match user's requirements:
    • REPORT_OUTPUT_DIR
      → user's workspace path
    • REGION_FILTER
      → "all" or specific region list
    • INSPECTION_ITEMS
      → "all" or specific item numbers (1-9)
    • THRESHOLDS
      → adjust if user specifies custom thresholds
  4. Write adapted script to workspace and execute
  5. If script fails: read error, fix the relevant function, retry
  6. Present key findings in conversation + link to generated report file
  1. 确认参数(区域范围、实例范围、巡检项子集)
  2. 查看references/status_inspection_template.py
  3. 修改
    [CUSTOMIZE]
    部分以匹配用户需求:
    • REPORT_OUTPUT_DIR
      → 用户工作区路径
    • REGION_FILTER
      → "all"或特定区域列表
    • INSPECTION_ITEMS
      → "all"或特定项编号(1-9)
    • THRESHOLDS
      → 若用户指定自定义阈值则调整
  4. 将适配后的脚本写入工作区并执行
  5. 若脚本失败:读取错误信息,修复相关功能后重试
  6. 在对话中展示关键发现 + 生成报告文件的链接

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:
  1. Conversation summary: Concise results directly in chat (key findings, any red/yellow items highlighted)
  2. Report file (when inspection or multi-item query): Generate a markdown file saved to user's workspace
始终提供:
  1. 对话摘要:在聊天中直接展示简洁结果(突出关键发现、任何红/黄项)
  2. 报告文件(巡检或多项目查询时):生成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):
  1. Null 值兜底 + 字段名探测:所有
    jq
    取字段处必须加
    // "N/A"
    兜底;带宽字段必须用 fallback 链
    .Bandwidth // .BandWidth // .MaxBandwidth // "N/A"
    (API 实际返回
    MaxBandwidth
    ,文档常误写
    BandWidth
    );CCN 名称用
    .Name // .CcnName // "N/A"
    ;禁止 CSV 出现
    null
    /
    None
    /空单元格(零实例区域占位行例外,必须写
    "no instances"
    )。
  2. 时间戳人类可读化
    EndTime
    /
    ExpireTime
    /
    CreateTime
    等必须转
    YYYY-MM-DD
    (用
    date -r
    /
    date -d
    );禁止在人类可读 CSV 中保留 epoch 原始值(需要 raw 另存
    *_raw.csv
    )。
  3. 表头/明细一致性断言:Summary 声明的「共 X 个实例/X 个区域」必须与明细表实际行数严格一致;该数字必须由
    wc -l
    /
    jq length
    计算得到,禁止人肉估算;报告生成后的最后一步必须运行一致性断言,不一致则 exit 1。
生成CSV/Markdown报告前必须执行三项强制数据清洗与自校验(详细jq/date/awk脚本见references/contract-skeletons.md § 数据清洗):
  1. Null值兜底 + 字段名探测:所有
    jq
    取字段处必须添加
    // "N/A"
    兜底;带宽字段必须使用兜底链
    .Bandwidth // .BandWidth // .MaxBandwidth // "N/A"
    (API实际返回
    MaxBandwidth
    ,文档常误写
    BandWidth
    );CCN名称使用
    .Name // .CcnName // "N/A"
    ;禁止CSV中出现
    null
    /
    None
    /空单元格(零实例区域占位行例外,必须写入
    "no instances"
    )。
  2. 时间戳人类可读化
    EndTime
    /
    ExpireTime
    /
    CreateTime
    等必须转换为
    YYYY-MM-DD
    格式(使用
    date -r
    /
    date -d
    );禁止在人类可读CSV中保留原始时间戳(如需原始数据可另存为
    *_raw.csv
    )。
  3. 表头/明细一致性断言:摘要中声明的「共X个实例/X个区域」必须与明细表实际行数严格一致;该数字必须由
    wc -l
    /
    jq length
    计算得出,禁止人工估算;报告生成后的最后一步必须运行一致性断言,不一致则退出并返回码1。

Error Handling

错误处理

ErrorCauseAction
InvalidRegionIdWrong regionAsk user to confirm region, list common SAG regions
InvalidSmartAGId.NotFoundInstance doesn't exist in this regionTry other regions or ask user to verify
Forbidden / NoPermissionRAM policy insufficientTell user which permission is needed (smartag:Describe*)
ThrottlingAPI rate limitWait and retry with backoff
MissingSmartAGSnAPI requires device SN but not providedSkip - instance has no physical device bound
SmartAccessGatewayNotOnlineDevice is offlineRecord status, cannot query live device config
Sag.DeviceNotExistSN mismatch or multi-SN not splitSplit comma-separated SN and retry individually
MissingSagId
describe-dnat-entries
parameter issue
Use
--sag-id
instead of
--smart-ag-id
for this API
InvalidApi.NotFoundAPI may not exist in current versionSkip gracefully, note in report
错误原因操作
InvalidRegionId区域错误请用户确认区域,列出常用SAG区域
InvalidSmartAGId.NotFound该区域不存在此实例尝试其他区域或请用户验证
Forbidden / NoPermissionRAM权限不足告知用户所需权限(smartag:Describe*)
ThrottlingAPI速率限制等待后重试并添加退避策略
MissingSmartAGSnAPI需要设备SN但未提供跳过——实例未绑定物理设备
SmartAccessGatewayNotOnline设备离线记录状态,无法查询实时设备配置
Sag.DeviceNotExistSN不匹配或多SN未拆分拆分逗号分隔的SN后逐个重试
MissingSagId
describe-dnat-entries
参数问题
对此API使用
--sag-id
而非
--smart-ag-id
InvalidApi.NotFound当前版本不存在该API优雅跳过,在报告中注明

Best Practices

最佳实践

  1. Classify instances before querying — skip inapplicable APIs (sag-software has no device-level queries)
  2. Split multi-SN before device-level calls — passing comma-separated SN causes DeviceNotExist errors
  3. Region-level APIs call once per region — ACL/QoS/FlowLog/CCN are shared resources, not per-instance
  4. Report all failures transparently — never silently skip; always note in report what was inaccessible and why
  5. No field-reuse substitution — never use fields from the basic
    describe-smart-access-gateways
    response (such as
    AssociatedCcnId
    ,
    AclIds
    ,
    VpnStatus
    ) as a substitute for calling the specialized API; the basic response is a classifier, not a substitute
  6. Save raw JSON to temp files — redirect CLI responses to
    /tmp/sag_*.json
    (e.g.
    aliyun smartag describe-xxx ... > /tmp/sag_<api>_<region>.json 2>&1
    ) and then summarize specific fields; avoid dumping full raw JSON into the conversation
  1. 查询前先分类实例 —— 跳过不适用的API(sag-software无设备级查询)
  2. 设备级调用前拆分多SN —— 传入逗号分隔的SN会导致DeviceNotExist错误
  3. 区域级API每个区域调用一次 —— ACL/QoS/FlowLog/CCN是共享资源,而非实例级资源
  4. 透明报告所有失败 —— 切勿静默跳过;始终在报告中注明无法访问的内容及原因
  5. 禁止字段复用替代 —— 切勿使用基础
    describe-smart-access-gateways
    响应中的字段(如
    AssociatedCcnId
    AclIds
    VpnStatus
    )替代专用API调用;基础响应仅作为分类器,而非替代方案
  6. 将原始JSON保存到临时文件 —— 将CLI响应重定向到
    /tmp/sag_*.json
    (例如
    aliyun smartag describe-xxx ... > /tmp/sag_<api>_<region>.json 2>&1
    ),然后汇总特定字段;避免将完整原始JSON输出到对话中

Known Unavailable APIs

已知不可用API

The following APIs are known unavailable in the current SAG API version (
2018-03-13
). 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:
APIStatusAlternative
describe-health-checks
/
describe-health-check-attribute
Returns
InvalidApi.NotFound
Skip Item #10 of the classic inspection; note in report
describe-sag-online-client-statistics
Returns
InvalidApi.NotFound
Use
describe-smart-access-gateway-client-users
for APP user list
以下API在当前SAG API版本(
2018-03-13
)中已知不可用。严禁调用——若场景看似需要这些API,请在报告中明确声明:"API X在当前版本不可用;跳过此项"或使用替代方案:
API状态替代方案
describe-health-checks
/
describe-health-check-attribute
返回
InvalidApi.NotFound
跳过经典巡检的第10项;在报告中注明
describe-sag-online-client-statistics
返回
InvalidApi.NotFound
使用
describe-smart-access-gateway-client-users
获取APP用户列表

Reference Links

参考链接

ReferenceDescription
references/openapi-reference.mdComplete 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.mdRequired RAM permissions (28 read-only actions)
参考文档描述
references/openapi-reference.md25+个SAG API的完整OpenAPI参数参考
references/contract-skeletons.md详细bash骨架、自检、数据清洗规则(契约A/B/C/D + 反模式 + 数据清洗)
references/ram-policies.md所需RAM权限(28个只读操作)