huawei-cloud-ecs-alert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHuawei 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 Operation | API/Command | Reason |
|---|---|---|
| Expose AK/SK | Any command that outputs AK/SK in plaintext | Account security risk |
| Accept AK/SK from user | Receiving credentials in conversation | Violates security best practices |
| ❌ Delete alarm rule | | Irreversible; deleted alarms cannot be recovered, may cause monitoring gaps |
| ❌ Batch delete alarms | Any batch deletion operation | High 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. Useor environment variables to configure credentials."hcloud configure
以下操作严格禁止,即使用户要求也不得执行:
| 禁止操作 | API/命令 | 原因 |
|---|---|---|
| 泄露AK/SK | 任何明文输出AK/SK的命令 | 账号安全风险 |
| 接收用户提供的AK/SK | 在对话中接收凭证 | 违反安全最佳实践 |
| ❌ 删除告警规则 | | 操作不可逆;删除的告警无法恢复,可能导致监控缺口 |
| ❌ 批量删除告警 | 任何批量删除操作 | 高风险;可能误删关键监控规则 |
若用户请求删除操作,必须拒绝并引导: "根据安全约束,本技能不支持删除操作(删除告警/批量删除)。请谨慎使用华为云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 Operation | Corresponding API | Alternative |
|---|---|---|
| Query alarm history | | View in CES console; or run |
| Enable/disable an alarm rule | | Operate in CES console (not wrapped by this skill) |
| Modify alarm threshold/metric | | Delete and recreate the rule; to change only notifications, use |
| Create an SMN topic | | Create in SMN console; or run |
| Create a monitoring dashboard | | Operate in CES console |
| View a single alarm rule detail | | Use |
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 | 替代方案 |
|---|---|---|
| 查询告警历史 | | 在CES控制台查看;或手动执行 |
| 启用/禁用告警规则 | | 在CES控制台操作(本技能未封装) |
| 修改告警阈值/指标 | | 删除并重新创建规则;若仅需修改通知配置,使用 |
| 创建SMN主题 | | 在SMN控制台创建;或手动执行 |
| 创建监控仪表盘 | | 在CES控制台操作 |
| 查看单个告警规则详情 | | 使用 |
若用户请求上述操作,回复: "本技能不支持<操作>。请使用华为云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 metricsWrite 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
undefinedbash
undefinedList 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
undefinedCreate Commands (write operations, require user confirmation)
创建命令(写入操作,需用户确认)
bash
undefinedbash
undefinedBatch 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>
undefinedUpdate/Delete Commands (write operations, require user confirmation)
更新/删除命令(写入操作,需用户确认)
bash
undefinedbash
undefinedUpdate 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>
undefinedArchitecture
架构
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 Runto verify version >= 7.2.2. If not installed or version is too low, see references/cli-installation-guide.md for installation guide.hcloud version
bash
hcloud version
Prerequisite 2: Huawei Cloud Credentials Configured Check if CLI configuration contains valid credentials (AK/SK, IAM, etc.).bashhcloud configure listCredential Configuration Methods (choose one):
hcloud CLI configuration (recommended):interactive setup, credentials encrypted and stored inhcloud configure~/.hcloud/config.json Per-call AK/SK: passon each command (for automation; note: appears in process list)--cli-access-key=<AK> --cli-secret-key=<SK>⚠️ IMPORTANT: hcloud (KooCLI) authenticates ONLY via(from~/.hcloud/config.json) or thehcloud configure/--cli-access-keyarguments. It does NOT read--cli-secret-key,HW_ACCESS_KEY,HW_SECRET_KEY,HUAWEI_CLOUD_AK,HUAWEI_CLOUD_SK, orHUAWEI_CLOUD_REGIONenvironment 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.HUAWEI_CLOUD_SECURITY_TOKENCredential source for this skill's scripts: The bundled Shell scripts are thin wrappers around hcloud CLI. They read the region from/HW_REGION_NAME(or default toHUAWEI_CLOUD_REGION) to setcn-north-4, but authentication always comes from--cli-region. Configure credentials once withhcloud configure, then the scripts work.hcloud configure
If output does not contain valid configuration, stop operation and guide user to configure. hcloud Parameter Format Requirement hcloud (KooCLI) all parameters must useformat (equals sign connection), does not support space separation. ✅ Correct:--param=value❌ Incorrect:hcloud CES ListAlarmRules --cli-region=cn-north-4hcloud CES ListAlarmRules --cli-region cn-north-4This 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>
Script Function hcloud Command list_ecs.shQuery ECS instance list hcloud ECS ListServersDetailslist_alarms.shQuery alarm rule list hcloud CES ListAlarmRulescreate_alert_rules.shBatch create alarm rules hcloud CES CreateAlarmRulesbatch_query_metrics.shBatch query monitoring data hcloud CES ShowMetricDatalist_subscriptions.shQuery SMN topics and subscriptions hcloud SMN ListTopics/Subscriptionsmanage_notifications.shManage SMN subscriptions hcloud SMN Subscribe/Unsubscribeupdate_alarm_notifications.shUpdate alarm notification configuration hcloud CES UpdateAlarmNotificationsUsage 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 执行验证版本是否>=7.2.2。若未安装或版本过低,请查看references/cli-installation-guide.md获取安装指南。hcloud version
bash
hcloud version
前置条件2:已配置华为云凭证 检查CLI配置是否包含有效凭证(AK/SK、IAM等)。bashhcloud configure list凭证配置方式(选其一):
hcloud CLI配置(推荐):执行交互式设置,凭证加密存储于hcloud configure~/.hcloud/config.json 单次调用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环境变量——此类变量会被静默忽略(hcloud会回退到config.json)。请勿指导用户通过导出这些环境变量来认证hcloud。HUAWEI_CLOUD_SECURITY_TOKEN本技能脚本的凭证来源:附带的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-4hcloud CES ListAlarmRules --cli-region cn-north-4本技能提供8个Shell脚本,封装了常用的hcloud命令,支持批量操作和格式化输出。<details> <summary>**脚本列表及使用示例(点击展开)**</summary>
脚本 功能 hcloud命令 list_ecs.sh查询ECS实例列表 hcloud ECS ListServersDetailslist_alarms.sh查询告警规则列表 hcloud CES ListAlarmRulescreate_alert_rules.sh批量创建告警规则 hcloud CES CreateAlarmRulesbatch_query_metrics.sh批量查询监控数据 hcloud CES ShowMetricDatalist_subscriptions.sh查询SMN主题和订阅 hcloud SMN ListTopics/Subscriptionsmanage_notifications.sh管理SMN订阅 hcloud SMN Subscribe/Unsubscribeupdate_alarm_notifications.sh更新告警通知配置 hcloud CES UpdateAlarmNotifications使用示例:</details>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 # 试运行
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:
- Query ECS instance IDs
- Batch create alarm rules using web template
- Configure email notification
bash
undefined背景:采购了10台新ECS实例,需要为所有实例配置CPU/内存告警规则。
步骤:
- 查询ECS实例ID
- 使用Web模板批量创建告警规则
- 配置邮件通知
bash
undefinedStep 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
undefinedScenario 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 (recommended, stored in
hcloud configure) — hcloud CLI does NOT read AK/SK environment variables~/.hcloud/config.json - Security Token (optional): For temporary STS credentials, use +
hcloud configure --cli-mode=AKSKor pass--cli-security-tokenper command--cli-security-token=<token> - Region: Via parameter or
--cli-region/HUAWEI_CLOUD_REGIONenv var (default: cn-north-4)HW_REGION_NAME - 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(namespace SYS.ECS); memory metric:disk_util_inband(namespace AGT.ECS)mem_usedPercent - Threshold: Alarm threshold value
- SMN Topic URN: SMN topic URN for notifications
- AK/SK:通过配置(推荐,存储于
hcloud configure)——hcloud CLI不读取AK/SK环境变量~/.hcloud/config.json - 安全令牌(可选):对于临时STS凭证,使用+
hcloud configure --cli-mode=AKSK,或在每个命令中传入--cli-security-token--cli-security-token=<token> - 区域:通过参数或
--cli-region/HUAWEI_CLOUD_REGION环境变量设置(默认:cn-north-4)HW_REGION_NAME - ECS IDs:逗号分隔的ECS实例ID列表
- Alarm IDs:逗号分隔的告警规则ID列表
- 模板:告警模板(web/database)
- 指标:监控指标名称。主机指标:、
cpu_util(命名空间SYS.ECS);内存指标:disk_util_inband(命名空间AGT.ECS)mem_usedPercent - 阈值:告警阈值
- SMN主题URN:用于通知的SMN主题URN
Parameter Confirmation
参数确认
All write operations (Create / Update / Delete) must explicitly show operation content and obtain user confirmation before execution.
| Operation Type | Script | Content to Confirm |
|---|---|---|
| Create | | Target ECS ID list, alarm template/metric/threshold |
| Create | | Subscription protocol, endpoint address, SMN topic URN |
| Create | | Email address, SMN topic URN |
| Update | | Alarm ID, SMN topic URN, operation type |
| 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.
所有写入操作(创建/更新/删除)必须明确展示操作内容,并在执行前获得用户确认。
| 操作类型 | 脚本 | 需确认内容 |
|---|---|---|
| 创建 | | 目标ECS ID列表、告警模板/指标/阈值 |
| 创建 | | 订阅协议、端点地址、SMN主题URN |
| 创建 | | 邮箱地址、SMN主题URN |
| 更新 | | 告警ID、SMN主题URN、操作类型 |
| 删除 | | 订阅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:
- List Alarms:
./scripts/list_alarms.sh --name-pattern <pattern> - Query Metrics:
./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util - Check Notifications:
./scripts/list_subscriptions.sh
See references/troubleshooting.md for common verification issues.
执行任何操作后,可通过以下方法验证:
- 列出告警:
./scripts/list_alarms.sh --name-pattern <pattern> - 查询指标:
./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util - 检查通知:
./scripts/list_subscriptions.sh
常见验证问题请查看references/troubleshooting.md。
Best Practices
最佳实践
- Use Templates for Standard Scenarios: Web/Database templates cover most use cases
- Configure Multiple Notification Channels: Email + SMS for critical alarms
- Set Reasonable Thresholds: CPU 80%, Memory 85%, Disk 90% recommended
- Configure Credentials via (hcloud CLI reads
hcloud configure; it does NOT read AK/SK env vars):~/.hcloud/config.json- ✅ Recommended: (encrypted storage in
hcloud configure)~/.hcloud/config.json - ⚠️ Region env var only: /
HUAWEI_CLOUD_REGIONset the script'sHW_REGION_NAMEdefault — region only, NOT authentication--cli-region - ❌ Prohibited: Hardcode AK/SK in scripts or configuration files
- ❌ Misleading: or
export HUAWEI_CLOUD_AK/SKwill NOT authenticate hcloud (env vars are ignored)export HW_ACCESS_KEY/SECRET_KEY
- ✅ Recommended:
- Use Environment Check Script: Run before first use to verify configuration
./scripts/check_env.sh
- 标准场景使用模板:Web/数据库模板覆盖大多数使用场景
- 配置多通知渠道:关键告警使用邮件+短信通知
- 设置合理阈值:推荐CPU 80%、内存85%、磁盘90%
- 通过配置凭证(hcloud CLI读取
hcloud configure;不读取AK/SK环境变量):~/.hcloud/config.json- ✅ 推荐:(凭证加密存储于
hcloud configure)~/.hcloud/config.json - ⚠️ 仅区域环境变量:/
HUAWEI_CLOUD_REGION设置脚本HW_REGION_NAME的默认值——仅用于区域,不用于认证--cli-region - ❌ 禁止:在脚本或配置文件中硬编码AK/SK
- ❌ 误导:或
export HUAWEI_CLOUD_AK/SK无法认证hcloud(环境变量会被忽略)export HW_ACCESS_KEY/SECRET_KEY
- ✅ 推荐:
- 使用环境检查脚本:首次使用前执行验证配置
./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 and policies are granted. See
references/iam-policies.md
CES FullAccessSMN FullAccess解决方案:检查IAM权限,确保已授予和策略。请查看references/iam-policies.md
CES FullAccessSMN FullAccessIssue 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 (or--cli-regionenvironment variable). Cross-region operations will fail.HUAWEI_CLOUD_REGION
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
script, which automatically uses hcloud CLI configured credentials (no need to manually set environment variables)./scripts/create_email_subscription.sh- ✅ 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
— credentials stored encrypted inhcloud configure, which is the ONLY credential source hcloud CLI reads~/.hcloud/config.json- ⚠️ Region env var only (NOT auth):
/HUAWEI_CLOUD_REGIONset the scripts'HW_REGION_NAMEdefault--cli-region- ❌ Misleading:
orexport HW_ACCESS_KEY/HW_SECRET_KEYdo NOT authenticate hcloud (env vars are ignored)export HUAWEI_CLOUD_AK/HUAWEI_CLOUD_SK- ❌ Prohibited: Hardcode AK/SK in scripts or configuration files
Authentication: hcloud CLI authenticates ONLY via(from~/.hcloud/config.json) orhcloud configure/--cli-access-keyper-command arguments. Environment variables for AK/SK/token are silently ignored. Do not document env-var export as a working authentication method.--cli-secret-key
CLI版本要求:必须使用hcloud CLI v7.2.2或更高版本。旧版本可能不支持某些API参数格式。
区域一致性:所有操作必须指定相同区域(或--cli-region环境变量)。跨区域操作会失败。HUAWEI_CLOUD_REGION
告警阈值范围:CPU/内存使用率阈值必须在0-100之间。磁盘使用率阈值建议设置在80-95之间。
监控数据延迟:CES监控数据通常存在5分钟延迟。查询实时数据可能返回空结果。
SMN订阅创建:
- ✅ 推荐:使用
脚本,自动使用hcloud CLI配置的凭证(无需手动设置环境变量)./scripts/create_email_subscription.sh- ✅ 替代方案:使用华为云控制台(SMN → 主题 → 订阅)创建订阅
- ⚠️ 注意:邮件/短信订阅需确认后才能接收通知。请检查邮箱并点击确认链接。
详细指南请查看references/smn-subscription-guide.md。
批量操作限制:单次批量创建建议不超过20台ECS实例。实例过多可能导致API超时。
凭证安全:
- ✅ 推荐:使用
——凭证加密存储于hcloud configure,这是hcloud CLI唯一读取的凭证来源~/.hcloud/config.json- ⚠️ 仅区域环境变量(不用于认证):
/HUAWEI_CLOUD_REGION设置脚本HW_REGION_NAME的默认值--cli-region- ❌ 误导:
或export HW_ACCESS_KEY/HW_SECRET_KEY无法认证hcloud(环境变量会被忽略)export HUAWEI_CLOUD_AK/HUAWEI_CLOUD_SK- ❌ 禁止:在脚本或配置文件中硬编码AK/SK
认证说明:hcloud CLI仅通过(来自~/.hcloud/config.json)或每个命令的hcloud configure/--cli-access-key参数进行认证。AK/SK/令牌的环境变量会被静默忽略。请勿将导出环境变量作为有效的认证方法进行文档记录。--cli-secret-key
Reference Documents
参考文档
- CLI Installation Guide
- IAM Policies
- Related APIs
- Troubleshooting
- SMN Subscription Guide
- Common Commands
- Memory Monitoring Guide
- Acceptance Criteria
- CLI安装指南
- IAM策略
- 相关API
- 故障排查
- SMN订阅指南
- 常用命令
- 内存监控指南
- 验收标准