OpenClaw SLS Integration
This skill provisions Alibaba Cloud SLS observability for OpenClaw on Linux and keeps reruns safe.
At a high level, execute this flow:
- 1. Check and install
aliyun CLI (install latest when missing) - Install
LoongCollector by project region (skip if already running) - Create an identifier-based machine group (local identifier + cloud machine group)
- Create
logstore index and dashboards - Create
logstore collection config - Bind the collection config to the machine group
Capture Intent Before Execution
Before running commands, make sure the user intent is complete:
- 1. Confirm the target
PROJECT and LOGSTORE. - Confirm Linux host access with
sudo available. - Confirm AK/SK are already exported in environment variables.
- If any required input is missing, ask for it first and do not run partial setup.
Prerequisites
Required:
- -
PROJECT: SLS project name - INLINECODE8 : SLS logstore name
Read from environment variables:
- - INLINECODE9
- INLINECODE10
- INLINECODE11 (used for the local UID file under
/etc/ilogtail/users)
Recommended optional:
- -
ALIBABA_CLOUD_REGION_ID (auto-resolved from PROJECT when not set)
If you use different AK/SK variable names, export them to these standard names first.
Expected Result
After successful execution, the environment should contain:
- - Running
LoongCollector (or ilogtaild) on the host - Machine group INLINECODE17
- Logstore index created on the target INLINECODE18
- Dashboards
openclaw-audit and INLINECODE20 - Collection config INLINECODE21
- Config binding between
openclaw-audit_${LOGSTORE} and INLINECODE23
One-Time Execution Flow (Idempotent)
The commands below are designed as "exists -> skip" and are safe to rerun.
Strict template mode: for index/config/dashboard payloads, always read from files in references/.
Do not handcraft or simplify JSON bodies beyond required placeholder replacement.
CODEBLOCK0
Response Format
When this skill completes, return a concise status report with:
- 1. Inputs used:
PROJECT, LOGSTORE, resolved INLINECODE27 - Created/updated resources (machine group, index, dashboards, config, binding)
- Any skipped steps (already existed / already running)
- Next verification commands for the user
Verification Commands
CODEBLOCK1
Reference Files
- - Command flow: INLINECODE28
- Index definition: INLINECODE29
- Dashboard templates:
references/dashboard-audit.json, INLINECODE31 - Collection config template: INLINECODE32
Read reference files only when needed:
- - Use
cli-commands.md for step-by-step troubleshooting. - Use JSON templates when creating/updating resources.
OpenClaw SLS 集成
该技能为 Linux 上的 OpenClaw 配置阿里云 SLS 可观测性,并确保重跑安全。
在高级层面,执行以下流程:
- 1. 检查并安装 aliyun CLI(缺失时安装最新版本)
- 根据项目地域安装 LoongCollector(如果已在运行则跳过)
- 创建基于标识的机器组(本地标识 + 云端机器组)
- 创建 logstore 索引和仪表盘
- 创建 logstore 采集配置
- 将采集配置绑定到机器组
执行前确认意图
在运行命令之前,确保用户意图完整:
- 1. 确认目标 PROJECT 和 LOGSTORE。
- 确认 Linux 主机可访问且具有 sudo 权限。
- 确认 AK/SK 已在环境变量中导出。
- 如果缺少任何必要输入,请先询问,不要运行部分设置。
前提条件
必需:
- - PROJECT:SLS 项目名称
- LOGSTORE:SLS 日志库名称
从环境变量读取:
- - ALIBABACLOUDACCESSKEYID
- ALIBABACLOUDACCESSKEYSECRET
- ALIYUN_UID(用于 /etc/ilogtail/users 下的本地 UID 文件)
推荐可选:
- - ALIBABACLOUDREGION_ID(未设置时从 PROJECT 自动解析)
如果您使用不同的 AK/SK 变量名,请先将其导出为这些标准名称。
预期结果
成功执行后,环境应包含:
- - 主机上正在运行的 LoongCollector(或 ilogtaild)
- 机器组 openclaw-sls-collector
- 在目标 LOGSTORE 上创建的日志库索引
- 仪表盘 openclaw-audit 和 openclaw-gateway
- 采集配置 openclaw-audit${LOGSTORE}
- openclaw-audit${LOGSTORE} 与 openclaw-sls-collector 之间的配置绑定
一次性执行流程(幂等)
以下命令设计为存在则跳过,可安全重跑。
严格模板模式:对于索引/配置/仪表盘负载,始终从 references/ 中的文件读取。
除必要的占位符替换外,不要手工制作或简化 JSON 主体。
bash
set -euo pipefail
===== 用户输入 =====
: ${PROJECT:?请导出 PROJECT}
: ${LOGSTORE:?请导出 LOGSTORE}
: ${ALIBABA
CLOUDACCESS
KEYID:?请导出 ALIBABA
CLOUDACCESS
KEYID}
: ${ALIBABA
CLOUDACCESS
KEYSECRET:?请导出 ALIBABA
CLOUDACCESS
KEYSECRET}
: ${ALIYUN
UID:?请导出 ALIYUNUID}
MACHINE_GROUP=openclaw-sls-collector
CONFIGNAME=openclaw-audit${LOGSTORE}
1) 如果缺失则安装 aliyun CLI(Linux)
if ! command -v aliyun >/dev/null 2>&1; then
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y aliyun-cli
elif command -v dnf >/dev/null 2>&1; then
sudo dnf install -y aliyun-cli
elif command -v yum >/dev/null 2>&1; then
sudo yum install -y aliyun-cli
elif command -v zypper >/dev/null 2>&1; then
sudo zypper -n install aliyun-cli
else
echo 未找到 aliyun CLI。请为您的 Linux 发行版手动安装 aliyun-cli。 >&2
exit 1
fi
fi
为 aliyun CLI 导出认证变量
export ALIBABA
CLOUDACCESS
KEYID
export ALIBABA
CLOUDACCESS
KEYSECRET
isloongrunning() {
if sudo /etc/init.d/loongcollectord status 2>/dev/null | grep -qi running; then
return 0
fi
if sudo /etc/init.d/ilogtaild status 2>/dev/null | grep -qi running; then
return 0
fi
return 1
}
2) 解析地域并安装 LoongCollector(已在运行时跳过)
REGION
ID=${ALIBABACLOUD
REGIONID:-}
if [ -z $REGION_ID ]; then
REGION_ID=$(aliyun sls GetProject --project $PROJECT --cli-query region --quiet 2>/dev/null | tr -d \ || true)
fi
if [ -z $REGION_ID ]; then
echo 无法从项目解析地域:$PROJECT。请设置 ALIBABA
CLOUDREGION_ID。 >&2
exit 1
fi
if ! isloongrunning; then
wget https://aliyun-observability-release-${REGIONID}.oss-${REGIONID}.aliyuncs.com/loongcollector/linux64/latest/loongcollector.sh -O loongcollector.sh
chmod +x loongcollector.sh
./loongcollector.sh install ${REGION_ID}
fi
安装后验证:loongcollectord/ilogtaild 必须有一个在运行。
if ! is
loongrunning; then
sudo /etc/init.d/loongcollectord start >/dev/null 2>&1 || true
sudo /etc/init.d/ilogtaild start >/dev/null 2>&1 || true
fi
if ! is
loongrunning; then
echo LoongCollector 安装检查失败:loongcollectord 和 ilogtaild 均未运行。 >&2
exit 1
fi
3) 本地用户自定义标识 + 创建机器组
sudo mkdir -p /etc/ilogtail
sudo mkdir -p /etc/ilogtail/users
if [ ! -f /etc/ilogtail/user
definedid ]; then
sudo touch /etc/ilogtail/user
definedid
fi
RAND8=$(LC_ALL=C tr -dc a-z0-9 DEFINEDID
PREFIX=${PROJECT}openclaw
slscollector_
EXISTING
USERDEFINED
ID=$(sudo awk -v p=${USERDEFINED
IDPREFIX} index($0,p)==1 {print; exit} /etc/ilogtail/user
definedid 2>/dev/null || true)
if [ -n ${EXISTING
USERDEFINED_ID} ]; then
USER
DEFINEDID=${EXISTING
USERDEFINED_ID}
else
USER
DEFINEDID=${USER
DEFINEDID_PREFIX}${RAND8}
echo ${USER
DEFINEDID} | sudo tee -a /etc/ilogtail/user
definedid >/dev/null
fi
if ! sudo grep -Fxq ${USER
DEFINEDID} /etc/ilogtail/user
definedid 2>/dev/null; then
echo 无法将 USER
DEFINEDID 持久化到 /etc/ilogtail/user
definedid >&2
exit 1
fi
if [ ! -f /etc/ilogtail/users/${ALIYUN_UID} ]; then
sudo touch /etc/ilogtail/users/${ALIYUN_UID}
fi
if [ ! -f /etc/ilogtail/users/${ALIYUN_UID} ]; then
echo 无法创建 UID 标记文件:/etc/ilogtail/users/${ALIYUN_UID} >&2
exit 1
fi
if ! aliyun sls GetMachineGroup --project $PROJECT --machineGroup $MACHINE_GROUP >/dev/null 2>&1; then
cat > /tmp/openclaw-machine-group.json <
{
groupName: ${MACHINE_GROUP},
groupType: ,
machineIdentifyType: userdefined,
machineList: [${USERDEFINEDID}]
}
EOF
aliyun sls CreateMachineGroup \
--project $PROJECT \
--body $(cat /tmp/openclaw-machine-group.json)
fi
if ! aliyun sls GetMachineGroup --project $PROJECT --machineGroup $MACHINE_GROUP