huawei-cloud-eip-cost-optimizer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Huawei Cloud EIP Cost Optimizer

华为云EIP成本优化工具

Overview

概述

This skill provides batch management and cost optimization capabilities for Huawei Cloud Elastic Public IPs (EIPs).
Architecture: Shell + hcloud CLI (KooCLI) → EIP Service API → VPC/Bandwidth resources
Related Skills: For broader cost optimization across all resource types (ECS, EVS, OBS, etc.), see the archived
huaweicloud-cost-optimizer
skill. This skill focuses exclusively on EIP optimization with deeper functionality and 100% hcloud CLI compliance.
  • Periodic cleanup of idle EIPs to reduce holding costs
  • Cost analysis and optimization recommendations
  • Multi-region unified management
  • Automated monitoring and alerting for idle resources
  • Operation audit logging for compliance
Typical Use Cases:
  • "Help me identify idle EIPs and generate an optimization report"
  • "Generate an EIP cost analysis report to identify high-cost resources"
  • "Set up idle EIP monitoring with automatic alerts via webhook or email"
  • "View EIP distribution and status summary across all regions"
  • "Show audit logs for EIP operations in the last 30 days"
  • "List all EIPs in cn-north-4 with detailed information"
本技能为华为云弹性公网IP(EIP)提供批量管理与成本优化能力。
架构:Shell + hcloud CLI(KooCLI)→ EIP服务API → VPC/带宽资源
关联技能:如需针对所有资源类型(ECS、EVS、OBS等)进行更全面的成本优化,请查看归档的
huaweicloud-cost-optimizer
技能。本技能专注于EIP优化,功能更深入且100%符合hcloud CLI规范。
  • 定期清理闲置EIP以降低持有成本
  • 成本分析与优化建议
  • 多地域统一管理
  • 闲置资源自动化监控与告警
  • 操作审计日志以满足合规要求
典型使用场景
  • "帮我识别闲置EIP并生成优化报告"
  • "生成EIP成本分析报告,找出高成本资源"
  • "配置闲置EIP监控,通过Webhook或邮件自动告警"
  • "查看所有地域的EIP分布与状态汇总"
  • "展示过去30天的EIP操作审计日志"
  • "列出cn-north-4地域的所有EIP及详细信息"

Prerequisites

前置条件

1. CLI Environment Requirements (MANDATORY)

1. CLI环境要求(必填)

  • hcloud CLI (KooCLI) v7.0+ — Huawei Cloud command-line tool
  • jq — JSON processor for parsing API responses
  • bc — Arbitrary precision calculator for cost estimation
  • curl — HTTP client for webhook notifications
Install hcloud CLI:
bash
undefined
  • hcloud CLI(KooCLI) v7.0+ — 华为云命令行工具
  • jq — 用于解析API响应的JSON处理器
  • bc — 用于成本估算的任意精度计算器
  • curl — 用于Webhook通知的HTTP客户端
安装hcloud CLI
bash
undefined

Linux/macOS one-click install

Linux/macOS一键安装

Verify installation

验证安装

hcloud --version

**Install jq, bc, curl**:

```bash
hcloud --version

**安装jq、bc、curl**:

```bash

Ubuntu/Debian

Ubuntu/Debian

sudo apt install -y jq bc curl
sudo apt install -y jq bc curl

CentOS/RHEL

CentOS/RHEL

sudo yum install -y jq bc curl
sudo yum install -y jq bc curl

macOS

macOS

brew install jq bc curl

**Available Shell Scripts**:

- `scripts/config.sh` - Shared configuration (credentials, regions, proxy)
- `scripts/list_eips.sh` - List all EIPs in a region (supports filtering and summary)
- `scripts/analyze_idle_eips.sh` - Analyze idle EIPs and generate optimization reports (read-only)
- `scripts/eip_cost_report.sh` - Generate EIP cost analysis reports (text/HTML/JSON)
- `scripts/monitor_idle_eips.sh` - Monitor idle EIPs with webhook/email alerts and cron support
- `scripts/check_env.sh` - Environment check and validation (hcloud CLI + tools + API)
- `scripts/eip_audit_log.sh` - Operation audit logging (JSONL + CSV/JSON export)

**Note**: All scripts are READ-ONLY. This skill does NOT perform bandwidth adjustment, tag management, or EIP release/deletion.
brew install jq bc curl

**可用Shell脚本**:

- `scripts/config.sh` - 共享配置(凭证、地域、代理)
- `scripts/list_eips.sh` - 列出某地域的所有EIP(支持过滤与汇总)
- `scripts/analyze_idle_eips.sh` - 分析闲置EIP并生成优化报告(只读)
- `scripts/eip_cost_report.sh` - 生成EIP成本分析报告(文本/HTML/JSON格式)
- `scripts/monitor_idle_eips.sh` - 配置闲置EIP监控,支持Webhook/邮件告警及定时任务
- `scripts/check_env.sh` - 环境检查与验证(hcloud CLI + 工具 + API)
- `scripts/eip_audit_log.sh` - 操作审计日志(支持JSONL + CSV/JSON导出)

**注意**:所有脚本均为只读模式。本技能不执行带宽调整、标签管理或EIP释放/删除操作。

2. Authentication Configuration

2. 认证配置

This skill supports one authentication path via environment variables:
本技能仅支持通过环境变量进行认证:

Environment Variables

环境变量

bash
export HW_ACCESS_KEY=<your-ak>
export HW_SECRET_KEY=<your-sk>
export HW_REGION_NAME=cn-north-4
Note: If you have already configured
hcloud configure
interactively (entering credentials via prompts, not command-line arguments), the skill will also detect and use those credentials.
Environment Variables:
VariableRequiredDescription
HW_ACCESS_KEY
OptionalHuawei Cloud Access Key ID (required only if hcloud configure not set)
HW_SECRET_KEY
OptionalHuawei Cloud Secret Access Key (required only if hcloud configure not set)
HW_REGION_NAME
OptionalDefault region (default:
cn-north-4
)
HW_SECURITY_TOKEN
OptionalSecurity token for temporary credentials
Security Notes:
  • Never commit credentials to version control
  • Never expose AK/SK values in code, conversation, or commands
  • Never pass AK/SK values as command-line arguments (exposes credentials in shell history and
    ps aux
    )
  • Use IAM users with minimal required permissions
  • Enable MFA for sensitive operations
  • Rotate AK/SK regularly
  • Use
    ./scripts/check_env.sh
    to validate credentials before running scripts
bash
export HW_ACCESS_KEY=<你的AK>
export HW_SECRET_KEY=<你的SK>
export HW_REGION_NAME=cn-north-4
注意:如果已通过交互式方式配置
hcloud configure
(通过提示输入凭证,而非命令行参数),本技能也会检测并使用这些凭证。
环境变量说明
变量名必填性描述
HW_ACCESS_KEY
可选华为云访问密钥ID(仅当未配置hcloud configure时需要)
HW_SECRET_KEY
可选华为云秘密访问密钥(仅当未配置hcloud configure时需要)
HW_REGION_NAME
可选默认地域(默认值:
cn-north-4
HW_SECURITY_TOKEN
可选临时凭证的安全令牌
安全注意事项
  • 切勿将凭证提交至版本控制系统
  • 切勿在代码、对话或命令中暴露AK/SK值
  • 切勿将AK/SK作为命令行参数传递(会在Shell历史记录和
    ps aux
    中暴露凭证)
  • 使用权限最小化的IAM用户
  • 为敏感操作启用MFA
  • 定期轮换AK/SK
  • 在运行脚本前使用
    ./scripts/check_env.sh
    验证凭证

3. Quick Start

3. 快速开始

bash
undefined
bash
undefined

Step 1: Configure authentication via environment variables

步骤1:通过环境变量配置认证

export HW_ACCESS_KEY=<your-ak> export HW_SECRET_KEY=<your-sk> export HW_REGION_NAME=cn-north-4
export HW_ACCESS_KEY=<你的AK> export HW_SECRET_KEY=<你的SK> export HW_REGION_NAME=cn-north-4

Step 2: Run environment check

步骤2:运行环境检查

bash scripts/check_env.sh
bash scripts/check_env.sh

Step 3: Run scripts

步骤3:运行脚本

bash scripts/list_eips.sh --region cn-north-4 bash scripts/analyze_idle_eips.sh --idle-days 7 bash scripts/eip_cost_report.sh --format html
undefined
bash scripts/list_eips.sh --region cn-north-4 bash scripts/analyze_idle_eips.sh --idle-days 7 bash scripts/eip_cost_report.sh --format html
undefined

4. IAM Permission Requirements

4. IAM权限要求

Note: This skill is READ-ONLY for EIP resources. It does NOT perform any write operations.
API ActionPermissionPurpose
vpc:publicIps:list
List EIPsQuery all EIPs and their status
vpc:publicIps:get
Get EIP detailsView individual EIP information
注意:本技能仅对EIP资源具有只读权限,不执行任何写入操作。
API操作权限用途
vpc:publicIps:list
列出EIP查询所有EIP及其状态
vpc:publicIps:get
获取EIP详情查看单个EIP的信息

Workflow

工作流程

Main Steps

主要步骤

  1. Environment Check → Verify hcloud CLI, jq, credentials
  2. EIP Query → List EIPs across regions via hcloud CLI
  3. Idle Analysis → Identify unbound EIPs exceeding idle threshold
  4. Cost Report → Generate HTML/JSON cost analysis report
  5. Monitoring Setup → Configure idle EIP alerts (webhook/email)
  6. Audit Logging → Record operations for compliance
  1. 环境检查 → 验证hcloud CLI、jq及凭证
  2. EIP查询 → 通过hcloud CLI跨地域列出EIP
  3. 闲置分析 → 识别超过闲置阈值的未绑定EIP
  4. 成本报告 → 生成HTML/JSON格式的成本分析报告
  5. 监控配置 → 配置闲置EIP告警(Webhook/邮件)
  6. 审计日志 → 记录操作以满足合规要求

EIP Query Workflow

EIP查询流程

List EIPs across regions, filter by status, output as JSON/table.
跨地域列出EIP,按状态过滤,以JSON/表格形式输出。

Idle EIP Analysis Workflow

闲置EIP分析流程

Detect unbound EIPs idle beyond threshold, calculate holding costs, generate optimization report.
检测超过阈值的未绑定闲置EIP,计算持有成本,生成优化报告。

Cost Report Workflow

成本报告流程

Aggregate EIP cost data, render as HTML or JSON report with savings recommendations.
汇总EIP成本数据,生成带节省建议的HTML或JSON报告。

Idle EIP Monitoring Workflow

闲置EIP监控流程

Periodically check for idle EIPs, send alerts via webhook or email when detected.
定期检查闲置EIP,检测到后通过Webhook或邮件发送告警。

Audit Log Workflow

审计日志流程

All EIP operations (list/analyze/report/monitor) automatically write to the audit log file for compliance. Each script records its own action on exit. Query history with
--action query-log --days N
.
All EIP operations use hcloud CLI commands:
Python SDK Methodhcloud CLI CommandDescription
EipClient.list_publicips()
hcloud EIP ListPublicips/v2 --cli-region=<region>
List all EIPs
EipClient.show_publicip()
hcloud EIP ShowPublicip/v2 --publicip_id=<id>
Get EIP details
IamClient.keystone_list_projects()
hcloud IAM KeystoneListProjects
List projects
Output format: All commands use
--cli-output=json
for machine-readable output, parsed by
jq
.
所有EIP操作(列出/分析/报告/监控)都会自动写入审计日志文件以满足合规要求。每个脚本退出时都会记录自身操作。使用
--action query-log --days N
查询历史记录。
所有EIP操作均使用hcloud CLI命令:
Python SDK方法hcloud CLI命令描述
EipClient.list_publicips()
hcloud EIP ListPublicips/v2 --cli-region=<region>
列出所有EIP
EipClient.show_publicip()
hcloud EIP ShowPublicip/v2 --publicip_id=<id>
获取EIP详情
IamClient.keystone_list_projects()
hcloud IAM KeystoneListProjects
列出项目
输出格式:所有命令使用
--cli-output=json
生成机器可读输出,由
jq
解析。

Core Commands

核心命令

CommandDescriptionBackend
list_eips.sh
List and query EIPs across regionshcloud CLI
analyze_idle_eips.sh
Identify idle/unbound EIPs with cost analysishcloud CLI
eip_cost_report.sh
Generate HTML/JSON cost analysis reportshcloud CLI
monitor_idle_eips.sh
Set up idle EIP monitoring with alertshcloud CLI
eip_audit_log.sh
Maintain operation audit logsShell
check_env.sh
Verify environment prerequisitesShell
config.sh
Load configuration and credentialsShell
命令描述后端
list_eips.sh
跨地域列出并查询EIPhcloud CLI
analyze_idle_eips.sh
识别闲置/未绑定EIP并进行成本分析hcloud CLI
eip_cost_report.sh
生成HTML/JSON格式的成本分析报告hcloud CLI
monitor_idle_eips.sh
配置闲置EIP监控与告警hcloud CLI
eip_audit_log.sh
维护操作审计日志Shell
check_env.sh
验证环境前置条件Shell
config.sh
加载配置与凭证Shell

EIP Query

EIP查询

bash
undefined
bash
undefined

List all EIPs in a region

列出某地域的所有EIP

bash scripts/list_eips.sh --region cn-north-4
bash scripts/list_eips.sh --region cn-north-4

List EIPs with status filter

按状态过滤列出EIP

bash scripts/list_eips.sh --region cn-north-4 --status DOWN
bash scripts/list_eips.sh --region cn-north-4 --status DOWN

List EIPs across multiple regions

列出多个地域的EIP

bash scripts/list_eips.sh --region cn-north-4,cn-east-3,cn-south-1
undefined
bash scripts/list_eips.sh --region cn-north-4,cn-east-3,cn-south-1
undefined

Idle EIP Analysis

闲置EIP分析

bash
undefined
bash
undefined

Analyze idle EIPs (default threshold: 0 days = all unbound)

分析闲置EIP(默认阈值:0天 = 所有未绑定EIP)

bash scripts/analyze_idle_eips.sh
bash scripts/analyze_idle_eips.sh

Custom idle threshold (14 days)

自定义闲置阈值(14天)

bash scripts/analyze_idle_eips.sh --idle-days 14
bash scripts/analyze_idle_eips.sh --idle-days 14

Analyze specific region with JSON output

分析指定地域并输出JSON格式报告

bash scripts/analyze_idle_eips.sh --region cn-north-4 --idle-days 7 --json
undefined
bash scripts/analyze_idle_eips.sh --region cn-north-4 --idle-days 7 --json
undefined

Cost Report

成本报告

bash
undefined
bash
undefined

Generate text cost report (default)

生成文本格式成本报告(默认)

bash scripts/eip_cost_report.sh
bash scripts/eip_cost_report.sh

Generate HTML report

生成HTML格式报告

bash scripts/eip_cost_report.sh --format html
bash scripts/eip_cost_report.sh --format html

Generate JSON report

生成JSON格式报告

bash scripts/eip_cost_report.sh --format json
bash scripts/eip_cost_report.sh --format json

Custom region

指定地域生成报告

bash scripts/eip_cost_report.sh --region cn-east-3 --format html

**Cost Model**: Bandwidth-based pricing (~3 CNY/Mbps/month for cn-north-4 on-demand) + IP retain fee (~0.02 CNY/hour for unbound EIPs). API does not return `charge_mode`, so all estimates use bandwidth billing model.
bash scripts/eip_cost_report.sh --region cn-east-3 --format html

**成本模型**:基于带宽的定价(cn-north-4按需实例约3元/Mbps/月)+ IP保留费(未绑定EIP约0.02元/小时)。API不返回`charge_mode`,因此所有估算均使用带宽计费模型。

Idle EIP Monitoring

闲置EIP监控

bash
undefined
bash
undefined

Monitor idle EIPs (default threshold: 7 days)

监控闲置EIP(默认阈值:7天)

bash scripts/monitor_idle_eips.sh
bash scripts/monitor_idle_eips.sh

Custom threshold

自定义阈值

bash scripts/monitor_idle_eips.sh --idle-days 14
bash scripts/monitor_idle_eips.sh --idle-days 14

Monitor with webhook alert (only DingTalk/WeCom/Slack HTTPS URLs are allowed)

通过Webhook告警(仅允许钉钉/企业微信/Slack的HTTPS地址)

bash scripts/monitor_idle_eips.sh --idle-days 7 --webhook "https://oapi.dingtalk.com/robot/send?access_token=YOUR_ACCESS_TOKEN"
bash scripts/monitor_idle_eips.sh --idle-days 7 --webhook "https://oapi.dingtalk.com/robot/send?access_token=YOUR_ACCESS_TOKEN"

Monitor with email alert

通过邮件告警

bash scripts/monitor_idle_eips.sh --idle-days 7 --email admin@example.com
bash scripts/monitor_idle_eips.sh --idle-days 7 --email admin@example.com

Set up daily cron job (9:00 AM) - REQUIRES webhook or email, otherwise it's rejected.

设置每日定时任务(上午9点)- 必须配置Webhook或邮件,否则会被拒绝。

The cron line embeds the alert parameters so scheduled runs actually notify.

定时任务行嵌入告警参数,以便定时运行时能实际发送通知。

bash scripts/monitor_idle_eips.sh --region cn-north-4 --idle-days 7 --setup-cron
--webhook "https://oapi.dingtalk.com/robot/send?access_token=YOUR_ACCESS_TOKEN"
bash scripts/monitor_idle_eips.sh --region cn-north-4 --idle-days 7 --setup-cron
--webhook "https://oapi.dingtalk.com/robot/send?access_token=YOUR_ACCESS_TOKEN"

Remove cron job

删除定时任务

bash scripts/monitor_idle_eips.sh --remove-cron
undefined
bash scripts/monitor_idle_eips.sh --remove-cron
undefined

Environment Check

环境检查

bash
undefined
bash
undefined

Full environment validation (CLI + tools + API)

完整环境验证(CLI + 工具 + API)

bash scripts/check_env.sh
bash scripts/check_env.sh

Verbose mode (show versions)

详细模式(显示版本信息)

bash scripts/check_env.sh --verbose
bash scripts/check_env.sh --verbose

Auto-fix missing dependencies

自动修复缺失依赖

bash scripts/check_env.sh --fix
undefined
bash scripts/check_env.sh --fix
undefined

Operation Audit Logging

操作审计日志

bash
undefined
bash
undefined

Log an EIP list operation

记录EIP列出操作

bash scripts/eip_audit_log.sh --action list --detail "Queried all EIPs"
bash scripts/eip_audit_log.sh --action list --detail "查询所有EIP"

Log an analyze operation

记录分析操作

bash scripts/eip_audit_log.sh --action analyze --detail "Idle EIP analysis for cn-north-4"
bash scripts/eip_audit_log.sh --action analyze --detail "cn-north-4地域闲置EIP分析"

Export audit logs to CSV

将审计日志导出为CSV格式

bash scripts/eip_audit_log.sh --action list --export csv
bash scripts/eip_audit_log.sh --action list --export csv

Export audit logs to JSON

将审计日志导出为JSON格式

bash scripts/eip_audit_log.sh --action list --export json
bash scripts/eip_audit_log.sh --action list --export json

Custom log directory (must NOT be a system dir; will be created if missing)

自定义日志目录(不能是系统目录;不存在则自动创建)

bash scripts/eip_audit_log.sh --action list --log-dir ~/eip_audit_logs
bash scripts/eip_audit_log.sh --action list --log-dir ~/eip_audit_logs

Query audit history for the last 30 days

查询过去30天的审计历史

bash scripts/eip_audit_log.sh --action query-log --days 30
bash scripts/eip_audit_log.sh --action query-log --days 30

Query audit history for a specific action type

查询特定操作类型的审计历史

bash scripts/eip_audit_log.sh --action query-log --days 7

**Audit Log Entry Format** (JSONL, timezone-aware timestamps):

```json
{
  "timestamp": "2026-07-16T10:30:00+08:00",
  "region": "cn-north-4",
  "action": "list",
  "detail": "Queried all EIPs",
  "user": "root"
}
bash scripts/eip_audit_log.sh --action query-log --days 7

**审计日志条目格式**(JSONL,带时区时间戳):

```json
{
  "timestamp": "2026-07-16T10:30:00+08:00",
  "region": "cn-north-4",
  "action": "list",
  "detail": "查询所有EIP",
  "user": "root"
}

KooCLI Command Format

KooCLI命令格式

bash
undefined
bash
undefined

General format

通用格式

hcloud <Service> <Operation> --cli-region=<region> --param1=value1 --param2=value2
hcloud <服务名> <操作名> --cli-region=<地域> --param1=value1 --param2=value2

EIP list example

EIP列出示例

hcloud EIP ListPublicips/v2 --cli-region=cn-north-4
hcloud EIP ListPublicips/v2 --cli-region=cn-north-4

EIP show detail

EIP详情查询

hcloud EIP ShowPublicip/v2 --cli-region=cn-north-4 --publicip_id=<id>

| Feature | Description | Example |
|---------|-------------|---------||
| Service name | Uppercase PascalCase | `EIP`, `VPC`, `IAM` |
| Operation name | PascalCase with version | `ListPublicips/v2`, `ShowPublicip/v2` |
| Region param | `--cli-region=<value>` | `--cli-region=cn-north-4` |
| Simple param | `--key=value` | `--publicip_id=xxx` |
| Output format | `--cli-output=json` | JSON output for programmatic parsing |
hcloud EIP ShowPublicip/v2 --cli-region=cn-north-4 --publicip_id=<id>

| 特性 | 描述 | 示例 |
|---------|-------------|---------|
| 服务名 | 大写帕斯卡命名法 | `EIP`, `VPC`, `IAM` |
| 操作名 | 帕斯卡命名法加版本 | `ListPublicips/v2`, `ShowPublicip/v2` |
| 地域参数 | `--cli-region=<值>` | `--cli-region=cn-north-4` |
| 简单参数 | `--key=value` | `--publicip_id=xxx` |
| 输出格式 | `--cli-output=json` | 生成JSON格式输出供程序解析 |

Parameters

参数说明

Shell Script Parameters

Shell脚本参数

ScriptParameterRequired/OptionalDescriptionDefault
list_eips.sh
--region
OptionalRegion(s), comma-separated
HW_REGION_NAME
or
cn-north-4
list_eips.sh
--status
OptionalFilter by status (ACTIVE/DOWN/ERROR)All
analyze_idle_eips.sh
--region
OptionalTarget region
HW_REGION_NAME
or
cn-north-4
analyze_idle_eips.sh
--idle-days
OptionalIdle threshold in days
0
(all unbound)
analyze_idle_eips.sh
--json
OptionalOutput JSON format report
false
eip_cost_report.sh
--region
OptionalTarget region
HW_REGION_NAME
or
cn-north-4
eip_cost_report.sh
--format
OptionalOutput format: text/html/json
text
monitor_idle_eips.sh
--region
OptionalTarget region
HW_REGION_NAME
or
cn-north-4
monitor_idle_eips.sh
--idle-days
OptionalIdle threshold in days
7
monitor_idle_eips.sh
--webhook
OptionalWebhook alert URL-
monitor_idle_eips.sh
--email
OptionalAlert email address-
monitor_idle_eips.sh
--setup-cron
OptionalSet up cron monitoring-
monitor_idle_eips.sh
--remove-cron
OptionalRemove cron monitoring-
check_env.sh
--verbose
OptionalShow detailed check info
false
check_env.sh
--fix
OptionalAuto-fix missing dependencies
false
eip_audit_log.sh
--action
RequiredOperation type (list/query/analyze/monitor/report)-
eip_audit_log.sh
--detail
OptionalOperation detail description-
eip_audit_log.sh
--export
OptionalExport format: csv/json-
eip_audit_log.sh
--log-dir
OptionalLog directory path
./eip_audit_logs
脚本参数必填/可选描述默认值
list_eips.sh
--region
可选地域,多个地域用逗号分隔
HW_REGION_NAME
cn-north-4
list_eips.sh
--status
可选按状态过滤(ACTIVE/DOWN/ERROR)所有状态
analyze_idle_eips.sh
--region
可选目标地域
HW_REGION_NAME
cn-north-4
analyze_idle_eips.sh
--idle-days
可选闲置阈值(天数)
0
(所有未绑定EIP)
analyze_idle_eips.sh
--json
可选输出JSON格式报告
false
eip_cost_report.sh
--region
可选目标地域
HW_REGION_NAME
cn-north-4
eip_cost_report.sh
--format
可选输出格式:text/html/json
text
monitor_idle_eips.sh
--region
可选目标地域
HW_REGION_NAME
cn-north-4
monitor_idle_eips.sh
--idle-days
可选闲置阈值(天数)
7
monitor_idle_eips.sh
--webhook
可选Webhook告警地址-
monitor_idle_eips.sh
--email
可选告警邮箱地址-
monitor_idle_eips.sh
--setup-cron
可选设置定时监控任务-
monitor_idle_eips.sh
--remove-cron
可选删除定时监控任务-
check_env.sh
--verbose
可选显示详细检查信息
false
check_env.sh
--fix
可选自动修复缺失依赖
false
eip_audit_log.sh
--action
必填操作类型(list/query/analyze/monitor/report)-
eip_audit_log.sh
--detail
可选操作详情描述-
eip_audit_log.sh
--export
可选导出格式:csv/json-
eip_audit_log.sh
--log-dir
可选日志目录路径
./eip_audit_logs

Environment Variables

环境变量

VariableRequiredDescriptionDefault
HW_ACCESS_KEY
Optional*Huawei Cloud AK (required only if hcloud configure not set)-
HW_SECRET_KEY
Optional*Huawei Cloud SK (required only if hcloud configure not set)-
HW_REGION_NAME
OptionalDefault region
cn-north-4
HW_SECURITY_TOKEN
OptionalTemporary credential token-
*When
hcloud configure
is already set up,
HW_ACCESS_KEY
and
HW_SECRET_KEY
are not needed. Environment variables take precedence when both are configured.
变量名必填性描述默认值
HW_ACCESS_KEY
可选*华为云AK(仅当未配置hcloud configure时需要)-
HW_SECRET_KEY
可选*华为云SK(仅当未配置hcloud configure时需要)-
HW_REGION_NAME
可选默认地域
cn-north-4
HW_SECURITY_TOKEN
可选临时凭证令牌-
当已通过交互式方式配置
hcloud configure
时,
HW_ACCESS_KEY
HW_SECRET_KEY
无需设置。若两者均配置,环境变量优先级更高。

Output Format

输出格式

EIP List Output

EIP列表输出

text
========================================
Huawei Cloud EIP List (Region: cn-north-4)
========================================
EIP ID: eip-xxx1, IP: 123.45.67.89, BW: 5 Mbps, Status: BOUND (ECS: ecs-xxx)
EIP ID: eip-xxx2, IP: 98.76.54.32, BW: 10 Mbps, Status: UNBOUND ⚠️
========================================
Total: 2 EIPs, Idle: 1
text
========================================
华为云EIP列表(地域:cn-north-4)
========================================
EIP ID: eip-xxx1, IP: 123.45.67.89, 带宽: 5 Mbps, 状态: BOUND(ECS: ecs-xxx)
EIP ID: eip-xxx2, IP: 98.76.54.32, 带宽: 10 Mbps, 状态: UNBOUND ⚠️
========================================
总计: 2个EIP, 闲置: 1个

Cost Report Output

成本报告输出

Generated by
scripts/eip_cost_report.sh
— includes:
  • Summary statistics (total EIPs, idle, active, total bandwidth, costs)
  • Per-EIP detail table with cost estimates
  • Available in text, HTML, and JSON formats
Pricing Model: Bandwidth-based (~3 CNY/Mbps/month + 0.02 CNY/hr IP retain fee for unbound EIPs)
scripts/eip_cost_report.sh
生成 — 包含:
  • 汇总统计(EIP总数、闲置数、活跃数、总带宽、成本)
  • 单个EIP详情表及成本估算
  • 支持文本、HTML、JSON三种格式
定价模型:基于带宽(约3元/Mbps/月 + 未绑定EIP0.02元/小时IP保留费)

Verification

验证

Environment Compliance Check

环境合规性检查

bash
undefined
bash
undefined

Run full environment check (CLI + tools + API)

运行完整环境检查(CLI + 工具 + API)

bash scripts/check_env.sh
bash scripts/check_env.sh

Exit codes:

退出码:

0 - All checks passed

0 - 所有检查通过

1 - Missing dependencies or API errors

1 - 缺失依赖或API错误

undefined
undefined

Best Practices

最佳实践

  1. Use Shell Scripts EXCLUSIVELY: All scripts are Shell + hcloud CLI. No Python SDK dependency.
  2. Regular Monitoring: Set up daily cron jobs with
    monitor_idle_eips.sh --setup-cron
    to catch idle EIPs early
  3. Cost Reports: Generate weekly cost reports with
    eip_cost_report.sh --format html
    to track optimization progress
  4. Audit Logging: Enable audit logging for all EIP operations using
    eip_audit_log.sh
  5. Multi-Region List:
    list_eips.sh
    supports comma-separated regions
    --region cn-north-4,cn-east-3
    for cross-region listing. Note:
    analyze_idle_eips.sh
    ,
    eip_cost_report.sh
    , and
    monitor_idle_eips.sh
    process a single region each (run once per region for multi-region analysis).
  6. Webhook Alerts: Configure webhooks for real-time idle EIP notifications
  7. Environment Validation: Always run
    check_env.sh
    first to verify hcloud CLI and dependencies
  8. Idle Days Consistency: Both
    analyze_idle_eips.sh
    and
    monitor_idle_eips.sh
    use
    --idle-days
    parameter with consistent timezone handling
  1. 仅使用Shell脚本:所有脚本均为Shell + hcloud CLI,无Python SDK依赖。
  2. 定期监控:使用
    monitor_idle_eips.sh --setup-cron
    设置每日定时任务,尽早发现闲置EIP
  3. 成本报告:每周使用
    eip_cost_report.sh --format html
    生成成本报告,跟踪优化进度
  4. 审计日志:使用
    eip_audit_log.sh
    为所有EIP操作启用审计日志
  5. 多地域列出
    list_eips.sh
    支持逗号分隔的地域参数
    --region cn-north-4,cn-east-3
    以实现跨地域列出。注意:
    analyze_idle_eips.sh
    eip_cost_report.sh
    monitor_idle_eips.sh
    每次仅处理单个地域(如需多地域分析,需每个地域运行一次)。
  6. Webhook告警:配置Webhook以获取实时闲置EIP通知
  7. 环境验证:运行脚本前始终先执行
    check_env.sh
    验证hcloud CLI及依赖
  8. 闲置天数一致性
    analyze_idle_eips.sh
    monitor_idle_eips.sh
    均使用
    --idle-days
    参数,且时区处理一致

References

参考文档

DocumentDescription
IAM Permission PoliciesRequired permissions and policy JSON
EIP API GuideEIP API reference (hcloud CLI)
CLI Installation Guidehcloud CLI install, configure, troubleshoot
Verification MethodStep-by-step verification
Acceptance CriteriaProduction readiness acceptance tests
文档描述
IAM权限策略所需权限及策略JSON
EIP API指南EIP API参考(hcloud CLI)
CLI安装指南hcloud CLI安装、配置与故障排查
验证方法分步验证流程
验收标准生产就绪性验收测试

Notes

注意事项

  • Cost estimates are for reference only — based on cn-north-4 on-demand pricing (bandwidth model: ~3 CNY/Mbps/month + 0.02 CNY/hr IP retain fee). Actual costs may vary by region and billing mode.
  • API does not return charge_mode — scripts cannot distinguish bandwidth vs traffic billing; all estimates use bandwidth model.
  • This skill is READ-ONLY — it analyzes and reports idle EIPs but does NOT release or delete any resources. Manual action in the console is required to release EIPs.
  • EIP release is irreversible — if you choose to release idle EIPs based on the analysis report, the public IP address will be reclaimed and cannot be recovered.
  • AK/SK must never be hardcoded — credentials should only be obtained via environment variables (
    HW_ACCESS_KEY
    ,
    HW_SECRET_KEY
    ) or
    hcloud configure
    interactive mode (entering via prompts, not command-line arguments).
  • hcloud CLI is the only supported method — all scripts use hcloud CLI (KooCLI) natively.
  • Authentication: Use environment variables (
    HW_ACCESS_KEY
    ,
    HW_SECRET_KEY
    ) as the primary method. If
    hcloud configure
    is already set up interactively, the skill will detect and use those credentials. Never pass credentials as command-line arguments.
  • Temporary Credentials Supported: This skill supports temporary AK/SK+Token obtained via IAM STS. Set
    HW_SECURITY_TOKEN
    when using temporary credentials.
  • Environment Variable Standard: Uses
    HW_*
    prefix for consistency with other Huawei Cloud skills.
  • jq is required for all scripts that parse hcloud CLI JSON output.
  • Idle days calculation is timezone-consistent — both analyze and monitor scripts use
    date
    command for epoch calculation, eliminating UTC offset issues.
  • Audit log timestamps are timezone-aware — format
    YYYY-MM-DDTHH:MM:SS+HH:MM
    (e.g.,
    +08:00
    ), not misleading
    Z
    suffix.
  • 成本估算仅供参考 — 基于cn-north-4按需定价(带宽模型:约3元/Mbps/月 + 0.02元/小时IP保留费)。实际成本可能因地域和计费模式而异。
  • API不返回charge_mode — 脚本无法区分带宽计费与流量计费;所有估算均使用带宽模型。
  • 本技能为只读模式 — 仅分析并报告闲置EIP,不释放或删除任何资源。如需释放EIP,需在控制台手动操作。
  • EIP释放不可逆 — 若根据分析报告选择释放闲置EIP,公网IP地址将被回收且无法恢复。
  • 切勿硬编码AK/SK — 凭证仅应通过环境变量(
    HW_ACCESS_KEY
    HW_SECRET_KEY
    )或
    hcloud configure
    交互式方式(通过提示输入,而非命令行参数)获取。
  • 仅支持hcloud CLI — 所有脚本原生使用hcloud CLI(KooCLI)。
  • 认证方式:优先使用环境变量(
    HW_ACCESS_KEY
    HW_SECRET_KEY
    )。若已通过交互式方式配置
    hcloud configure
    ,本技能会检测并使用这些凭证。切勿将凭证作为命令行参数传递。
  • 支持临时凭证:本技能支持通过IAM STS获取的临时AK/SK+令牌。使用临时凭证时需设置
    HW_SECURITY_TOKEN
  • 环境变量标准:使用
    HW_*
    前缀以与其他华为云技能保持一致。
  • 所有解析hcloud CLI JSON输出的脚本均需jq
  • 闲置天数计算时区一致 — 分析与监控脚本均使用
    date
    命令进行时间戳计算,消除UTC偏移问题。
  • 审计日志时间戳带时区 — 格式为
    YYYY-MM-DDTHH:MM:SS+HH:MM
    (例如
    +08:00
    ),而非易混淆的
    Z
    后缀。

Common Pitfalls

常见问题

PitfallSymptomQuick Fix
hcloud not installed
command not found: hcloud
Install KooCLI
jq not installedJSON parse errors
sudo apt install jq
bc not installedCost calculation errors
sudo apt install bc
AK/SK not setAPI 401 / credential errorExport
HW_ACCESS_KEY
/
HW_SECRET_KEY
or configure
hcloud
interactively
Wrong region
❌ API 返回异常
Use valid region ID (e.g.,
cn-north-4
)
Invalid format
❌ 不支持的格式
Use text/html/json for
--format
API rate limit
429 Too Many Requests
Add delay between calls
问题症状快速修复
hcloud未安装
command not found: hcloud
安装KooCLI
jq未安装JSON解析错误
sudo apt install jq
bc未安装成本计算错误
sudo apt install bc
AK/SK未设置API 401 / 凭证错误导出
HW_ACCESS_KEY
/
HW_SECRET_KEY
或交互式配置
hcloud
地域错误
❌ API 返回异常
使用有效的地域ID(例如
cn-north-4
格式无效
❌ 不支持的格式
--format
参数使用text/html/json
API速率限制
429 Too Many Requests
在调用之间添加延迟