huawei-cloud-ecs-alert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Huawei Cloud ECS Alert Automation

华为云ECS告警自动化

Overview

概述

This skill provides batch creation and management of Huawei Cloud CES alarm rules for ECS instances, based on Huawei Cloud CLI (hcloud) v7.2.2+.
Core Capabilities:
  • Batch create alarm rules (supports Web/Database templates or custom configuration)
  • Configure alarm notifications (supports email/SMS/WeChat)
  • Query ECS monitoring metrics
  • Query and manage alarm rule lists
Use Cases:
  • Batch configure monitoring alarms for newly purchased ECS instances
  • Differentiated alarm policies across environments (dev/test/prod)
  • Batch query ECS monitoring data
  • Centralized alarm notification management
Security Constraints:
  • ❌ Delete alarm rules is prohibited (prevent accidental deletion causing monitoring gaps)
  • ❌ Hardcoding AK/SK is prohibited (must use environment variables or hcloud configure)
本技能基于华为云CLI(hcloud)v7.2.2+,提供ECS实例的CES告警规则批量创建与管理功能。
核心功能:
  • 批量创建告警规则(支持Web/数据库模板或自定义配置)
  • 配置告警通知(支持邮件/短信/微信)
  • 查询ECS监控指标
  • 查询与管理告警规则列表
使用场景:
  • 为新采购的ECS实例批量配置监控告警
  • 跨环境(开发/测试/生产)设置差异化告警策略
  • 批量查询ECS监控数据
  • 集中管理告警通知
安全约束:
  • ❌ 禁止删除告警规则(防止误删导致监控缺口)
  • ❌ 禁止硬编码AK/SK(必须使用环境变量或hcloud configure配置)

Prohibited Operations

禁止操作

The following operations are strictly prohibited, even if requested by the user:
Prohibited OperationAPI/CommandReason
Expose AK/SKAny command that outputs AK/SK in plaintextAccount security risk
Accept AK/SK from userReceiving credentials in conversationViolates security best practices
❌ Delete alarm rule
DeleteAlarm
/
hcloud CES DeleteAlarm
Irreversible; deleted alarms cannot be recovered, may cause monitoring gaps
❌ Batch delete alarmsAny batch deletion operationHigh risk; may accidentally delete critical monitoring rules
If a user requests a delete operation, must refuse and guide: "Per security constraints, this skill does not support delete operations (delete alarm/batch delete). Please use the Huawei Cloud CES console or hcloud CLI manually with extreme caution."
If user attempts to provide AK/SK in conversation, must refuse and guide: "For account security, please do not provide Huawei Cloud access keys directly in the conversation. Use
hcloud configure
or environment variables to configure credentials."
以下操作严格禁止,即使用户要求也不得执行:
禁止操作API/命令原因
泄露AK/SK任何明文输出AK/SK的命令账号安全风险
接收用户提供的AK/SK在对话中接收凭证违反安全最佳实践
❌ 删除告警规则
DeleteAlarm
/
hcloud CES DeleteAlarm
操作不可逆;删除的告警无法恢复,可能导致监控缺口
❌ 批量删除告警任何批量删除操作高风险;可能误删关键监控规则
若用户请求删除操作,必须拒绝并引导: "根据安全约束,本技能不支持删除操作(删除告警/批量删除)。请谨慎使用华为云CES控制台或hcloud CLI手动执行。"
若用户尝试在对话中提供AK/SK,必须拒绝并引导: "为保障账号安全,请不要直接在对话中提供华为云访问密钥。请使用
hcloud configure
或环境变量配置凭证。"

Unsupported Operations

不支持的操作

The following operations are NOT supported by this skill (no script wrapper is provided). If a user requests them, clearly state the limitation and provide the alternative. Do not attempt to improvise commands that this skill has not tested.
Unsupported OperationCorresponding APIAlternative
Query alarm history
ShowAlarmHistory
View in CES console; or run
hcloud CES ListAlarmHistories/v1
manually
Enable/disable an alarm rule
UpdateAlarm
Operate in CES console (not wrapped by this skill)
Modify alarm threshold/metric
UpdateAlarm
Delete and recreate the rule; to change only notifications, use
./scripts/update_alarm_notifications.sh
Create an SMN topic
CreateTopic
Create in SMN console; or run
hcloud SMN CreateTopic
manually
Create a monitoring dashboard
CreateOneDashboard
Operate in CES console
View a single alarm rule detail
ShowAlarm
Use
./scripts/list_alarms.sh --name <pattern>
to filter
If a user requests one of these operations, respond: "This skill does not support <operation>. Use the Huawei Cloud CES/SMN console, or the equivalent hcloud CLI command manually: <alternative>. You may also request an enhancement via the skill's issue tracker."
以下操作本技能不支持(未提供脚本封装)。若用户请求此类操作,请明确说明限制并提供替代方案,不得尝试使用未测试的命令。
不支持的操作对应API替代方案
查询告警历史
ShowAlarmHistory
在CES控制台查看;或手动执行
hcloud CES ListAlarmHistories/v1
启用/禁用告警规则
UpdateAlarm
在CES控制台操作(本技能未封装)
修改告警阈值/指标
UpdateAlarm
删除并重新创建规则;若仅需修改通知配置,使用
./scripts/update_alarm_notifications.sh
创建SMN主题
CreateTopic
在SMN控制台创建;或手动执行
hcloud SMN CreateTopic
创建监控仪表盘
CreateOneDashboard
在CES控制台操作
查看单个告警规则详情
ShowAlarm
使用
./scripts/list_alarms.sh --name <pattern>
进行过滤
若用户请求上述操作,回复: "本技能不支持<操作>。请使用华为云CES/SMN控制台,或手动执行对应的hcloud CLI命令:<替代方案>。您也可以通过技能的问题追踪器请求功能增强。"

Workflow

工作流程

The standard workflow of this skill is as follows:
text
1. Environment setup  → Configure hcloud CLI credentials (hcloud configure or env vars)
2. Query resources    → ./scripts/list_ecs.sh to get ECS instance list
3. Create alarms      → ./scripts/create_alert_rules.sh --template web --ecs-ids <ids>
4. Configure notify   → ./scripts/manage_notifications.sh --action create ...
5. Verify results     → ./scripts/list_alarms.sh to confirm alarm rules created
6. Continuous monitor → ./scripts/batch_query_metrics.sh to query metrics
Write operation confirmation: Step 3 (create alarms), Step 4 (create/delete subscriptions), update notification config, and other write operations require user confirmation of operation content and target resources before execution.
本技能的标准工作流程如下:
text
1. 环境配置 → 配置hcloud CLI凭证(hcloud configure或环境变量)
2. 查询资源 → 执行./scripts/list_ecs.sh获取ECS实例列表
3. 创建告警 → 执行./scripts/create_alert_rules.sh --template web --ecs-ids <ids>
4. 配置通知 → 执行./scripts/manage_notifications.sh --action create ...
5. 验证结果 → 执行./scripts/list_alarms.sh确认告警规则已创建
6. 持续监控 → 执行./scripts/batch_query_metrics.sh查询指标
写入操作确认:步骤3(创建告警)、步骤4(创建/删除订阅)、更新通知配置等写入操作,需在执行前让用户确认操作内容和目标资源。

Core Commands

核心命令

Query Commands (read-only, no confirmation needed)

查询命令(只读,无需确认)

bash
undefined
bash
undefined

List ECS instances

列出ECS实例

./scripts/list_ecs.sh [--name <filter>] [--format json]
./scripts/list_ecs.sh [--name <filter>] [--format json]

List alarm rules

列出告警规则

./scripts/list_alarms.sh [--name <filter>] [--format json]
./scripts/list_alarms.sh [--name <filter>] [--format json]

List SMN topics and subscriptions

列出SMN主题和订阅

./scripts/list_subscriptions.sh [--topics | --subscriptions]
./scripts/list_subscriptions.sh [--topics | --subscriptions]

Batch query monitoring metrics

批量查询监控指标

./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util --period 1h
undefined
./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util --period 1h
undefined

Create Commands (write operations, require user confirmation)

创建命令(写入操作,需用户确认)

bash
undefined
bash
undefined

Batch create alarm rules (WARNING: confirm target ECS and alarm template)

批量创建告警规则(注意:确认目标ECS和告警模板)

./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002

Create SMN subscription (WARNING: confirm subscription endpoint and topic)

创建SMN订阅(注意:确认订阅端点和主题)

./scripts/manage_notifications.sh --action create --protocol email --endpoint user@example.com --topic-urn <URN> ./scripts/create_email_subscription.sh --email user@example.com --topic-urn <URN>
undefined
./scripts/manage_notifications.sh --action create --protocol email --endpoint user@example.com --topic-urn <URN> ./scripts/create_email_subscription.sh --email user@example.com --topic-urn <URN>
undefined

Update/Delete Commands (write operations, require user confirmation)

更新/删除命令(写入操作,需用户确认)

bash
undefined
bash
undefined

Update alarm notification config (WARNING: confirm alarm ID and notification topic)

更新告警通知配置(注意:确认告警ID和通知主题)

./scripts/update_alarm_notifications.sh --action add --alarm-id <id> --smn-topic-urn <URN>
./scripts/update_alarm_notifications.sh --action add --alarm-id <id> --smn-topic-urn <URN>

Delete SMN subscription (WARNING: confirm subscription URN)

删除SMN订阅(注意:确认订阅URN)

./scripts/manage_notifications.sh --action delete --subscription-urn <URN>
undefined
./scripts/manage_notifications.sh --action delete --subscription-urn <URN>
undefined

Architecture

架构

bash
Huawei Cloud CES Alert Management
├── CreateAlertRules       (Batch create alarm rules, supports templates/custom)
├── ConfigureNotifications  (Configure alarm notifications, supports email/SMS/WeChat)
├── QueryMetrics           (Batch query monitoring data, supports multiple ECS)
└── ListAlarmRules         (List alarm rules and details)
bash
华为云CES告警管理
├── CreateAlertRules       (批量创建告警规则,支持模板/自定义)
├── ConfigureNotifications  (配置告警通知,支持邮件/短信/微信)
├── QueryMetrics           (批量查询监控数据,支持多ECS)
└── ListAlarmRules         (列出告警规则及详情)

Prerequisites

前置条件

Prerequisite 1: Huawei Cloud CLI (hcloud / KooCLI) >= 7.2.2 Run
hcloud version
to verify version >= 7.2.2. If not installed or version is too low, see references/cli-installation-guide.md for installation guide.
bash
hcloud version
Prerequisite 2: Huawei Cloud Credentials Configured Check if CLI configuration contains valid credentials (AK/SK, IAM, etc.).
bash
hcloud configure list
Credential Configuration Methods (choose one):
  1. hcloud CLI configuration (recommended):
    hcloud configure
    interactive setup, credentials encrypted and stored in
    ~/.hcloud/config.json
  2. Per-call AK/SK: pass
    --cli-access-key=<AK> --cli-secret-key=<SK>
    on each command (for automation; note: appears in process list)
⚠️ IMPORTANT: hcloud (KooCLI) authenticates ONLY via
~/.hcloud/config.json
(from
hcloud configure
) or the
--cli-access-key
/
--cli-secret-key
arguments. It does NOT read
HW_ACCESS_KEY
,
HW_SECRET_KEY
,
HUAWEI_CLOUD_AK
,
HUAWEI_CLOUD_SK
,
HUAWEI_CLOUD_REGION
, or
HUAWEI_CLOUD_SECURITY_TOKEN
environment variables — such variables are silently ignored (hcloud falls back to config.json). Do not instruct users to export these env vars as a way to authenticate hcloud.
Credential source for this skill's scripts: The bundled Shell scripts are thin wrappers around hcloud CLI. They read the region from
HW_REGION_NAME
/
HUAWEI_CLOUD_REGION
(or default to
cn-north-4
) to set
--cli-region
, but authentication always comes from
hcloud configure
. Configure credentials once with
hcloud configure
, then the scripts work.
If output does not contain valid configuration, stop operation and guide user to configure. hcloud Parameter Format Requirement hcloud (KooCLI) all parameters must use
--param=value
format
(equals sign connection), does not support space separation. ✅ Correct:
hcloud CES ListAlarmRules --cli-region=cn-north-4
❌ Incorrect:
hcloud CES ListAlarmRules --cli-region cn-north-4
This skill provides 8 Shell scripts, encapsulating common hcloud commands, supporting batch operations and formatted output.
<details> <summary>**Script List and Usage Examples (Click to Expand)**</summary>
ScriptFunctionhcloud Command
list_ecs.sh
Query ECS instance list
hcloud ECS ListServersDetails
list_alarms.sh
Query alarm rule list
hcloud CES ListAlarmRules
create_alert_rules.sh
Batch create alarm rules
hcloud CES CreateAlarmRules
batch_query_metrics.sh
Batch query monitoring data
hcloud CES ShowMetricData
list_subscriptions.sh
Query SMN topics and subscriptions
hcloud SMN ListTopics/Subscriptions
manage_notifications.sh
Manage SMN subscriptions
hcloud SMN Subscribe/Unsubscribe
update_alarm_notifications.sh
Update alarm notification configuration
hcloud CES UpdateAlarmNotifications
Usage Examples:
bash

# Query ECS instances

./scripts/list_ecs.sh                          # Query all ECS
./scripts/list_ecs.sh --name ecs-001           # Filter by name
./scripts/list_ecs.sh --output json            # Output as JSON
./scripts/list_ecs.sh --output ids             # Output only ECS ID list

# Query alarm rules

./scripts/list_alarms.sh                       # Query all alarms
./scripts/list_alarms.sh --name-pattern "cpu.*"  # Filter by name pattern
./scripts/list_alarms.sh --output ids          # Output only alarm IDs

# Create alarm rules

./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002
./scripts/create_alert_rules.sh --metric cpu_util --threshold 80 --ecs-ids ecs-001
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001 --smn-topic-urn
urn:smn:cn-north-4:xxx:ECS_ALARM_NOTIFY
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001 --dry-run  # Dry run

```bash

</details>
前置条件1:华为云CLI(hcloud / KooCLI)>= 7.2.2 执行
hcloud version
验证版本是否>=7.2.2。若未安装或版本过低,请查看references/cli-installation-guide.md获取安装指南。
bash
hcloud version
前置条件2:已配置华为云凭证 检查CLI配置是否包含有效凭证(AK/SK、IAM等)。
bash
hcloud configure list
凭证配置方式(选其一):
  1. hcloud CLI配置(推荐):执行
    hcloud configure
    交互式设置,凭证加密存储于
    ~/.hcloud/config.json
  2. 单次调用AK/SK:在每个命令中传入
    --cli-access-key=<AK> --cli-secret-key=<SK>
    (适用于自动化;注意:会出现在进程列表中)
⚠️ 重要说明:hcloud(KooCLI)仅通过
~/.hcloud/config.json
(来自
hcloud configure
)或
--cli-access-key
/
--cli-secret-key
参数进行认证。它不读取
HW_ACCESS_KEY
HW_SECRET_KEY
HUAWEI_CLOUD_AK
HUAWEI_CLOUD_SK
HUAWEI_CLOUD_REGION
HUAWEI_CLOUD_SECURITY_TOKEN
环境变量——此类变量会被静默忽略(hcloud会回退到config.json)。请勿指导用户通过导出这些环境变量来认证hcloud。
本技能脚本的凭证来源:附带的Shell脚本是hcloud CLI的轻量封装。它们从
HW_REGION_NAME
/
HUAWEI_CLOUD_REGION
读取区域(或默认使用
cn-north-4
)来设置
--cli-region
,但认证始终来自
hcloud configure
。只需通过
hcloud configure
配置一次凭证,脚本即可正常工作。
若输出中无有效配置,请停止操作并引导用户进行配置。 hcloud参数格式要求 hcloud(KooCLI)所有参数必须使用
--param=value
格式
(等号连接),不支持空格分隔 ✅ 正确格式:
hcloud CES ListAlarmRules --cli-region=cn-north-4
❌ 错误格式:
hcloud CES ListAlarmRules --cli-region cn-north-4
本技能提供8个Shell脚本,封装了常用的hcloud命令,支持批量操作和格式化输出。
<details> <summary>**脚本列表及使用示例(点击展开)**</summary>
脚本功能hcloud命令
list_ecs.sh
查询ECS实例列表
hcloud ECS ListServersDetails
list_alarms.sh
查询告警规则列表
hcloud CES ListAlarmRules
create_alert_rules.sh
批量创建告警规则
hcloud CES CreateAlarmRules
batch_query_metrics.sh
批量查询监控数据
hcloud CES ShowMetricData
list_subscriptions.sh
查询SMN主题和订阅
hcloud SMN ListTopics/Subscriptions
manage_notifications.sh
管理SMN订阅
hcloud SMN Subscribe/Unsubscribe
update_alarm_notifications.sh
更新告警通知配置
hcloud CES UpdateAlarmNotifications
使用示例:
bash

# 查询ECS实例

./scripts/list_ecs.sh                          # 查询所有ECS
./scripts/list_ecs.sh --name ecs-001           # 按名称过滤
./scripts/list_ecs.sh --output json            # 以JSON格式输出
./scripts/list_ecs.sh --output ids             # 仅输出ECS ID列表

# 查询告警规则

./scripts/list_alarms.sh                       # 查询所有告警
./scripts/list_alarms.sh --name-pattern "cpu.*"  # 按名称模式过滤
./scripts/list_alarms.sh --output ids          # 仅输出告警ID列表

# 创建告警规则

./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002
./scripts/create_alert_rules.sh --metric cpu_util --threshold 80 --ecs-ids ecs-001
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001 --smn-topic-urn
urn:smn:cn-north-4:xxx:ECS_ALARM_NOTIFY
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001 --dry-run  # 试运行
</details>

Core Capabilities

核心功能

  • Batch Create Alarm Rules: Support template-based creation (Web/Database scenarios) or custom metric/threshold configuration
  • Batch Query Monitoring Data: Support multi-ECS concurrent query, output CPU/Memory/Disk metrics
  • Notification Configuration: Support email/SMS/WeChat notification, SMN subscription management
  • Security Compliance: AK/SK via environment variables or CLI config, never hardcode
  • 批量创建告警规则:支持基于模板(Web/数据库场景)或自定义指标/阈值配置
  • 批量查询监控数据:支持多ECS并发查询,输出CPU/内存/磁盘指标
  • 通知配置:支持邮件/短信/微信通知,SMN订阅管理
  • 安全合规:通过环境变量或CLI配置AK/SK,绝不硬编码

Usage Scenarios

使用场景

Scenario 1: Batch Configure Alarms for New ECS

场景1:为新ECS批量配置告警

Background: Purchased 10 new ECS instances, need to configure CPU/Memory alarm rules for all.
Steps:
  1. Query ECS instance IDs
  2. Batch create alarm rules using web template
  3. Configure email notification
bash
undefined
背景:采购了10台新ECS实例,需要为所有实例配置CPU/内存告警规则。
步骤:
  1. 查询ECS实例ID
  2. 使用Web模板批量创建告警规则
  3. 配置邮件通知
bash
undefined

Step 0: Configure credentials once (hcloud CLI reads ~/.hcloud/config.json; it does NOT read AK/SK env vars)

步骤0:一次性配置凭证(hcloud CLI读取~/.hcloud/config.json;不读取AK/SK环境变量)

hcloud configure
hcloud configure

Optional: set region env var consumed by the scripts' --cli-region default

可选:设置区域环境变量,作为脚本--cli-region的默认值

export HUAWEI_CLOUD_REGION=cn-north-4 ./scripts/list_ecs.sh --output ids
export HUAWEI_CLOUD_REGION=cn-north-4 ./scripts/list_ecs.sh --output ids

2. Batch create alarm rules

2. 批量创建告警规则

./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002,ecs-003
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002,ecs-003

3. Configure notification

3. 配置通知

./scripts/manage_notifications.sh --action subscribe --topic-urn <SMN_TOPIC_URN> --protocol email --endpoint user@example.com
undefined
./scripts/manage_notifications.sh --action subscribe --topic-urn <SMN_TOPIC_URN> --protocol email --endpoint user@example.com
undefined

Scenario 2: Query Monitoring Data for Multiple ECS

场景2:查询多台ECS的监控数据

Background: Need to check CPU utilization for 5 ECS instances over the past hour.
bash
./scripts/batch_query_metrics.sh \
  --ecs-ids ecs-001,ecs-002,ecs-003,ecs-004,ecs-005 \
  --metric cpu_util \
  --from 2024-01-01T10:00:00Z \
  --to 2024-01-01T11:00:00Z \
  --output table
背景:需要查看过去1小时内5台ECS实例的CPU使用率。
bash
./scripts/batch_query_metrics.sh \
  --ecs-ids ecs-001,ecs-002,ecs-003,ecs-004,ecs-005 \
  --metric cpu_util \
  --from 2024-01-01T10:00:00Z \
  --to 2024-01-01T11:00:00Z \
  --output table

Input Parameters

输入参数

  • AK/SK: Via
    hcloud configure
    (recommended, stored in
    ~/.hcloud/config.json
    ) — hcloud CLI does NOT read AK/SK environment variables
  • Security Token (optional): For temporary STS credentials, use
    hcloud configure --cli-mode=AKSK
    +
    --cli-security-token
    or pass
    --cli-security-token=<token>
    per command
  • Region: Via
    --cli-region
    parameter or
    HUAWEI_CLOUD_REGION
    /
    HW_REGION_NAME
    env var (default: cn-north-4)
  • ECS IDs: Comma-separated ECS instance IDs
  • Alarm IDs: Comma-separated alarm rule IDs
  • Template: Alarm template (web/database)
  • Metric: Monitoring metric name. Host metrics:
    cpu_util
    ,
    disk_util_inband
    (namespace SYS.ECS); memory metric:
    mem_usedPercent
    (namespace AGT.ECS)
  • Threshold: Alarm threshold value
  • SMN Topic URN: SMN topic URN for notifications
  • AK/SK:通过
    hcloud configure
    配置(推荐,存储于
    ~/.hcloud/config.json
    )——hcloud CLI不读取AK/SK环境变量
  • 安全令牌(可选):对于临时STS凭证,使用
    hcloud configure --cli-mode=AKSK
    +
    --cli-security-token
    ,或在每个命令中传入
    --cli-security-token=<token>
  • 区域:通过
    --cli-region
    参数或
    HUAWEI_CLOUD_REGION
    /
    HW_REGION_NAME
    环境变量设置(默认:cn-north-4)
  • ECS IDs:逗号分隔的ECS实例ID列表
  • Alarm IDs:逗号分隔的告警规则ID列表
  • 模板:告警模板(web/database)
  • 指标:监控指标名称。主机指标:
    cpu_util
    disk_util_inband
    (命名空间SYS.ECS);内存指标:
    mem_usedPercent
    (命名空间AGT.ECS)
  • 阈值:告警阈值
  • SMN主题URN:用于通知的SMN主题URN

Parameter Confirmation

参数确认

All write operations (Create / Update / Delete) must explicitly show operation content and obtain user confirmation before execution.
Operation TypeScriptContent to Confirm
Create
create_alert_rules.sh
Target ECS ID list, alarm template/metric/threshold
Create
manage_notifications.sh --action create
Subscription protocol, endpoint address, SMN topic URN
Create
create_email_subscription.sh
Email address, SMN topic URN
Update
update_alarm_notifications.sh
Alarm ID, SMN topic URN, operation type
Delete
manage_notifications.sh --action delete
Subscription URN (irreversible after deletion)
Query operations (list_ecs / list_alarms / list_subscriptions / batch_query_metrics) are read-only and do not require confirmation.
所有写入操作(创建/更新/删除)必须明确展示操作内容,并在执行前获得用户确认。
操作类型脚本需确认内容
创建
create_alert_rules.sh
目标ECS ID列表、告警模板/指标/阈值
创建
manage_notifications.sh --action create
订阅协议、端点地址、SMN主题URN
创建
create_email_subscription.sh
邮箱地址、SMN主题URN
更新
update_alarm_notifications.sh
告警ID、SMN主题URN、操作类型
删除
manage_notifications.sh --action delete
订阅URN(删除后不可逆)
查询操作(list_ecs / list_alarms / list_subscriptions / batch_query_metrics)为只读操作,无需确认。

Output Format

输出格式

  • Table: Formatted table output (default)
  • JSON: JSON format for programmatic processing
  • IDs: Only ID list for scripting
  • 表格:格式化表格输出(默认)
  • JSON:JSON格式,供程序处理
  • IDs:仅输出ID列表,用于脚本调用

Verification Method

验证方法

After executing any operation, verify using the following methods:
  1. List Alarms:
    ./scripts/list_alarms.sh --name-pattern <pattern>
  2. Query Metrics:
    ./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util
  3. Check Notifications:
    ./scripts/list_subscriptions.sh
See references/troubleshooting.md for common verification issues.
执行任何操作后,可通过以下方法验证:
  1. 列出告警
    ./scripts/list_alarms.sh --name-pattern <pattern>
  2. 查询指标
    ./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util
  3. 检查通知
    ./scripts/list_subscriptions.sh
常见验证问题请查看references/troubleshooting.md

Best Practices

最佳实践

  1. Use Templates for Standard Scenarios: Web/Database templates cover most use cases
  2. Configure Multiple Notification Channels: Email + SMS for critical alarms
  3. Set Reasonable Thresholds: CPU 80%, Memory 85%, Disk 90% recommended
  4. Configure Credentials via
    hcloud configure
    (hcloud CLI reads
    ~/.hcloud/config.json
    ; it does NOT read AK/SK env vars):
    • ✅ Recommended:
      hcloud configure
      (encrypted storage in
      ~/.hcloud/config.json
      )
    • ⚠️ Region env var only:
      HUAWEI_CLOUD_REGION
      /
      HW_REGION_NAME
      set the script's
      --cli-region
      default — region only, NOT authentication
    • ❌ Prohibited: Hardcode AK/SK in scripts or configuration files
    • ❌ Misleading:
      export HUAWEI_CLOUD_AK/SK
      or
      export HW_ACCESS_KEY/SECRET_KEY
      will NOT authenticate hcloud (env vars are ignored)
  5. Use Environment Check Script: Run
    ./scripts/check_env.sh
    before first use to verify configuration
  1. 标准场景使用模板:Web/数据库模板覆盖大多数使用场景
  2. 配置多通知渠道:关键告警使用邮件+短信通知
  3. 设置合理阈值:推荐CPU 80%、内存85%、磁盘90%
  4. 通过
    hcloud configure
    配置凭证
    (hcloud CLI读取
    ~/.hcloud/config.json
    ;不读取AK/SK环境变量):
    • ✅ 推荐:
      hcloud configure
      (凭证加密存储于
      ~/.hcloud/config.json
    • ⚠️ 仅区域环境变量:
      HUAWEI_CLOUD_REGION
      /
      HW_REGION_NAME
      设置脚本
      --cli-region
      的默认值——仅用于区域,不用于认证
    • ❌ 禁止:在脚本或配置文件中硬编码AK/SK
    • ❌ 误导:
      export HUAWEI_CLOUD_AK/SK
      export HW_ACCESS_KEY/SECRET_KEY
      无法认证hcloud(环境变量会被忽略)
  5. 使用环境检查脚本:首次使用前执行
    ./scripts/check_env.sh
    验证配置

Common Issues

常见问题

Issue 1: hcloud Command Not Found

问题1:hcloud命令未找到

Solution: Install KooCLI, see references/cli-installation-guide.md
解决方案:安装KooCLI,请查看references/cli-installation-guide.md

Issue 2: 403 Forbidden

问题2:403 Forbidden

Solution: Check IAM permissions, ensure
CES FullAccess
and
SMN FullAccess
policies are granted. See references/iam-policies.md
解决方案:检查IAM权限,确保已授予
CES FullAccess
SMN FullAccess
策略。请查看references/iam-policies.md

Issue 3: Alarm Creation Fails

问题3:告警创建失败

Solution: Check metric name and threshold range. CPU/Memory thresholds should be 0-100.
解决方案:检查指标名称和阈值范围。CPU/内存阈值应在0-100之间。

Issue 4: No Monitoring Data

问题4:无监控数据

Solution: Check ECS instance status and metric collection interval. Data may have 5-minute delay.
See references/troubleshooting.md for more troubleshooting guides.
解决方案:检查ECS实例状态和指标采集间隔。数据可能存在5分钟延迟。
更多故障排查指南请查看references/troubleshooting.md

Important Notes

重要说明

CLI Version Requirement: Must use hcloud CLI v7.2.2 or later. Older versions may not support certain API parameter formats.
Region Consistency: All operations must specify the same region (
--cli-region
or
HUAWEI_CLOUD_REGION
environment variable). Cross-region operations will fail.
Alarm Threshold Range: CPU/memory utilization thresholds must be between 0-100. Disk usage threshold is recommended to be set between 80-95.
Monitoring Data Delay: CES monitoring data typically has a 5-minute delay. Querying real-time data may return empty results.
SMN Subscription Creation:
  • Recommended: Use
    ./scripts/create_email_subscription.sh
    script, which automatically uses hcloud CLI configured credentials (no need to manually set environment variables)
  • Alternative: Use Huawei Cloud Console (SMN → Topics → Subscribe) for subscription creation
  • ⚠️ Note: Email/SMS subscriptions require confirmation before receiving notifications. Check your email and click the confirmation link.
See references/smn-subscription-guide.md for detailed guide.
Batch Operation Limits: Single batch creation is recommended for no more than 20 ECS instances. Too many instances may cause API timeout.
Credential Security:
  • ✅ Recommended: Use
    hcloud configure
    — credentials stored encrypted in
    ~/.hcloud/config.json
    , which is the ONLY credential source hcloud CLI reads
  • ⚠️ Region env var only (NOT auth):
    HUAWEI_CLOUD_REGION
    /
    HW_REGION_NAME
    set the scripts'
    --cli-region
    default
  • ❌ Misleading:
    export HW_ACCESS_KEY/HW_SECRET_KEY
    or
    export HUAWEI_CLOUD_AK/HUAWEI_CLOUD_SK
    do NOT authenticate hcloud (env vars are ignored)
  • ❌ Prohibited: Hardcode AK/SK in scripts or configuration files
Authentication: hcloud CLI authenticates ONLY via
~/.hcloud/config.json
(from
hcloud configure
) or
--cli-access-key
/
--cli-secret-key
per-command arguments. Environment variables for AK/SK/token are silently ignored. Do not document env-var export as a working authentication method.
CLI版本要求:必须使用hcloud CLI v7.2.2或更高版本。旧版本可能不支持某些API参数格式。
区域一致性:所有操作必须指定相同区域(
--cli-region
HUAWEI_CLOUD_REGION
环境变量)。跨区域操作会失败。
告警阈值范围:CPU/内存使用率阈值必须在0-100之间。磁盘使用率阈值建议设置在80-95之间。
监控数据延迟:CES监控数据通常存在5分钟延迟。查询实时数据可能返回空结果。
SMN订阅创建:
  • 推荐:使用
    ./scripts/create_email_subscription.sh
    脚本,自动使用hcloud CLI配置的凭证(无需手动设置环境变量)
  • 替代方案:使用华为云控制台(SMN → 主题 → 订阅)创建订阅
  • ⚠️ 注意:邮件/短信订阅需确认后才能接收通知。请检查邮箱并点击确认链接。
详细指南请查看references/smn-subscription-guide.md
批量操作限制:单次批量创建建议不超过20台ECS实例。实例过多可能导致API超时。
凭证安全:
  • ✅ 推荐:使用
    hcloud configure
    ——凭证加密存储于
    ~/.hcloud/config.json
    ,这是hcloud CLI唯一读取的凭证来源
  • ⚠️ 仅区域环境变量(不用于认证):
    HUAWEI_CLOUD_REGION
    /
    HW_REGION_NAME
    设置脚本
    --cli-region
    的默认值
  • ❌ 误导:
    export HW_ACCESS_KEY/HW_SECRET_KEY
    export HUAWEI_CLOUD_AK/HUAWEI_CLOUD_SK
    无法认证hcloud(环境变量会被忽略)
  • ❌ 禁止:在脚本或配置文件中硬编码AK/SK
认证说明:hcloud CLI仅通过
~/.hcloud/config.json
(来自
hcloud configure
)或每个命令的
--cli-access-key
/
--cli-secret-key
参数进行认证。AK/SK/令牌的环境变量会被静默忽略。请勿将导出环境变量作为有效的认证方法进行文档记录。

Reference Documents

参考文档

  • CLI Installation Guide
  • IAM Policies
  • Related APIs
  • Troubleshooting
  • SMN Subscription Guide
  • Common Commands
  • Memory Monitoring Guide
  • Acceptance Criteria
  • CLI安装指南
  • IAM策略
  • 相关API
  • 故障排查
  • SMN订阅指南
  • 常用命令
  • 内存监控指南
  • 验收标准