huawei-cloud-eip-cost-optimizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHuawei 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 skill. This skill focuses exclusively on EIP optimization with deeper functionality and 100% hcloud CLI compliance.
huaweicloud-cost-optimizer- 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等)进行更全面的成本优化,请查看归档的技能。本技能专注于EIP优化,功能更深入且100%符合hcloud CLI规范。
huaweicloud-cost-optimizer- 定期清理闲置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
undefinedLinux/macOS one-click install
Linux/macOS一键安装
Verify installation
验证安装
hcloud --version
**Install jq, bc, curl**:
```bashhcloud --version
**安装jq、bc、curl**:
```bashUbuntu/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-4Note: If you have already configuredinteractively (entering credentials via prompts, not command-line arguments), the skill will also detect and use those credentials.hcloud configure
Environment Variables:
| Variable | Required | Description |
|---|---|---|
| Optional | Huawei Cloud Access Key ID (required only if hcloud configure not set) |
| Optional | Huawei Cloud Secret Access Key (required only if hcloud configure not set) |
| Optional | Default region (default: |
| Optional | Security 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 to validate credentials before running scripts
./scripts/check_env.sh
bash
export HW_ACCESS_KEY=<你的AK>
export HW_SECRET_KEY=<你的SK>
export HW_REGION_NAME=cn-north-4注意:如果已通过交互式方式配置(通过提示输入凭证,而非命令行参数),本技能也会检测并使用这些凭证。hcloud configure
环境变量说明:
| 变量名 | 必填性 | 描述 |
|---|---|---|
| 可选 | 华为云访问密钥ID(仅当未配置hcloud configure时需要) |
| 可选 | 华为云秘密访问密钥(仅当未配置hcloud configure时需要) |
| 可选 | 默认地域(默认值: |
| 可选 | 临时凭证的安全令牌 |
安全注意事项:
- 切勿将凭证提交至版本控制系统
- 切勿在代码、对话或命令中暴露AK/SK值
- 切勿将AK/SK作为命令行参数传递(会在Shell历史记录和中暴露凭证)
ps aux - 使用权限最小化的IAM用户
- 为敏感操作启用MFA
- 定期轮换AK/SK
- 在运行脚本前使用验证凭证
./scripts/check_env.sh
3. Quick Start
3. 快速开始
bash
undefinedbash
undefinedStep 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
undefinedbash 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
undefined4. IAM Permission Requirements
4. IAM权限要求
Note: This skill is READ-ONLY for EIP resources. It does NOT perform any write operations.
| API Action | Permission | Purpose |
|---|---|---|
| List EIPs | Query all EIPs and their status |
| Get EIP details | View individual EIP information |
注意:本技能仅对EIP资源具有只读权限,不执行任何写入操作。
| API操作 | 权限 | 用途 |
|---|---|---|
| 列出EIP | 查询所有EIP及其状态 |
| 获取EIP详情 | 查看单个EIP的信息 |
Workflow
工作流程
Main Steps
主要步骤
- Environment Check → Verify hcloud CLI, jq, credentials
- EIP Query → List EIPs across regions via hcloud CLI
- Idle Analysis → Identify unbound EIPs exceeding idle threshold
- Cost Report → Generate HTML/JSON cost analysis report
- Monitoring Setup → Configure idle EIP alerts (webhook/email)
- Audit Logging → Record operations for compliance
- 环境检查 → 验证hcloud CLI、jq及凭证
- EIP查询 → 通过hcloud CLI跨地域列出EIP
- 闲置分析 → 识别超过闲置阈值的未绑定EIP
- 成本报告 → 生成HTML/JSON格式的成本分析报告
- 监控配置 → 配置闲置EIP告警(Webhook/邮件)
- 审计日志 → 记录操作以满足合规要求
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 NAll EIP operations use hcloud CLI commands:
| Python SDK Method | hcloud CLI Command | Description |
|---|---|---|
| | List all EIPs |
| | Get EIP details |
| | List projects |
Output format: All commands use for machine-readable output, parsed by .
--cli-output=jsonjq所有EIP操作(列出/分析/报告/监控)都会自动写入审计日志文件以满足合规要求。每个脚本退出时都会记录自身操作。使用查询历史记录。
--action query-log --days N所有EIP操作均使用hcloud CLI命令:
| Python SDK方法 | hcloud CLI命令 | 描述 |
|---|---|---|
| | 列出所有EIP |
| | 获取EIP详情 |
| | 列出项目 |
输出格式:所有命令使用生成机器可读输出,由解析。
--cli-output=jsonjqCore Commands
核心命令
| Command | Description | Backend |
|---|---|---|
| List and query EIPs across regions | hcloud CLI |
| Identify idle/unbound EIPs with cost analysis | hcloud CLI |
| Generate HTML/JSON cost analysis reports | hcloud CLI |
| Set up idle EIP monitoring with alerts | hcloud CLI |
| Maintain operation audit logs | Shell |
| Verify environment prerequisites | Shell |
| Load configuration and credentials | Shell |
| 命令 | 描述 | 后端 |
|---|---|---|
| 跨地域列出并查询EIP | hcloud CLI |
| 识别闲置/未绑定EIP并进行成本分析 | hcloud CLI |
| 生成HTML/JSON格式的成本分析报告 | hcloud CLI |
| 配置闲置EIP监控与告警 | hcloud CLI |
| 维护操作审计日志 | Shell |
| 验证环境前置条件 | Shell |
| 加载配置与凭证 | Shell |
EIP Query
EIP查询
bash
undefinedbash
undefinedList 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
undefinedbash scripts/list_eips.sh --region cn-north-4,cn-east-3,cn-south-1
undefinedIdle EIP Analysis
闲置EIP分析
bash
undefinedbash
undefinedAnalyze 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
undefinedbash scripts/analyze_idle_eips.sh --region cn-north-4 --idle-days 7 --json
undefinedCost Report
成本报告
bash
undefinedbash
undefinedGenerate 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
undefinedbash
undefinedMonitor 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"
--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"
--webhook "https://oapi.dingtalk.com/robot/send?access_token=YOUR_ACCESS_TOKEN"
Remove cron job
删除定时任务
bash scripts/monitor_idle_eips.sh --remove-cron
undefinedbash scripts/monitor_idle_eips.sh --remove-cron
undefinedEnvironment Check
环境检查
bash
undefinedbash
undefinedFull 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
undefinedbash scripts/check_env.sh --fix
undefinedOperation Audit Logging
操作审计日志
bash
undefinedbash
undefinedLog 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
undefinedbash
undefinedGeneral 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脚本参数
| Script | Parameter | Required/Optional | Description | Default |
|---|---|---|---|---|
| | Optional | Region(s), comma-separated | |
| | Optional | Filter by status (ACTIVE/DOWN/ERROR) | All |
| | Optional | Target region | |
| | Optional | Idle threshold in days | |
| | Optional | Output JSON format report | |
| | Optional | Target region | |
| | Optional | Output format: text/html/json | |
| | Optional | Target region | |
| | Optional | Idle threshold in days | |
| | Optional | Webhook alert URL | - |
| | Optional | Alert email address | - |
| | Optional | Set up cron monitoring | - |
| | Optional | Remove cron monitoring | - |
| | Optional | Show detailed check info | |
| | Optional | Auto-fix missing dependencies | |
| | Required | Operation type (list/query/analyze/monitor/report) | - |
| | Optional | Operation detail description | - |
| | Optional | Export format: csv/json | - |
| | Optional | Log directory path | |
| 脚本 | 参数 | 必填/可选 | 描述 | 默认值 |
|---|---|---|---|---|
| | 可选 | 地域,多个地域用逗号分隔 | |
| | 可选 | 按状态过滤(ACTIVE/DOWN/ERROR) | 所有状态 |
| | 可选 | 目标地域 | |
| | 可选 | 闲置阈值(天数) | |
| | 可选 | 输出JSON格式报告 | |
| | 可选 | 目标地域 | |
| | 可选 | 输出格式:text/html/json | |
| | 可选 | 目标地域 | |
| | 可选 | 闲置阈值(天数) | |
| | 可选 | Webhook告警地址 | - |
| | 可选 | 告警邮箱地址 | - |
| | 可选 | 设置定时监控任务 | - |
| | 可选 | 删除定时监控任务 | - |
| | 可选 | 显示详细检查信息 | |
| | 可选 | 自动修复缺失依赖 | |
| | 必填 | 操作类型(list/query/analyze/monitor/report) | - |
| | 可选 | 操作详情描述 | - |
| | 可选 | 导出格式:csv/json | - |
| | 可选 | 日志目录路径 | |
Environment Variables
环境变量
| Variable | Required | Description | Default |
|---|---|---|---|
| Optional* | Huawei Cloud AK (required only if hcloud configure not set) | - |
| Optional* | Huawei Cloud SK (required only if hcloud configure not set) | - |
| Optional | Default region | |
| Optional | Temporary credential token | - |
*When is already set up, and are not needed. Environment variables take precedence when both are configured.
hcloud configureHW_ACCESS_KEYHW_SECRET_KEY| 变量名 | 必填性 | 描述 | 默认值 |
|---|---|---|---|
| 可选* | 华为云AK(仅当未配置hcloud configure时需要) | - |
| 可选* | 华为云SK(仅当未配置hcloud configure时需要) | - |
| 可选 | 默认地域 | |
| 可选 | 临时凭证令牌 | - |
当已通过交互式方式配置时,和无需设置。若两者均配置,环境变量优先级更高。
hcloud configureHW_ACCESS_KEYHW_SECRET_KEYOutput 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: 1text
========================================
华为云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 — includes:
scripts/eip_cost_report.sh- 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
undefinedbash
undefinedRun 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错误
undefinedundefinedBest Practices
最佳实践
- Use Shell Scripts EXCLUSIVELY: All scripts are Shell + hcloud CLI. No Python SDK dependency.
- Regular Monitoring: Set up daily cron jobs with to catch idle EIPs early
monitor_idle_eips.sh --setup-cron - Cost Reports: Generate weekly cost reports with to track optimization progress
eip_cost_report.sh --format html - Audit Logging: Enable audit logging for all EIP operations using
eip_audit_log.sh - Multi-Region List: supports comma-separated regions
list_eips.shfor cross-region listing. Note:--region cn-north-4,cn-east-3,analyze_idle_eips.sh, andeip_cost_report.shprocess a single region each (run once per region for multi-region analysis).monitor_idle_eips.sh - Webhook Alerts: Configure webhooks for real-time idle EIP notifications
- Environment Validation: Always run first to verify hcloud CLI and dependencies
check_env.sh - Idle Days Consistency: Both and
analyze_idle_eips.shusemonitor_idle_eips.shparameter with consistent timezone handling--idle-days
- 仅使用Shell脚本:所有脚本均为Shell + hcloud CLI,无Python SDK依赖。
- 定期监控:使用设置每日定时任务,尽早发现闲置EIP
monitor_idle_eips.sh --setup-cron - 成本报告:每周使用生成成本报告,跟踪优化进度
eip_cost_report.sh --format html - 审计日志:使用为所有EIP操作启用审计日志
eip_audit_log.sh - 多地域列出:支持逗号分隔的地域参数
list_eips.sh以实现跨地域列出。注意:--region cn-north-4,cn-east-3、analyze_idle_eips.sh和eip_cost_report.sh每次仅处理单个地域(如需多地域分析,需每个地域运行一次)。monitor_idle_eips.sh - Webhook告警:配置Webhook以获取实时闲置EIP通知
- 环境验证:运行脚本前始终先执行验证hcloud CLI及依赖
check_env.sh - 闲置天数一致性:和
analyze_idle_eips.sh均使用monitor_idle_eips.sh参数,且时区处理一致--idle-days
References
参考文档
| Document | Description |
|---|---|
| IAM Permission Policies | Required permissions and policy JSON |
| EIP API Guide | EIP API reference (hcloud CLI) |
| CLI Installation Guide | hcloud CLI install, configure, troubleshoot |
| Verification Method | Step-by-step verification |
| Acceptance Criteria | Production 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) orHW_SECRET_KEYinteractive mode (entering via prompts, not command-line arguments).hcloud configure - hcloud CLI is the only supported method — all scripts use hcloud CLI (KooCLI) natively.
- Authentication: Use environment variables (,
HW_ACCESS_KEY) as the primary method. IfHW_SECRET_KEYis already set up interactively, the skill will detect and use those credentials. Never pass credentials as command-line arguments.hcloud configure - Temporary Credentials Supported: This skill supports temporary AK/SK+Token obtained via IAM STS. Set when using temporary credentials.
HW_SECURITY_TOKEN - Environment Variable Standard: Uses prefix for consistency with other Huawei Cloud skills.
HW_* - jq is required for all scripts that parse hcloud CLI JSON output.
- Idle days calculation is timezone-consistent — both analyze and monitor scripts use command for epoch calculation, eliminating UTC offset issues.
date - Audit log timestamps are timezone-aware — format (e.g.,
YYYY-MM-DDTHH:MM:SS+HH:MM), not misleading+08:00suffix.Z
- 成本估算仅供参考 — 基于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。
- 闲置天数计算时区一致 — 分析与监控脚本均使用命令进行时间戳计算,消除UTC偏移问题。
date - 审计日志时间戳带时区 — 格式为(例如
YYYY-MM-DDTHH:MM:SS+HH:MM),而非易混淆的+08:00后缀。Z
Common Pitfalls
常见问题
| Pitfall | Symptom | Quick Fix |
|---|---|---|
| hcloud not installed | | Install KooCLI |
| jq not installed | JSON parse errors | |
| bc not installed | Cost calculation errors | |
| AK/SK not set | API 401 / credential error | Export |
| Wrong region | | Use valid region ID (e.g., |
| Invalid format | | Use text/html/json for |
| API rate limit | | Add delay between calls |
| 问题 | 症状 | 快速修复 |
|---|---|---|
| hcloud未安装 | | 安装KooCLI |
| jq未安装 | JSON解析错误 | |
| bc未安装 | 成本计算错误 | |
| AK/SK未设置 | API 401 / 凭证错误 | 导出 |
| 地域错误 | | 使用有效的地域ID(例如 |
| 格式无效 | | |
| API速率限制 | | 在调用之间添加延迟 |