Query SAG (Smart Access Gateway / 智能接入网关) configurations and perform status inspections via Alibaba Cloud OpenAPI. Generates inspection report files. Use when the user mentions SAG, smart access gateway, 智能接入网关, or asks to check SAG instance status, query SAG configs, inspect SAG health, troubleshoot SAG connectivity, perform SAG device inspections, 网关巡检, 查询SAG配置, SAG状态巡检, or SAG健康检查.
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)
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.
[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
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).
[MUST] Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:
Read references/ram-policies.md to get the full list of permissions required by this SKILL
Use ram-permission-diagnose skill to guide the user through requesting the necessary permissions
Pause and wait until the user confirms that the required permissions have been granted
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
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.
API Invocation Method
Aliyun CLI (Plugin Mode)
SAG plugin provides native command support with parameter validation and auto-completion:
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)
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.
Contract A — Single-Instance Full Configuration Query
Top-N packet drop statistics (use --size 10, graceful skip on SAG_QUERY_TOPN_ERROR)
11
SAG 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)
12
DNS config
describe-sag-current-dns
Active DNS servers
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)
Query Output Template
text
## SAG Configuration: [Query Type]
**Instance**: sag-xxxxx | **Region**: cn-shanghai | **Time**: 2026-05-09 14:30
### Results
[Formatted key-value pairs or table from API response]
### Notes
[Any observations: version outdated, config missing, potential issues]
Module 2: Status Inspection (状态巡检)
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,在当前版本不可用。
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
describe-dnat-entries parameter issue
Use --sag-id instead of --smart-ag-id for this API
InvalidApi.NotFound
API may not exist in current version
Skip gracefully, note in report
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 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
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
Known Unavailable APIs
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: