npx skills add ...
npx skills add huaweicloud/huaweicloud-skills --skill huawei-cloud-ecs-alert
Automate batch creation and management of Huawei Cloud CES alarm rules for ECS instances using hcloud CLI v7.2.2+. Use this skill to: (1) batch create alarms with templates (web/database), (2) update SMN notifications, (3) query ECS metrics and alarm lists.
npx skills add huaweicloud/huaweicloud-skills --skill huawei-cloud-ecs-alert
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:
Use Cases:
Security Constraints:
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 | DeleteAlarm / hcloud CES DeleteAlarm | 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. Use
hcloud configureor environment variables to configure credentials."
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 | 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 . Use the Huawei Cloud CES/SMN console, or the equivalent hcloud CLI command manually: . You may also request an enhancement via the skill's issue tracker."
The standard workflow of this skill is as follows:
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.
Prerequisite 1: Huawei Cloud CLI (hcloud / KooCLI) >= 7.2.2 Run
hcloud versionto verify version >= 7.2.2. If not installed or version is too low, see references/cli-installation-guide.md for installation guide.
Prerequisite 2: Huawei Cloud Credentials Configured Check if CLI configuration contains valid credentials (AK/SK, IAM, etc.).
Credential Configuration Methods (choose one):
hcloud CLI configuration (recommended):
hcloud configureinteractive setup, credentials encrypted and stored in~/.hcloud/config.jsonPer-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(fromhcloud configure) or the--cli-access-key/--cli-secret-keyarguments. It does NOT readHW_ACCESS_KEY,HW_SECRET_KEY,HUAWEI_CLOUD_AK,HUAWEI_CLOUD_SK,HUAWEI_CLOUD_REGION, orHUAWEI_CLOUD_SECURITY_TOKENenvironment 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 tocn-north-4) to set--cli-region, but authentication always comes fromhcloud configure. Configure credentials once withhcloud 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=valueformat (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-4This skill provides 8 Shell scripts, encapsulating common hcloud commands, supporting batch operations and formatted output.
**Script List and Usage Examples (Click to Expand)**
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 AddSubscription / BatchDeleteSubscriptionsupdate_alarm_notifications.shUpdate alarm notification configuration hcloud CES UpdateAlarmNotificationsUsage Examples:
Background: Purchased 10 new ECS instances, need to configure CPU/Memory alarm rules for all.
Steps:
Background: Need to check CPU utilization for 5 ECS instances over the past hour.
hcloud configure (recommended, stored in ~/.hcloud/config.json) — hcloud CLI does NOT read AK/SK environment variableshcloud configure --cli-mode=AKSK + --cli-security-token or pass --cli-security-token=<token> per command--cli-region parameter or HUAWEI_CLOUD_REGION/HW_REGION_NAME env var (default: cn-north-4)cpu_util, disk_util_inband (namespace SYS.ECS); memory metric: mem_usedPercent (namespace AGT.ECS)All write operations (Create / Update / Delete) must explicitly show operation content and obtain user confirmation before execution.
| Operation Type | Script | Content 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.
After executing any operation, verify using the following methods:
./scripts/list_alarms.sh --name <pattern>./scripts/batch_query_metrics.sh --ecs-ids <ids> --metric cpu_util./scripts/list_subscriptions.shSee references/troubleshooting.md for common verification issues.
hcloud configure (hcloud CLI reads ~/.hcloud/config.json; it does NOT read AK/SK env vars):
hcloud configure (encrypted storage in ~/.hcloud/config.json)HUAWEI_CLOUD_REGION / HW_REGION_NAME set the script's --cli-region default — region only, NOT authenticationexport HUAWEI_CLOUD_AK/SK or export HW_ACCESS_KEY/SECRET_KEY will NOT authenticate hcloud (env vars are ignored)./scripts/check_env.sh before first use to verify configurationSolution: Install KooCLI, see references/cli-installation-guide.md
Solution: Check IAM permissions, ensure CES FullAccess and SMN FullAccess policies are granted. See
references/iam-policies.md
Solution: Check metric name and threshold range. CPU/Memory thresholds should be 0-100.
Solution: Check ECS instance status and metric collection interval. Data may have 5-minute delay.
See references/troubleshooting.md for more troubleshooting guides.
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-regionorHUAWEI_CLOUD_REGIONenvironment 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.shscript, 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_NAMEset the scripts'--cli-regiondefault- ❌ Misleading:
export HW_ACCESS_KEY/HW_SECRET_KEYorexport HUAWEI_CLOUD_AK/HUAWEI_CLOUD_SKdo 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(fromhcloud configure) or--cli-access-key/--cli-secret-keyper-command arguments. Environment variables for AK/SK/token are silently ignored. Do not document env-var export as a working authentication method.
# Batch create alarm rules (WARNING: confirm target ECS and alarm template)
./scripts/create_alert_rules.sh --template web --ecs-ids ecs-001,ecs-002
# Create SMN subscription (WARNING: confirm subscription endpoint and topic)
./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># Update alarm notification config (WARNING: confirm alarm ID and notification topic)
./scripts/update_alarm_notifications.sh --action add --alarm-id <id> --smn-topic-urn <URN>
# Delete SMN subscription (WARNING: confirm subscription URN)
./scripts/manage_notifications.sh --action delete --subscription-urn <URN>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)
hcloud version