DevOps-centric cloud cost governance and automation tool
Project description
Cloud Billing Automation
๐ทโโ๏ธ DevOps-Centric Cloud Cost Governance & Automation
A comprehensive cloud billing automation tool built for Cloud Engineers and DevOps Engineers to gain visibility, control, and automation over cloud billing across AWS, Azure, and GCP.
๐ฏ Why DevOps & Cloud Engineers Use This
- ๐จ Prevent unexpected cloud bills with real-time monitoring and alerts
- ๐ค Automate cloud cost monitoring through scheduled jobs and CI/CD integration
- ๐ท๏ธ Enforce tagging & cost ownership with automated compliance checks
- ๐ Detect cost anomalies early using machine learning-based anomaly detection
- โ๏ธ Integrate billing checks into automation workflows with CLI and API access
โจ Core DevOps Features
โ๏ธ Multi-Cloud Support
- AWS: Cost Explorer, EC2, RDS, Lambda, S3 integration
- Azure: Billing Management, Resource Manager, Compute, Storage APIs
- GCP: Cloud Billing, Compute Engine, Cloud Storage integration
๐ Cost Analysis & Insights
- Cost breakdown by service, region, environment, and cost center
- Resource-level analysis with efficiency scoring and recommendations
- Trend analysis with seasonal pattern detection
- Advanced forecasting using machine learning models
๐จ Intelligent Alerting
- Budget threshold monitoring with configurable warning and critical levels
- Anomaly detection using Z-score, IQR, and percentage deviation methods
- Multi-channel notifications (email, webhooks, Slack integration)
- Escalation policies for critical alerts
๐ท๏ธ Tag Compliance & Governance
- Automated tag validation for required tags (Environment, CostCenter, etc.)
- Cost ownership tracking through mandatory tagging policies
- Compliance reporting with violation detection and remediation suggestions
๐ Resource Optimization
- Idle resource detection for compute instances, storage, and databases
- Cost optimization recommendations based on usage patterns
- Rightsizing suggestions with potential savings calculations
๐ Automated Reporting
- Scheduled reports (daily, weekly, monthly) in multiple formats
- Custom report templates with charts and visualizations
- Email delivery with interactive HTML reports
โ๏ธ DevOps Integration
- CLI tool for automation and scripting
- YAML configuration for infrastructure-as-code compatibility
- CI/CD pipeline integration examples
- Cron job scheduling for automated monitoring
๐ ๏ธ Tech Stack
- Python 3.8+ - Core automation framework
- Cloud SDKs - boto3 (AWS), azure-mgmt, google-cloud
- Data Processing - pandas, numpy for analysis
- Machine Learning - scikit-learn for forecasting
- Security - cryptography, keyring for credential management
- CLI - Click, Typer, Rich for command-line interface
- Configuration - YAML for declarative config
๐ Quick Start
Prerequisites
- Python 3.8 or higher
- Cloud provider credentials (AWS, Azure, or GCP)
- Required billing permissions in your cloud accounts
Installation
# Clone the repository
git clone https://github.com/NotHarshhaa/cloud-billing-automation.git
cd cloud-billing-automation
# Install in development mode
pip install -e .
# Or install from requirements
pip install -r requirements.txt
Configuration
Create a configuration file:
# config/billing-config.yaml
debug: false
log_level: "INFO"
data_retention_days: 90
providers:
aws:
enabled: true
account_id: "123456789012"
regions: ["us-east-1", "us-west-2"]
tags_required: ["Environment", "CostCenter", "Owner"]
cost_center_tag: "CostCenter"
environment_tag: "Environment"
azure:
enabled: false
subscription_id: "your-subscription-id"
regions: ["eastus", "westus2"]
tags_required: ["Environment", "CostCenter"]
gcp:
enabled: false
project_id: "your-gcp-project"
regions: ["us-central1", "us-east1"]
tags_required: ["Environment", "CostCenter"]
budget:
monthly_limit: 10000.0
warning_threshold: 0.8 # 80%
critical_threshold: 0.95 # 95%
currency: "USD"
alert_emails: ["devops@company.com"]
alert_webhooks: ["https://hooks.slack.com/your-webhook"]
reports:
output_dir: "reports"
formats: ["json", "csv", "html"]
schedule: "daily"
include_charts: true
email_reports: true
email_recipients: ["finance@company.com"]
Setup Credentials
# AWS credentials
cba credentials setup-aws \
--access-key-id YOUR_ACCESS_KEY \
--secret-access-key YOUR_SECRET_KEY
# Azure service principal
cba credentials setup-azure \
--tenant-id YOUR_TENANT_ID \
--client-id YOUR_CLIENT_ID \
--client-secret YOUR_CLIENT_SECRET \
--subscription-id YOUR_SUBSCRIPTION_ID
# GCP service account
cba credentials setup-gcp \
--service-account-key-path /path/to/service-account.json
๏ฟฝ Alerting & Notification System
The cloud-billing-automation tool includes a comprehensive alerting system with multi-channel notifications, escalation policies, and intelligent alert management.
Alert Types
- Budget Alerts - Threshold-based budget monitoring (warning, critical, exceeded)
- Forecast Alerts - Predictive alerts based on spending trends
- Anomaly Alerts - Statistical detection of cost outliers
- Trend Alerts - Spending pattern changes and escalations
- Resource Alerts - Individual resource cost issues
Notification Channels
- Email - Rich HTML emails with detailed information and recommendations
- Slack - Color-coded messages with interactive elements
- Webhook - JSON payloads for integration with monitoring systems
- Custom Channels - Extensible channel system for custom integrations
Alert Features
- Severity Levels - Low, Medium, High, Critical with appropriate escalation
- Cooldown Periods - Prevent alert spam with configurable cooldowns
- Alert Suppression - Temporary suppression for maintenance windows
- Template System - Jinja2-based dynamic alert templates
- Alert History - Comprehensive tracking and analytics
- Smart Grouping - Reduces noise by grouping related alerts
Escalation Policies
- Threshold-Based - Different actions for different severity levels
- Multi-Channel Routing - Critical alerts go to all channels, warnings to email only
- Time-Based Escalation - Escalate unacknowledged critical alerts
- Auto-Resolution - Automatically resolve alerts when conditions normalize
๐ฅ๏ธ CLI Interface
The cloud-billing-automation tool includes a comprehensive command-line interface with rich output, intuitive commands, and professional error handling.
Installation & Setup
# Install the tool
pip install cloud-billing-automation
# Initialize configuration
cba init --output-dir config
# Set up credentials
cba credentials setup-aws --access-key-id YOUR_KEY --secret-access-key YOUR_SECRET
cba credentials setup-azure --tenant-id TENANT_ID --client-id CLIENT_ID --client-secret SECRET --subscription-id SUB_ID
cba credentials setup-gcp --service-account-key-path /path/to/key.json
# Validate credentials
cba credentials validate
cba credentials status
# List stored credentials
cba credentials list
# Export credentials
cba credentials export aws --output-file aws-credentials.sh
Command Structure
cba [GLOBAL_OPTIONS] COMMAND [COMMAND_OPTIONS]
Global Options:
-c, --config FILE Configuration file path
--debug Enable debug mode
-v, --verbose Enable verbose output
--help Show help message
Cost Analysis Commands
# Analyze costs for specific period
cba analyze costs \
--start-date 2024-01-01 \
--end-date 2024-01-31 \
--providers aws,azure \
--output table
# Get cost breakdown by service
cba analyze breakdown \
--group-by service \
--period monthly
# Detect cost anomalies
cba analyze anomalies \
--methods zscore,iqr,percentage \
--threshold 2.0
# Analyze cost trends
cba analyze trends \
--metrics total_cost \
--period weekly
# Generate cost forecast
cba analyze forecast \
--days 30 \
--model auto
Budget Management Commands
# Check current budget status
cba budget status \
--config config/billing-config.yaml \
--forecast
# Set monthly budget limit
cba budget set-limit 10000
# Set up budget alerts
cba budget alerts --setup
# Test alert channels
cba budget alerts --test
# View budget history
cba budget history --days 30
# Generate budget forecast
cba budget forecast --days 30
Alert Management Commands
# Test notification channels
cba alerts test \
--channels email,slack,webhook
# View alert history
cba alerts history \
--days 30 \
--severity critical,high \
--status active
# Suppress alerts for maintenance
cba alerts suppress \
--resource-id i-1234567890abcdef0 \
--duration-hours 12 \
--reason "Scheduled maintenance"
# Acknowledge an alert
cba alerts acknowledge alert-id-123 --by "John Doe"
# Resolve an alert
cba alerts resolve alert-id-123
# Check alert system status
cba alerts status
# Manage alert rules
cba alerts rules --list
cba alerts rules --enable budget_warning
cba alerts rules --disable anomaly_detection
CLI Features
- Rich Terminal Output - Beautiful tables, panels, and colored output
- Progress Indicators - Progress bars for long-running operations
- Error Handling - User-friendly error messages and validation
- Auto-completion - Command auto-completion (bash/zsh)
- Help System - Comprehensive help for all commands
- Configuration Detection - Automatic config file discovery
- Multiple Output Formats - Table, JSON, CSV output options
Output Examples
Budget Status Output
Checking budget status...
Budget Status - Warning
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ Metric โ Value โ
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโค
โ Budget Limit โ $10,000.00 โ
โ Current Spend โ $8,234.56 โ
โ Usage โ 82.3% โ
โ Remaining โ $1,765.44 โ
โ Days Remaining โ 12 โ
โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
Risk Assessment
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Risk Level: HIGH
Daily Average: $274.49
Projected Daily: $147.11
Alert History Output
Loading alert history for last 30 days...
Alert History (15 alerts)
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ
โ ID โ Title โ Severity โ Status โ Source โ Time โ
โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโค
โ 1234... โ Budget Warning: 82.3% used โ medium โ active โ Budget โ 2024-01-15 14:30 โ
โ 5678... โ Cost Anomaly Detected โ high โ resolved โ Anomaly โ 2024-01-14 09:15 โ
โ 9012... โ Budget Critical: 95.1% used โ critical โ acknowledged โ Budget โ 2024-01-13 16:45 โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโ
๐ Usage Examples
Basic Cost Analysis
# Analyze costs for the last 30 days
cba analyze costs \
--start-date 2024-01-01 \
--end-date 2024-01-31 \
--config config/billing-config.yaml
# Get cost breakdown by service
cba analyze breakdown \
--group-by service \
--period monthly
# Detect cost anomalies
cba analyze anomalies \
--methods zscore,iqr,percentage \
--threshold 2.0
Budget Monitoring & Alerting
# Check budget status
cba budget status \
--config config/billing-config.yaml
# Set up budget alerts with multiple channels
cba budget alerts setup \
--emails devops@company.com,finance@company.com \
--slack-webhook https://hooks.slack.com/your-webhook \
--webhook https://monitoring.company.com/webhooks/billing
# Test alert channels
cba alerts test \
--channels email,slack,webhook
# View alert history
cba alerts history \
--days 30 \
--severity critical,high
# Suppress alerts for maintenance
cba alerts suppress \
--resource-id i-1234567890abcdef0 \
--duration-hours 12 \
--reason "Scheduled maintenance"
Alert Configuration Examples
# config/alerts.yaml
notifications:
channels:
email:
type: email
smtp_server: smtp.company.com
smtp_port: 587
username: alerts@company.com
password: ${EMAIL_PASSWORD}
from_email: alerts@company.com
to_emails:
- devops@company.com
- finance@company.com
use_tls: true
slack:
type: slack
webhook_url: ${SLACK_WEBHOOK_URL}
channel: "#billing-alerts"
username: "CloudBillingBot"
icon_emoji: ":moneybag:"
webhook:
type: webhook
url: https://monitoring.company.com/webhooks/billing
method: POST
headers:
Authorization: "Bearer ${WEBHOOK_TOKEN}"
Content-Type: "application/json"
timeout: 30
retry_count: 3
alert_rules:
budget_warning:
enabled: true
severity: medium
cooldown_period: 60 # minutes
channels: [email, slack]
budget_critical:
enabled: true
severity: high
cooldown_period: 30
channels: [email, slack, webhook]
anomaly_detection:
enabled: true
min_confidence: 0.7
min_deviation_percentage: 20.0
channels: [email]
Configuration Management
# Create configuration file
cba config create --template production --output-file billing-config.yaml
# Validate configuration
cba config validate --config billing-config.yaml
# Show current configuration
cba config show --section providers
# Edit configuration interactively
cba config edit --section budget
# Merge configurations
cba config merge source-config.yaml --target-file billing-config.yaml --strategy merge
Reporting
# Generate monthly report
cba reports generate \
--period monthly \
--formats html,pdf \
--email finance@company.com
# Schedule daily reports
cba reports schedule \
--frequency daily \
--time 09:00 \
--recipients team@company.com
๐๏ธ Architecture
cloud-billing-automation/
โโโ cloud_billing_automation/ # Main package
โ โโโ core/ # Core infrastructure
โ โ โโโ config.py # Configuration management
โ โ โโโ credentials.py # Secure credential handling
โ โ โโโ exceptions.py # Custom exceptions
โ โโโ collectors/ # Data collection
โ โ โโโ base.py # Base collector interface
โ โ โโโ aws_collector.py # AWS billing data
โ โ โโโ azure_collector.py # Azure billing data
โ โ โโโ gcp_collector.py # GCP billing data
โ โโโ analyzers/ # Cost analysis
โ โ โโโ cost.py # Cost analysis & breakdown
โ โ โโโ anomaly.py # Anomaly detection
โ โ โโโ trend.py # Trend analysis
โ โ โโโ forecast.py # Cost forecasting
โ โโโ alerts/ # Alerting system
โ โ โโโ base.py # Base alert management
โ โ โโโ budget.py # Budget alert manager
โ โ โโโ anomaly.py # Anomaly alert manager
โ โ โโโ channels.py # Notification channels
โ โ โโโ templates.py # Alert templates
โ โโโ reports/ # Report generation
โ โโโ utils/ # Security and utility modules
โ โโโ security.py # IAM and access control
โ โโโ encryption.py # Data encryption utilities
โ โโโ validation.py # Input validation and sanitization
โ โโโ helpers.py # Formatting and data utilities
โ โโโ cli/ # Command-line interface
โ โ โโโ main.py # Main CLI application
โ โ โโโ commands/ # CLI command modules
โ โ โโโ analyze.py # Cost analysis commands
โ โ โโโ budget.py # Budget monitoring commands
โ โ โโโ alerts.py # Alert management commands
โ โ โโโ resources.py # Resource commands (planned)
โ โ โโโ reports.py # Report commands (planned)
โ โ โโโ credentials.py # Credential management commands
โ โ โโโ config.py # Configuration management commands
โโโ tests/ # Test suite
โโโ config/ # Configuration examples
โโโ docs/ # Documentation
โโโ examples/ # Usage examples
โโโ pyproject.toml # Project configuration
โโโ requirements.txt # Dependencies
โโโ setup.py # Setup script
โโโ README.md # This file
๐ง Development
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=cloud_billing_automation
# Run specific test categories
pytest tests/unit/
pytest tests/integration/
Code Quality
# Format code
black . tests/
# Lint code
flake8 . tests/
# Type checking
mypy .
Adding New Cloud Providers
- Create a new collector class inheriting from
BaseCollector - Implement required abstract methods:
authenticate()collect_billing_data()collect_resource_data()get_cost_breakdown()
- Add provider configuration to
Configclass - Update CLI commands and documentation
Adding New CLI Commands
- Create a new command module in
cli/commands/ - Inherit from
typer.Typerfor command structure - Implement command logic with proper error handling
- Add rich output formatting using
rich.console.Console - Register the command in the main CLI app
Adding New Alert Channels
- Create a new channel class inheriting from
BaseChannel - Implement
send()andtest_connection()methods - Add channel type to
ChannelManager._initialize_channels() - Create alert templates for the new channel
- Update configuration schema
๐ Current Implementation Status
โ Completed Features
-
Core Infrastructure
- โ Configuration management (YAML + environment variables)
- โ Secure credential storage (encrypted keyring)
- โ Comprehensive error handling
- โ Project structure and packaging
-
Data Collection & Analysis
- โ Multi-cloud billing data collection (AWS, Azure, GCP)
- โ Cost analysis and breakdown by multiple dimensions
- โ Anomaly detection with statistical methods
- โ Trend analysis and forecasting
- โ Resource-level cost analysis
-
Budget Monitoring & Alerting
- โ Budget threshold monitoring and alerts
- โ Multi-channel notifications (Email, Slack, Webhook)
- โ Alert escalation policies and suppression
- โ Dynamic alert templates (Jinja2)
- โ Real-time monitoring and history tracking
-
CLI Interface
- โ Rich terminal output with tables and progress bars
- โ Comprehensive command structure (analyze, budget, alerts)
- โ Professional error handling and validation
- โ Interactive configuration management
- โ Credential management commands
-
IAM & Security
- โ Role-based access control (RBAC)
- โ JWT-based session management
- โ Secure credential encryption (AES-256)
- โ Comprehensive audit logging
- โ Multi-cloud validation and sanitization
- โ Security utilities and helper functions
๐ง In Progress
- Tag Compliance - Automated tag validation and enforcement (next priority)
๐ Planned Features
- Idle Resource Detection - Identify and report unused resources
- Automated Reports - Scheduled reports with multiple formats
- CI/CD Integration - Pipeline integration examples
๐ Security Features
- Role-Based Access Control (RBAC) - Granular permissions with roles (admin, operator, viewer, billing_manager, devops)
- JWT Session Management - Secure token-based authentication with configurable timeouts
- AES-256 Encryption - Military-grade encryption for all sensitive data and credentials
- Comprehensive Audit Logging - Complete audit trail for all security events and operations
- Multi-Cloud Validation - Input validation and sanitization for AWS, Azure, and GCP
- Security Utilities - Password hashing, IP validation, secure file operations
- Account Lockout - Automatic account lockout after failed login attempts
- Session Revocation - Immediate session termination capabilities
- Secure Key Storage - Encrypted key management with restrictive file permissions
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ ๏ธ Author & Community
Built with passion and purpose by Harshhaa.
Your ideas, feedback, and contributions are what make this project better.
โก Made with โค๏ธ for DevOps Engineers by Harshhaa
Connect & Collaborate:
- GitHub: @NotHarshhaa
- Links: Links - Portfolio
- Portfolio: Portfolio
- CV Portfolio: CV Portfolio
- LinkedIn: Harshhaa Vardhan Reddy
โญ How You Can Support
If you found this project useful:
- โญ Star the repository to show your support
- ๐ข Share it with your friends and colleagues
- ๐ Open issues or submit pull requests to help improve it
๐ข Stay Connected
Join the community, share your experience, and help us grow!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloud_billing_automation-0.2.0.tar.gz.
File metadata
- Download URL: cloud_billing_automation-0.2.0.tar.gz
- Upload date:
- Size: 101.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f81a286ea0019ed4e0de7364d7f92aec7f7d7be7fa7995c0045603a976b25914
|
|
| MD5 |
881eccc86d5468420acb64dbc238952c
|
|
| BLAKE2b-256 |
7cf6e103c526363fe76f377be8992e200239ba7ea177fdbc7976f3bf0b4dde59
|
File details
Details for the file cloud_billing_automation-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cloud_billing_automation-0.2.0-py3-none-any.whl
- Upload date:
- Size: 111.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
397831d48a45bd76be107e636bd23d17b2ee3e7503d09c32383037f29e5e62d5
|
|
| MD5 |
593d89e9de5879d05aa28d2600d41922
|
|
| BLAKE2b-256 |
f1446b9f96e4a3cd2b401fa995301ea0b28fcb32ad3968d0e1df65ca75e3c543
|