← 返回 Skills 市场
sdk-team

Alibabacloud Sls Query

作者 alibabacloud-skills-team · GitHub ↗ · v0.0.1 · MIT-0
cross-platform ✓ 安全检测通过
107
总下载
0
收藏
0
当前安装
3
版本数
在 OpenClaw 中安装
/install alibabacloud-sls-query
功能描述
Alibaba Cloud SLS (Simple Log Service) log query & analysis skill. Use this skill to help users write, explain, optimize, execute, or troubleshoot SLS index...
使用说明 (SKILL.md)

Alibaba Cloud SLS Query & Analysis

Scenario Description

Use this skill when the user wants to:

  • Explain, rewrite, optimize or execute an existing query
  • Translate a natural-language requirement into an SLS index query, SQL, or SPL statement

Prerequisites

Install Aliyun CLI

Run aliyun version to verify if version >= 3.3.8. If not installed or outdated, follow the doc references/cli-installation-guide.md to install or update.

Ensure AI Mode Enabled

Before executing any CLI commands, enable AI-Mode, set User-Agent, and update plugins:

aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-sls-query"
aliyun plugin update

Check Alibaba Cloud credentials configured

Run aliyun configure list to check if credentials configured. If no valid profile is shown, STOP here and ask the user to run aliyun configure outside of this session.

Security rules:

  • NEVER read, echo, or print AK/SK values
  • NEVER ask the user to paste AK/SK into the conversation
  • ONLY use aliyun configure list to check credential status

RAM Permission Requirements

API CLI Action Purpose
GetLogsV2 get-logs-v2 log:GetLogStoreLogs Run query / SQL / SPL and read results
GetIndex get-index log:GetIndex Read index config to verify prerequisites

For the minimum and complete RAM policy JSON, see references/ram-policies.md.

Permission failure handling: If a call returns Unauthorized permission error, stop and surface references/ram-policies.md to the user. Do not retry with a different account without explicit user confirmation.


Core Workflow

  1. Read index configuration (GetIndex)
  2. Pick query mode
  3. Build statement
  4. Resolve time range
  5. Execute query
  6. Extract data from response
  7. Present CLI command and results

Step 1: Read the Index Configuration (Mandatory)

Always call get-index first — the index config decides which query modes are available in Step 2.

aliyun sls get-index \
  --project \x3Cproject> --logstore \x3Clogstore>

Two sections in the response drive every later decision:

Section Meaning
line Full-text index — absence means full-text search is disabled
keys Field indexes — map of field → { type, doc_value, token, caseSensitive, chn, ... }. doc_value: true means statistics are enabled on that field

If the call returns IndexConfigNotExist (HTTP 404), or the response has neither line nor keys populated, the Logstore has no index at all — stop immediately and tell the user they must create an index before any query / SQL / SPL can run.

  • The response can be large — extract only the fields relevant to the current query. Cache per logstore and reuse within the session.

For field types, tokenization, and how get-index maps to capabilities, see references/related-apis.md and references/query-analysis.md.


Step 2: Pick the Query Mode (Critical)

The query statement takes one of the following forms:

Priority Mode Statement Form Use when Requires
1 Index search \x3Cindex-search> Filtering raw logs; return time-ordered and paginated logs Full-text (line) or any field index (keys.\x3Cfield>)
2 SQL \x3Cindex-search> | \x3CSQL> Aggregation, GROUP BY, sort, window, top-N, projection, and other analytical operations Target field has keys.\x3Cfield> with doc_value: true
3 SQL scan \x3Cindex-search> | \x3CSQL scan> User requested None
4 SPL \x3Cindex-search> | \x3CSPL> User requested None

Selection rule:

  • Always prefer Index search for fastest speed.
  • Use Index search + SQL when the user needs analytical operations or field projection rather than full raw-log retrieval, such as aggregation, GROUP BY, sorting, window analysis, top-N, or returning only the required fields/columns.
  • Do not proactively choose SQL scan or SPL; use them only when the user explicitly requests.

For the full decision guide, see references/query-analysis.md.


Step 3: Write the Statement

3.1 Build the index-search segment first (left of |)

Collect every filter that can be expressed in index-search syntax and place it before the first |. Use * if no filter applies.

* and "payment failed" and status: "500" and not path: "/healthz"
  • * matches all; "..." is full-text (needs full-text index).
  • key: "value" is a field filter (needs field index).
  • Combine with and / or / not; group with parentheses.
  • key: * means field exists. Range (>, >=, [a, b]) works only on long / double.

If the requirement can be fully answered without aggregation or row-level processing, stop here — this is already a complete index search. For full index-search syntax, see references/query-analysis.md.

3.2 Append SQL — for aggregation / analytics

status: 500 | SELECT date_trunc('minute', __time__) AS minute,
                    count(*) AS errors
              FROM log
              GROUP BY minute
              ORDER BY minute
  • Read references/query-analysis.md for Query & SQL rules
  • Table name is log (recommended to omit).
  • SQL respects the indexed field type from get-index — a long / double field can be compared directly (status >= 500). Cast only when a field is indexed as text but numeric semantics are needed (try_cast to suppress errors).
  • Read references/functions-guide.md for unusual Function selection (aggregate, JSON, regex, datetime, IP geo …)

3.3 Append SPL — for row-level processing / flexible filtering

status: 500 and service: payment
| where try_cast(latency as BIGINT) > 1000
| extend latency_ms = try_cast(latency as BIGINT)
| project service, latency_ms, message

For SPL syntax, pipeline commands, and field-handling rules, read references/spl-guide.md.

3.4 Append SQL scan — fallback when the target field has no index / statistics

Syntax follows regular SQL (see 3.2), with one difference: every field is varchar, so always cast() / try_cast() before numeric comparison or arithmetic. See references/query-analysis.md for scan semantics.

* | set session mode=scan; SELECT api, count(1) AS pv FROM log GROUP BY api

Step 4: Resolve the Time Range

Generate --from / --to as Unix timestamps in seconds before building the CLI command. --from is inclusive and --to is exclusive.

Choose one of three input patterns:

  1. Relative time — user says "recent / last N minutes|hours|days".
  2. Natural-language absolute time without timezone — normalize to YYYY-MM-DD HH:MM:SS, then parse using the machine's local timezone.
  3. Absolute time with explicit timezone — parse using the customer-provided timezone or UTC offset.

1. Relative time

# recent 15 minutes
FROM=$(($(date +%s) - 900))
TO=$(date +%s)

2. Natural-language absolute time without timezone

If the user gives a date/time but no timezone, use the machine's local timezone. First normalize natural language such as 2026年3月13日12点 to 2026-03-13 12:00:00, then parse it as local time.

# Example: 2026年3月13日12点 -> 2026-03-13 12:00:00

# Linux (GNU date): local timezone
FROM=$(date -d "2026-03-13 12:00:00" +%s)

# macOS (BSD date): local timezone
FROM=$(date -j -f "%Y-%m-%d %H:%M:%S" "2026-03-13 12:00:00" +%s)

For a time range such as "2026年3月13日12点到13点", compute both endpoints the same way. For a single point-in-time request, infer a practical window from the user's intent; if unclear, ask for the range before executing.

3. Absolute time with explicit timezone

To convert a local date/time to a Unix timestamp: parse the input as UTC with date -u, then subtract the timezone's UTC offset in seconds.

Formula: unix_ts = date_utc_parse(input) − (UTC_offset_hours × 3600)

# Example: 2025-01-15 10:30:00 Beijing Time (UTC+8)
# Beijing is UTC+8, so subtract 8 × 3600 = 28800

# Linux (GNU date)
FROM=$(( $(date -u -d "2025-01-15 10:30:00" +%s) - 28800 ))

# macOS (BSD date)
FROM=$(( $(date -u -j -f "%Y-%m-%d %H:%M:%S" "2025-01-15 10:30:00" +%s) - 28800 ))
# Example: 2025-01-15 10:30:00 New York Time (UTC-5)
# New York is UTC-5, so subtract -5 × 3600 = subtract -18000 = add 18000

# Linux (GNU date)
FROM=$(( $(date -u -d "2025-01-15 10:30:00" +%s) + 18000 ))

# macOS (BSD date)
FROM=$(( $(date -u -j -f "%Y-%m-%d %H:%M:%S" "2025-01-15 10:30:00" +%s) + 18000 ))

Common UTC offsets (value to subtract):

Timezone UTC offset hours Seconds to subtract
Beijing (UTC+8) +8 28800
Tokyo (UTC+9) +9 32400
London (UTC) 0 0
New York (UTC-5) -5 -18000

Step 5: Execute via get-logs-v2

Use aliyun sls get-logs-v2 to execute queries. Run aliyun help sls get-logs-v2 to see CLI parameter usage; read references/related-apis.md for detailed API parameter descriptions.

Required CLI flags:

  • --project: SLS project name
  • --logstore: Logstore name within the project
  • --from: Start of time range, Unix timestamp in seconds (inclusive)
  • --to: End of time range, Unix timestamp in seconds (exclusive)
  • --query: Statement built in Step 3

Pagination works differently depending on whether the statement has a |:

5.1 Index-search only — paginate with --offset / --line

aliyun sls get-logs-v2 \
  --project my-project --logstore my-logstore \
  --from 1740000000 --to 1740003600 \
  --query '* and "payment failed" and status: "500"' \
  --line 100 --offset 0 --reverse true
  • Pagination: --line is page size (1–100, required); --offset is the start row (optional, default 0).
  • Ordering: --reverse true returns newest first; default false is oldest first.

5.2 With SQL — paginate with LIMIT inside the statement

aliyun sls get-logs-v2 \
  --project my-project --logstore my-logstore \
  --from 1740000000 --to 1740003600 \
  --query 'status: "500" | SELECT request_uri, count(*) AS cnt FROM log GROUP BY request_uri ORDER BY cnt DESC LIMIT 20'
  • SQL default result cap is 100 rows. To get more results or paginate:
    • LIMIT count — raise the cap (e.g., LIMIT 500 returns up to 500 rows)
    • LIMIT offset, count — paginate (e.g., LIMIT 20, 20 for rows 21–40; LIMIT 40, 20 for rows 41–60). Max offset+count is 1000000.
    • Do not use LIMIT count OFFSET offset syntax — it is not supported. Always use LIMIT offset, count.
  • Ordering: use ORDER BY \x3Cfield> DESC/ASC to sort.

Result completeness check: every response contains meta.progress. If it is Incomplete, re-issue the same request until it returns Complete.


Step 6: Extract Data from the Response

get-logs-v2 returns:

{
  "meta": { "progress": "Complete", "count": 10, ... },
  "data": [ { "field1": "value1", ... }, ... ]
}
Field Meaning
meta.progress Complete or Incomplete (see Step 5)
meta.count Number of rows returned
data Array of log entries or aggregation rows; may contain __time__ (Unix seconds, string)

Use jq (preferred) or --cli-query (JMESPath) to extract the fields the user needs:

Extract jq --cli-query (JMESPath)
Data rows | jq '.data' --cli-query 'data'
Progress | jq '.meta.progress' --cli-query 'meta.progress'
Row count | jq '.meta.count' --cli-query 'meta.count'
Specific fields | jq '.data[] | {LogStore, read_mb}' --cli-query 'data[].{LogStore: LogStore, read_mb: read_mb}'

Step 7: Present the CLI Command and Results

CLI command — always show the full, copy-paste-ready aliyun sls get-logs-v2 ... command. Redact any AK/SK. If the query was not executed (write / explain scenario), present the command the user should run.

Results — when a query was executed, use Step 6 to extract data and format according to the user's request (table, list, summary, etc.). Append one sentence explaining the query mode choice.


Cleanup

Whether operations succeed or fail, you MUST disable AI-Mode before ending the session:

aliyun configure ai-mode disable

Global Rules

  • Always prefer Index search for fastest raw-log retrieval, and use Index search + SQL for analysis or field projection.
  • When the user only needs specific fields, use SELECT to project them rather than fetching full raw logs — this reduces network overhead. Requires doc_value: true on the target fields (confirmed in Step 1).
  • Do not hard-code __time__ filters — pass time range via --from / --to.
  • Deprecated API: never call get-logs; always use get-logs-v2.

Troubleshooting

When the user reports "no data", "wrong result", or a CLI error, walk through the checklist in this exact order:

  1. Time range — wrong --from/--to? Milliseconds instead of seconds? Recent writes still indexing?
  2. Index configuration — field index missing? Full-text index off? Target field not in keys?
  3. Field type / statistics — range query on a text field? SQL on a field without doc_value?
  4. Syntax — mixed SQL and SPL? Leading * in fuzzy match? SPL string escaping?
  5. Mode choice — scanning when an index-based query would do? Aggregating in SPL instead of SQL?
  6. Completenessmeta.progress = Incomplete, caller did not retry (see Step 5).
  7. ProjectNotExist — region or endpoint is wrong. See references/regions.md.
  8. Network failure (timeout, connection refused) — try switching to internal endpoint. See references/regions.md.

For the full catalog of failure modes and error codes, see references/troubleshooting.md and the Common Errors table in references/related-apis.md.


Reference Documents

Document Description
references/query-analysis.md Mode decision, index-search / SQL rules, scan semantics
references/spl-guide.md SPL pipeline syntax, common commands, field handling
references/functions-guide.md Function categories, SQL/SPL differences, templates
references/troubleshooting.md "No data / wrong result / error" playbook
references/related-apis.md GetLogsV2 and GetIndex API & CLI reference
references/ram-policies.md Minimum and complete RAM policies
references/cli-installation-guide.md Aliyun CLI install, auth modes, profiles
references/regions.md Region / endpoint configuration, internal endpoint, ProjectNotExist troubleshooting
references/acceptance-criteria.md CLI invocation acceptance tests
references/query_analysis/*.yaml · references/spl/*.yaml · references/functions/*.yaml Source-of-truth YAMLs bundled with this skill
安全使用建议
This skill appears to do exactly what it claims: it uses your installed aliyun CLI and whatever credentials are already configured to read index configuration and run SLS queries. Before installing/using it: 1) Verify you trust the skill's source (registry metadata shows unknown homepage). 2) Ensure your aliyun CLI is installed and up-to-date as the docs require; perform credential configuration (aliyun configure) yourself outside the agent session. 3) Use a least-privilege RAM profile or temporary STS credentials for queries (do not use root keys). 4) Expect the skill to modify your aliyun CLI config when it enables AI-Mode and sets the User-Agent — if you don't want those changes, decline that step. 5) Review/limit the RAM policy the skill requires (GetLogsV2, GetIndex) to the minimum resources needed. 6) Do not paste AccessKey/Secret into the chat — follow the skill's guidance and keep secrets in the CLI/profile or use STS/ECS roles.
功能分析
Type: OpenClaw Skill Name: alibabacloud-sls-query Version: 0.0.1 The skill bundle is a comprehensive and well-structured tool for querying Alibaba Cloud Simple Log Service (SLS) logs using the Aliyun CLI. It includes explicit security guardrails in SKILL.md that strictly forbid the AI agent from reading, echoing, or requesting user credentials (AK/SK), and it provides detailed reference documentation for SLS functions, SQL syntax, and SPL pipelines. The logic is entirely consistent with its stated purpose, and no indicators of data exfiltration, malicious execution, or harmful prompt injection were found.
能力标签
cryptorequires-walletcan-make-purchasesrequires-sensitive-credentials
能力评估
Purpose & Capability
Name/description match the requested operations: building, explaining, optimizing, and executing SLS index/search/SQL/SPL queries via the aliyun CLI. The required actions (get-index, get-logs-v2, reading index configuration) align with SLS query functionality.
Instruction Scope
SKILL.md instructs only CLI operations relevant to SLS (check CLI version, enable AI-mode, read index, pick mode, build/execute queries). It explicitly forbids reading or printing AK/SK and tells the agent to stop if no credentials are configured. There are no instructions to read unrelated local files or exfiltrate data to third-party endpoints.
Install Mechanism
This is an instruction-only skill with no install spec and no code files; nothing will be downloaded or written by the skill package itself. The documentation includes standard, known aliyun CLI download URLs (alicdn), which are expected for this integration.
Credentials
The skill does not request environment variables or secrets directly; it relies on the user's existing aliyun CLI configuration or environment credentials (ALIBABA_CLOUD_*). This is proportionate for a CLI-driven cloud integration, but users should be aware the skill will execute commands that use whatever credentials the CLI is configured with (so it will have whatever permissions those credentials grant).
Persistence & Privilege
always:false (no forced global presence). The run instructions ask the user/agent to enable aliyun CLI AI-Mode and set a User-Agent string (these modify the user's CLI configuration). This is reasonable for integration but does change local CLI config; the skill does not request elevated platform privileges or modify other skills.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install alibabacloud-sls-query
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /alibabacloud-sls-query 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.0.1
- Minor update to skill trigger phrases: replaced "SLS 排障" with "analyze sls logs" in the trigger list. - No functional changes to workflow, requirements, or usage instructions.
v0.0.1-beta.2
- Adds detailed guidance for handling user-provided time ranges in log queries, including relative time, absolute time, and timezone normalization. - Expands instructions in "Step 4: Resolve the Time Range" with specific input patterns and parsing choices. - Structure and workflow for query building remain unchanged. - No code or feature changes beyond documentation.
v0.0.1-beta.1
Alibaba Cloud SLS log query & analysis skill - initial release. - Enables users to write, explain, optimize, execute, or troubleshoot SLS index search, SQL analytics, and SPL statements using the aliyun CLI. - Provides detailed workflow: checking index config, selecting query mode, building query statements, and handling time ranges. - Incorporates security rules for credential handling; includes permission requirements and troubleshooting steps. - Step-by-step guidance for choosing query mode (index, SQL, SQL scan, SPL) based on index config and user needs. - Reference links and permission handling guidance included for enhanced reliability.
元数据
Slug alibabacloud-sls-query
版本 0.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 3
常见问题

Alibabacloud Sls Query 是什么?

Alibaba Cloud SLS (Simple Log Service) log query & analysis skill. Use this skill to help users write, explain, optimize, execute, or troubleshoot SLS index... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 107 次。

如何安装 Alibabacloud Sls Query?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install alibabacloud-sls-query」即可一键安装,无需额外配置。

Alibabacloud Sls Query 是免费的吗?

是的,Alibabacloud Sls Query 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Alibabacloud Sls Query 支持哪些平台?

Alibabacloud Sls Query 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Alibabacloud Sls Query?

由 alibabacloud-skills-team(@sdk-team)开发并维护,当前版本 v0.0.1。

💬 留言讨论