Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DevOps Toolbox

A comprehensive collection of DevOps and Site Reliability Engineering (SRE) scripts for monitoring, logging, backup, and deployment automation across AWS, Azure, GCP, and Kubernetes.

πŸ“‹ Table of Contents

✨ Features

  • Multi-cloud Support: AWS, Azure, GCP
  • Container Orchestration: Kubernetes, Docker, ECS
  • Zero-downtime Deployments: Blue-green deployment strategies
  • Comprehensive Monitoring: Health checks, uptime monitoring, service monitoring
  • Log Analysis: Parse, filter, and analyze logs from multiple sources
  • Disaster Recovery: Automated backup and recovery procedures
  • CI/CD Integration: Pipeline helpers and build automation

πŸš€ Installation

Clone or Copy

# Clone this toolbox to your preferred location
git clone <repository-url> devops-toolbox
cd devops-toolbox

# Make scripts executable
chmod +x monitoring/*.sh monitoring/*.py
chmod +x logs/*.sh logs/*.py
chmod +x backup/*.sh backup/*.py
chmod +x deployment/*.sh deployment/*.py

Install Dependencies

Python Requirements:

pip install requests  # For HTTP health checks

Go Requirements (for uptime monitor):

cd monitoring
go build uptime_monitor.go

System Requirements:

  • bash 4.0+
  • Python 3.7+
  • Docker (for container operations)
  • kubectl (for Kubernetes operations)
  • AWS CLI (for AWS operations)
  • Azure CLI (for Azure operations)
  • gcloud/gsutil (for GCP operations)

🎯 Quick Start

Health Check

# Check HTTP endpoint
./monitoring/health_check.py --http https://example.com

# Check SSL certificate
./monitoring/health_check.py --ssl example.com

# Check TCP port
./monitoring/health_check.py --tcp example.com:443

Monitor Services

# Monitor Docker containers
./monitoring/service_monitor.sh docker web-app db-container

# Monitor Kubernetes deployments
./monitoring/service_monitor.sh k8s production/my-app

Analyze Logs

# Parse and filter logs
./logs/log_analyzer.py /var/log/app.log --level ERROR --grep "timeout"

# Tail multiple sources
./logs/multitail.sh /var/log/app.log docker:web k8s:default/api

Backup Database

# Backup PostgreSQL to S3
./backup/db_backup.sh --s3 my-bucket backup postgres mydb

Deploy Application

# Deploy to Kubernetes
./deployment/deploy.sh k8s deployment.yaml production

# Blue-green deployment
./deployment/blue_green.sh deploy k8s myapp deployment.yaml production

πŸ›  Tools Overview

Monitoring

health_check.py

Multi-purpose health check script supporting HTTP, TCP, and SSL certificate checks.

Features:

  • HTTP/HTTPS endpoint monitoring
  • TCP port connectivity checks
  • SSL certificate expiration monitoring
  • Batch mode with JSON configuration
  • JSON output for integration with monitoring systems

Usage:

# Single HTTP check
./monitoring/health_check.py --http https://api.example.com

# Multiple checks with batch file
cat > checks.json << EOF
{
  "checks": [
    {"type": "http", "url": "https://api.example.com"},
    {"type": "tcp", "target": "db.example.com:5432"},
    {"type": "ssl", "hostname": "example.com"}
  ]
}
EOF

./monitoring/health_check.py --batch checks.json --json

service_monitor.sh

Monitor systemd services, Docker containers, Kubernetes deployments, and processes.

Features:

  • State tracking with notifications
  • Webhook and Slack integration
  • Continuous monitoring mode
  • Support for multiple service types

Usage:

# Monitor systemd services
./monitoring/service_monitor.sh systemd nginx postgresql

# Monitor with Slack notifications
export SLACK_WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
./monitoring/service_monitor.sh -c 60 docker web-app

# Monitor Kubernetes deployments
./monitoring/service_monitor.sh k8s production/api production/worker

uptime_monitor.go

Concurrent uptime monitor with statistics tracking.

Features:

  • Concurrent monitoring of multiple targets
  • Configurable check intervals
  • Uptime statistics and reporting
  • Response time tracking

Usage:

# Build
go build monitoring/uptime_monitor.go

# Monitor single URL
./uptime_monitor -url https://example.com -interval 60

# Monitor with config file
cat > monitor-config.json << EOF
{
  "targets": [
    {"name": "API", "url": "https://api.example.com", "interval": 30},
    {"name": "Web", "url": "https://example.com", "interval": 60}
  ]
}
EOF

./uptime_monitor -config monitor-config.json

Log Management

log_analyzer.py

Parse and analyze logs from various formats with filtering and statistics.

Features:

  • Multiple log format support (nginx, apache, syslog, JSON, etc.)
  • Pattern filtering and searching
  • Time-range filtering
  • Statistics generation
  • JSON output

Usage:

# Show errors from last 24 hours
./logs/log_analyzer.py /var/log/app.log --level ERROR --since 24

# Filter by pattern with regex
./logs/log_analyzer.py /var/log/app.log --grep "timeout|error" --regex

# Generate statistics
./logs/log_analyzer.py /var/log/app.log --stats

# JSON output for integration
./logs/log_analyzer.py /var/log/app.log --level ERROR --json

log_rotator.sh

Rotate, compress, and manage log files with cloud backup support.

Features:

  • Size and age-based rotation
  • Compression with pigz support
  • Cloud backup (S3, Azure)
  • Configurable retention

Usage:

# Rotate if size exceeds 100MB
./logs/log_rotator.sh -s 100 check-size /var/log/app.log

# Rotate with S3 backup
./logs/log_rotator.sh --s3 my-bucket rotate /var/log/app.log

# Clean old logs
./logs/log_rotator.sh clean /var/log

# Continuous monitoring
./logs/log_rotator.sh monitor /var/log/app.log

multitail.sh

Tail multiple log sources with colored output and filtering.

Features:

  • Multiple file sources
  • Docker container logs
  • Kubernetes pod logs
  • systemd journal logs
  • Pattern filtering and highlighting

Usage:

# Tail multiple files
./logs/multitail.sh /var/log/app.log /var/log/error.log

# Tail Docker containers
./logs/multitail.sh docker:web docker:api docker:db

# Tail Kubernetes pods
./logs/multitail.sh k8s:production/api k8s:production/worker

# Mix sources with filtering
./logs/multitail.sh -f "ERROR|WARN" -H "ERROR" \
  /var/log/app.log docker:web k8s:default/api

Backup & Recovery

cloud_backup.py

Multi-cloud backup tool with encryption and verification.

Features:

  • Archive creation with compression
  • SHA256 checksum verification
  • Multi-cloud upload (S3, Azure, GCS)
  • Exclude patterns
  • Dry-run mode

Usage:

# Backup to S3
./backup/cloud_backup.py /var/www /etc/nginx \
  --s3-bucket my-backups \
  --exclude "*.log" "*.tmp"

# Backup to multiple clouds
./backup/cloud_backup.py /data \
  --s3-bucket aws-backups \
  --azure-container azure-backups \
  --gcp-bucket gcp-backups

# Dry run
./backup/cloud_backup.py /data --s3-bucket my-backups --dry-run

db_backup.sh

Backup PostgreSQL, MySQL, MongoDB, and Redis databases.

Features:

  • Multiple database support
  • Compression and encryption
  • Cloud upload (S3, Azure)
  • Automated cleanup

Usage:

# Backup PostgreSQL
export PGPASSWORD="secret"
./backup/db_backup.sh backup postgres mydb localhost 5432 postgres

# Backup MySQL with S3 upload
export MYSQL_PASSWORD="secret"
./backup/db_backup.sh --s3 my-bucket backup mysql mydb

# Backup MongoDB
./backup/db_backup.sh backup mongodb mydb localhost 27017

# Cleanup old backups
./backup/db_backup.sh cleanup 30

disaster_recovery.sh

Restore backups and test recovery procedures.

Features:

  • Multi-cloud download
  • Checksum verification
  • Database restoration
  • Recovery testing
  • Recovery plan generation

Usage:

# Download backup from S3
./backup/disaster_recovery.sh download \
  s3://my-bucket/backups/db.sql.gz /tmp/db.sql.gz

# Verify backup integrity
./backup/disaster_recovery.sh verify /tmp/db.sql.gz

# Restore database
./backup/disaster_recovery.sh decompress /tmp/db.sql.gz
./backup/disaster_recovery.sh restore postgres /tmp/db.sql mydb

# Test recovery procedure
./backup/disaster_recovery.sh test /var/backups/db.sql.gz

# Show recovery plan
./backup/disaster_recovery.sh plan

Deployment & CI/CD

deploy.sh

Deploy applications to Kubernetes, Docker, AWS ECS, and systemd.

Features:

  • Multi-platform deployment
  • Health checks
  • Webhook notifications
  • Deployment logging

Usage:

# Deploy to Kubernetes
./deployment/deploy.sh k8s deployment.yaml production

# Deploy Docker container
./deployment/deploy.sh docker myapp:latest myapp-container 8080:80 .env

# Deploy to AWS ECS
./deployment/deploy.sh ecs production myapp task-definition.json

# Deploy systemd service
./deployment/deploy.sh systemd myapp /etc/systemd/system/myapp.service

# With Slack notifications
./deployment/deploy.sh --slack "$SLACK_WEBHOOK" k8s deployment.yaml prod

blue_green.sh

Zero-downtime blue-green deployments.

Features:

  • Kubernetes support
  • Docker support
  • AWS ECS support
  • Automatic rollback capability
  • Smoke testing

Usage:

# Deploy with blue-green strategy
./deployment/blue_green.sh deploy k8s myapp deployment.yaml production

# Rollback deployment
./deployment/blue_green.sh rollback k8s myapp production

# Check status
./deployment/blue_green.sh status

# Generate nginx config for Docker
./deployment/blue_green.sh nginx-config myapp 8080 9080 > nginx.conf

rollback.sh

Quick rollback for failed deployments.

Features:

  • Platform-specific rollback
  • Deployment history tracking
  • Automatic state management

Usage:

# Rollback Kubernetes deployment
./deployment/rollback.sh k8s myapp production

# Rollback to specific revision
./deployment/rollback.sh k8s myapp production 5

# Rollback Docker container
./deployment/rollback.sh docker myapp-container myapp:v1.0

# Rollback AWS ECS
./deployment/rollback.sh ecs production myapp

# View deployment history
./deployment/rollback.sh history
./deployment/rollback.sh history k8s myapp

ci_helper.py

CI/CD pipeline utilities for build info, artifacts, and notifications.

Features:

  • Git information extraction
  • Build info generation
  • Checksum calculation
  • Release notes generation
  • Docker image tagging
  • URL health checks
  • Webhook notifications

Usage:

# Generate build info
./deployment/ci_helper.py build-info -o build-info.json

# Calculate checksums
./deployment/ci_helper.py checksums dist/*.tar.gz -o checksums.json

# Generate release notes
./deployment/ci_helper.py release-notes v1.0.0 HEAD -o RELEASE_NOTES.md

# Tag and push Docker image
./deployment/ci_helper.py docker-tag myapp:latest latest v1.2.3
./deployment/ci_helper.py docker-push myapp latest v1.2.3

# Wait for deployment
./deployment/ci_helper.py wait-for-url https://example.com/health -t 300

# Send notification
./deployment/ci_helper.py notify "$WEBHOOK_URL" "Deployment successful" -s success

πŸ“š Examples

Complete CI/CD Pipeline

#!/bin/bash
set -euo pipefail

# Generate build info
./deployment/ci_helper.py build-info

# Run tests (your test commands here)
npm test

# Build Docker image
docker build -t myapp:latest .

# Tag image
GIT_SHA=$(git rev-parse --short HEAD)
./deployment/ci_helper.py docker-tag myapp:latest latest "$GIT_SHA"

# Push to registry
./deployment/ci_helper.py docker-push myapp latest "$GIT_SHA"

# Deploy with blue-green strategy
./deployment/blue_green.sh deploy k8s myapp k8s/deployment.yaml production

# Wait for health check
./deployment/ci_helper.py wait-for-url https://myapp.com/health -t 300

# Send success notification
./deployment/ci_helper.py notify "$SLACK_WEBHOOK" \
  "Deployment of myapp@$GIT_SHA successful" -s success

Backup and Disaster Recovery

#!/bin/bash
set -euo pipefail

# Backup databases
./backup/db_backup.sh --s3 my-backups backup postgres prod_db
./backup/db_backup.sh --s3 my-backups backup redis

# Backup application files
./backup/cloud_backup.py /var/www /etc/nginx \
  --s3-bucket my-backups \
  --exclude "*.log" "cache/*"

# Test recovery procedure
./backup/disaster_recovery.sh test /var/backups/postgres-prod_db-*.sql.gz

# Cleanup old backups
./backup/db_backup.sh cleanup 7

Monitoring Setup

#!/bin/bash

# Create monitoring config
cat > monitors.json << EOF
{
  "checks": [
    {"type": "http", "url": "https://api.example.com/health", "expected_status": 200},
    {"type": "http", "url": "https://example.com", "expected_status": 200},
    {"type": "tcp", "target": "db.example.com:5432"},
    {"type": "ssl", "hostname": "example.com"}
  ]
}
EOF

# Run health checks
./monitoring/health_check.py --batch monitors.json --json > health-report.json

# Monitor services continuously
./monitoring/service_monitor.sh -c 60 \
  --slack "$SLACK_WEBHOOK" \
  docker web api worker

πŸ“¦ Requirements

Core Tools

  • bash 4.0+
  • Python 3.7+
  • curl
  • jq (for JSON processing)

Cloud CLI Tools

  • AWS CLI (for AWS operations)
  • Azure CLI (for Azure operations)
  • gcloud/gsutil (for GCP operations)

Container Tools

  • Docker (for container operations)
  • docker-compose (optional)
  • kubectl (for Kubernetes operations)

Database Tools

  • pg_dump/psql (for PostgreSQL)
  • mysqldump/mysql (for MySQL)
  • mongodump/mongorestore (for MongoDB)
  • redis-cli (for Redis)

βš™οΈ Configuration

Environment Variables

Most scripts support configuration via environment variables:

# Monitoring
export SLACK_WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK"
export NOTIFICATION_WEBHOOK="https://your-webhook.com/notify"

# Backup
export S3_BUCKET="my-backups"
export AZURE_CONTAINER="backups"
export BACKUP_DIR="/var/backups"
export KEEP_DAYS="30"

# Deployment
export DEPLOYMENT_DIR="/opt/deployments"
export LOG_FILE="/var/log/deployments.log"

# Database credentials
export PGPASSWORD="postgres-password"
export MYSQL_PASSWORD="mysql-password"
export MONGODB_PASSWORD="mongo-password"
export REDIS_PASSWORD="redis-password"

Configuration Files

Many scripts support JSON configuration files for batch operations and complex setups.

🀝 Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

πŸ“„ License

This toolbox is provided as-is for DevOps and SRE work. Customize and extend as needed for your infrastructure.

πŸ”— Additional Resources

πŸ†˜ Support

For issues, questions, or contributions:

  1. Check the script's --help output for detailed usage
  2. Review the examples in this README
  3. Open an issue in the repository

Built with ❀️ for DevOps and SRE teams

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages