mcpField
H
huawei-cloud-lts-manage

huawei-cloud-lts-manage

github.com/huaweicloud云与 DevOps5964 次安装2 天前更新
代码仓库

关于 huawei-cloud-lts-manage

通过 hcloud CLI 管理 Huawei Cloud LTS 日志服务资源的技能,适用于日志运维、故障诊断和安全事件响应。涵盖日志组、流、索引、传输任务和告警规则的生命周期及日志检索。

主要功能

  1. 01管理日志组和日志流
  2. 02配置索引与 OBS 传输任务
  3. 03创建、更新和查询告警规则
  4. 04按关键词与时间范围检索日志
  5. 05查看日志上下文和分布直方图
  6. 06删除资源前要求明确确认

适用场景

  1. 01按时间和关键词排查故障日志
  2. 02设置日志索引和 OBS 传输
  3. 03维护日志保留期限与告警规则
  4. 04查询告警历史以响应安全事件

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/huaweicloud/huaweicloud-skills --skill huawei-cloud-lts-manage

安装后在 Claude Code 中输入/huawei-cloud-lts-manage确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
acceptance-criteria.md
cli-installation-guide.md
dataflow-diagram.md
iam-policies.md
lts-alarm-reference.md
verification-method.md
scripts/
test-cli-commands.sh
templates/
test-vars.json

详细介绍

Huawei Cloud LTS 日志服务管理

概述

此技能通过 hcloud CLI 管理 Huawei Cloud LTS(Log Tank Service / 云日志服务)资源。 涵盖日志组、日志流、索引、转储任务和告警规则的完整生命周期, 还支持日志搜索,用于故障诊断和安全事件响应。

功能:

类别操作
查询列出日志组、日志流、索引、转储任务、告警规则、告警历史;搜索日志(关键词、结构化、上下文、直方图)
创建创建日志组、日志流、全文索引、OBS 转储任务、关键词告警规则、SQL 告警规则
更新更新日志组 TTL、日志流 TTL/存储、转储配置、告警规则、告警状态、结构化配置
删除删除日志组、日志流、转储任务、告警规则(⚠️ 需要确认)
诊断按关键词/时间搜索日志以定位故障;查询日志上下文;查看日志分布直方图

范围边界:此技能仅支持 Huawei Cloud LTS(Log Tank Service / 云日志服务) 日志组 / 日志流 / 索引 / 转储 / 告警 / 搜索管理。它不支持 其他云服务(例如 ECS、数据库)——拒绝非 LTS 请求,并引导用户使用 适当的技能或控制台。

前提条件

  1. 已安装并完成身份验证的 hcloud CLI——参见 references/cli-installation-guide.md
  2. 已通过 hcloud configure 配置 Huawei Cloud AK/SK(CLI 配置文件)
  3. IAM 权限——最小权限策略参见 references/iam-policies.md
  4. 区域:LTS 按区域区分。使用 --cli-region 指定目标区域(例如 cn-north-4、ap-southeast-1)

工作流

1. Identify target log group/stream (ListLogGroups → ListLogStreams)
2. Query or manage resources based on user intent:
   ├── Query: list/show logs, indexes, transfers, alarms
   ├── Create: create log group/stream/index/transfer/alarm
   ├── Update: modify TTL/index/transfer/alarm config
   ├── Delete: remove resources (⚠️ confirmation required)
   └── Diagnose: search logs with keywords/time range
3. Return results (query returns JSON; mutations return resource config snapshot)

核心命令

查询 — 日志组和日志流
# List all log groups
hcloud LTS ListLogGroups --cli-region={region} --project_id={project_id}

# List log streams under a group
hcloud LTS ListLogStreams --cli-region={region} --project_id={project_id} \
  --log_group_name={log_group_name}

# Query index configuration for a log stream
hcloud LTS ListLogStreamIndex --cli-region={region} --project_id={project_id} \
  --group_id={group_id} --stream_id={stream_id}
查询 — 转储任务
# List all transfer tasks
hcloud LTS ListTransfers --cli-region={region} --project_id={project_id}

# Filter by transfer type (OBS/DIS/DMS)
hcloud LTS ListTransfers --cli-region={region} --project_id={project_id} \
  --log_transfer_type=OBS
查询 — 告警规则和历史记录
# List keyword alarm rules
hcloud LTS ListKeywordsAlarmRules --cli-region={region} --project_id={project_id}

# List SQL alarm rules
hcloud LTS ListSqlAlarmRules --cli-region={region} --project_id={project_id}

# Query active or history alarms (type: active_alert/history_alert)
# --whether_custom_field=false requires --time_range (minutes); true requires --start_time/--end_time (ms)
hcloud LTS ListActiveOrHistoryAlarms --cli-region={region} --project_id={project_id} \
  --domain_id={domain_id} --type=history_alert --whether_custom_field=false --time_range=30 --limit=10
查询 — 日志搜索(诊断)
# Search logs by keyword and time range
hcloud LTS ListLogs --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --log_stream_id={log_stream_id} \
  --start_time={start_time} --end_time={end_time} \
  --keywords="ERROR" --limit=50 --is_desc=true --highlight=true

# Get log context around a specific line (for fault diagnosis)
hcloud LTS ListLogContext --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --log_stream_id={log_stream_id} \
  --__time__={timestamp} --line_num={line_num} \
  --backwards_size=10 --forwards_size=10

# Get log distribution histogram (for trend analysis)
hcloud LTS ListLogHistogram --cli-region={region} --project_id={project_id} \
  --group_id={group_id} --stream_id={stream_id} \
  --start_time={start_time} --end_time={end_time} \
  --key_word="ERROR" --step_interval=3600000

# Query structured logs with SQL expression (requires the log stream to have a struct config)
# Supported SQL: GROUP BY / LIKE / WHERE
hcloud LTS ListQueryStructuredLogs --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --log_stream_id={log_stream_id} \
  --start_time={start_time} --end_time={end_time} \
  --sql_expression="select * where level like '%ERROR%'"
创建 — 日志组和日志流
# Create a log group with TTL (days)
hcloud LTS CreateLogGroup --cli-region={region} --project_id={project_id} \
  --log_group_name="my-log-group" --ttl_in_days=30

# Create a log stream under a group
# Note: log stream TTL must equal the TTL of the log group it belongs to
# (e.g. `--ttl_in_days={log_group_ttl}` where {log_group_ttl} is the owning group's TTL),
# otherwise the API returns a USE_ERROR.
hcloud LTS CreateLogStream --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --log_stream_name="my-log-stream" --ttl_in_days={log_group_ttl}
创建 — 索引
# Create full-text index for a log stream
hcloud LTS CreateLogStreamIndex --cli-region={region} --project_id={project_id} \
  --group_id={group_id} --stream_id={stream_id} --logStreamId={stream_id} \
  --fullTextIndex.enable=true --fullTextIndex.caseSensitive=false \
  --fullTextIndex.includeChinese=true --fullTextIndex.tokenizer=" "
创建 — 转储任务(到 OBS)
# Create a transfer task to OBS bucket
hcloud LTS CreateTransfer --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} \
  --log_streams.1.log_stream_id={stream_id} --log_streams.1.log_stream_name={stream_name} \
  --log_transfer_info.log_transfer_type=OBS \
  --log_transfer_info.log_transfer_mode=cycle \
  --log_transfer_info.log_storage_format=RAW \
  --log_transfer_info.log_transfer_status=ENABLE \
  --log_transfer_info.log_transfer_detail.obs_bucket_name={bucket_name} \
  --log_transfer_info.log_transfer_detail.obs_period=5 \
  --log_transfer_info.log_transfer_detail.obs_period_unit=min
创建 — 告警规则
# Create a keyword alarm rule
hcloud LTS CreateKeywordsAlarmRule --cli-region={region} --project_id={project_id} \
  --domain_id={domain_id} \
  --keywords_alarm_rule_name="error-alarm" \
  --keywords_alarm_level=Critical \
  --keywords_requests.1.log_group_id={group_id} \
  --keywords_requests.1.log_stream_id={stream_id} \
  --keywords_requests.1.keywords="ERROR" \
  --keywords_requests.1.condition=">=" --keywords_requests.1.number=1 \
  --keywords_requests.1.search_time_range=5 --keywords_requests.1.search_time_range_unit=minute \
  --frequency.type=CRON --frequency.cron_expr="0 */5 * * * *" --notification_frequency=5

# Create a SQL alarm rule (requires sql_requests.[N].search_time_range)
hcloud LTS CreateSqlAlarmRule --cli-region={region} --project_id={project_id} \
  --domain_id={domain_id} \
  --sql_alarm_rule_name="sql-error-alarm" \
  --sql_alarm_level=Major \
  --sql_requests.1.log_group_id={group_id} \
  --sql_requests.1.log_stream_id={stream_id} \
  --sql_requests.1.sql="select count(*) where level='ERROR'" \
  --sql_requests.1.search_time_range=5 --sql_requests.1.search_time_range_unit=minute \
  --condition_expression=">=1" \
  --frequency.type=CRON --frequency.cron_expr="0 */5 * * * *" --notification_frequency=5
更新 — TTL 和配置
# Update log group TTL (save duration)
hcloud LTS UpdateLogGroup --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --ttl_in_days=60

# Update log stream TTL and storage
hcloud LTS UpdateLogStream --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --log_stream_id={log_stream_id} \
  --ttl_in_days=60 --whether_log_storage=true

# Update transfer task config
hcloud LTS UpdateTransfer --cli-region={region} --project_id={project_id} \
  --log_transfer_id={transfer_id} \
  --log_transfer_info.log_storage_format=RAW \
  --log_transfer_info.log_transfer_status=ENABLE \
  --log_transfer_info.log_transfer_detail.obs_bucket_name={bucket_name} \
  --log_transfer_info.log_transfer_detail.obs_period=5 \
  --log_transfer_info.log_transfer_detail.obs_period_unit=min

# Enable/disable an alarm rule (status: RUNNING/STOPPING; type: keywords/sql)
hcloud LTS UpdateAlarmRuleStatus --cli-region={region} --project_id={project_id} \
  --alarm_rule_id={alarm_rule_id} --status=STOPPING --type=keywords
删除 — ⚠️ 需要确认

关键:执行任何删除操作前,都必须获得用户的明确确认。 禁止批量删除所有 LTS 资源。每次删除都必须指定单个资源 ID。

# Delete a log group (⚠️ cascades all log streams under it)
hcloud LTS DeleteLogGroup --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id}

# Delete a log stream
hcloud LTS DeleteLogStream --cli-region={region} --project_id={project_id} \
  --log_group_id={log_group_id} --log_stream_id={log_stream_id}

# Delete a transfer task
hcloud LTS DeleteTransfer --cli-region={region} --project_id={project_id} \
  --log_transfer_id={transfer_id}

# Delete a keyword alarm rule
hcloud LTS DeleteKeywordsAlarmRule --cli-region={region} --project_id={project_id} \
  --keywords_alarm_rule_id={alarm_rule_id}

# Delete a SQL alarm rule
hcloud LTS DeleteSqlAlarmRule --cli-region={region} --project_id={project_id} \
  --sql_alarm_rule_id={alarm_rule_id}

参数确认

参数必填说明示例
--cli-region是目标区域{your-region}
--project_id是项目 ID从 IAM 控制台获取
--log_group_id适用于日志流/索引/转储操作日志组 IDxxx-xxx-xxx
--log_stream_id适用于索引/日志搜索操作日志流 IDxxx-xxx-xxx
--ttl_in_days适用于创建/更新日志组或日志流日志保留天数30、60、365
--keywords适用于日志搜索搜索关键词"ERROR"、"Exception"
--start_time / --end_time适用于日志搜索时间范围(毫秒)1700000000000
--log_transfer_type适用于转储筛选转储类型OBS、DIS、DMS
删除安全规则
  1. 仅允许删除单个资源——每次 Delete 调用必须恰好指定一个资源 ID
  2. 禁止使用通配符/批量删除——DeleteLogGroup 会删除组下的所有日志流;务必确认级联影响
  3. 用户必须明确确认——执行任何删除操作前,用户须回复“确认”/“confirm”/“ok”
  4. 禁止在单次会话中删除所有日志组或所有告警规则,除非逐项获得确认

参考文档

KooCLI 命令格式规范

hcloud LTS ListLogGroups --cli-region={your-region} [--key=value ...]
功能描述示例
服务名称LTS(大写)hcloud LTS ListLogGroups
操作名称PascalCaseListLogGroups、CreateTransfer、DeleteLogStream
区域参数--cli-region=<value>--cli-region={your-region}
简单参数--key=value--log_group_name=my-group
索引参数--key.1=value--keywords_requests.1.keywords=ERROR

评论

支持 Markdown