Skip to content

Latest commit

ย 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Building Self-Healing Cloud Systems with GitHub Copilot

HackersMang April 2026 Workshop
A hands-on workshop demonstrating how GitHub Copilot accelerates the development of self-healing systems on Azure.


๐Ÿ—๏ธ Architecture Overview

Local App (Python)
    โ”‚
    โ”œโ”€โ”€ az login  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Azure CLI (DefaultAzureCredential)
    โ”‚                                   โ”‚
    โ””โ”€โ”€ Azure SDK (Python) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ ComputeManagementClient
                                        โ”‚
                            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     List all VMs              Poll every 30s
                            โ”‚                       โ”‚
                     Parallel health          Detect failures
                       checks                      โ”‚
                            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        โ”‚
                               ๐Ÿค– GitHub Models
                               (gpt-4o via OpenAI SDK)
                                        โ”‚
                            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       AI Diagnose              AI Incident
                        failure                  Report
                            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        โ”‚
                               begin_start() in
                              background threads

๐Ÿ“ Project Structure

HackersMang-April-2026/
โ”œโ”€โ”€ monitor/
โ”‚   โ”œโ”€โ”€ vm_connector.py     # Stage 1 โ€” Connect & read VM state
โ”‚   โ”œโ”€โ”€ vm_monitor.py       # Stage 2 โ€” Single VM health monitor + auto-heal
โ”‚   โ”œโ”€โ”€ fleet_monitor.py    # Stage 3 โ€” Multi-VM fleet monitor (parallel)
โ”‚   โ”œโ”€โ”€ ai_healer.py        # Stage 4 โ€” AI-powered diagnosis + incident reports
โ”‚   โ”œโ”€โ”€ requirements.txt    # Python dependencies
โ”‚   โ””โ”€โ”€ .env                # Azure config (not committed)
โ””โ”€โ”€ README.md

โš™๏ธ Prerequisites

  • Python 3.10+
  • Azure CLI installed
  • An active Azure subscription

๐Ÿš€ Stage 1 โ€” Connect to Azure & Read VM State

Demonstrates how GitHub Copilot generates the Azure SDK integration to authenticate and fetch live VM power states from Azure.

What it does

  • Authenticates using DefaultAzureCredential โ€” automatically picks up az login session (no API keys needed)
  • Lists all Virtual Machines in the resource group with color-coded power states
  • Fetches the detailed power state of a target VM (running, stopped, deallocated)

Setup

1. Login to Azure

az login

2. Clone the repo and create a virtual environment

git clone https://github.com/Developer-Kommunity-24/HackersMang-April-2026.git
cd HackersMang-April-2026
python -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install -r monitor/requirements.txt

4. Configure environment variables

Create a monitor/.env file:

AZURE_SUBSCRIPTION_ID=<your-subscription-id>
AZURE_RESOURCE_GROUP=<your-resource-group>
AZURE_VM_NAME=<your-vm-name>

# Stage 4 only
GITHUB_TOKEN=<your-github-pat>
GITHUB_MODEL=gpt-4o

5. Run Stage 1

python monitor/vm_connector.py

Expected Output

๐Ÿ”Œ Connecting to Azure via DefaultAzureCredential...
โœ… Connected!

       ๐Ÿ–ฅ๏ธ  Virtual Machines in [your-resource-group]
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ VM Name          โ”ƒ Location  โ”ƒ Power State  โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ autoheal-test-vm โ”‚ centralus โ”‚ โœ… running   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ” Checking power state for VM: autoheal-test-vm
   Power State โ†’ running

Azure Policy Notes (Corporate Subscriptions)

Policy Required Setting
No public IPs on NICs Set Public IP to None when creating VM
No Premium_LRS disks Set OS disk type to Standard HDD (Standard_LRS)

๐Ÿš€ Stage 2 โ€” VM Health Monitor with Auto-Healing

Continuously polls the target VM every 30 seconds. If it enters an unhealthy state (stopped, deallocated, stopping), it automatically triggers begin_start() to recover it.

What it does

  • Infinite polling loop with configurable interval
  • Color-coded live health status in the terminal
  • Detects stopped / deallocated / stopping states
  • Triggers begin_start() with a 120s timeout โ€” non-blocking, picks up on next poll if Azure is slow
  • Tracks total heals performed per session

Run Stage 2

python monitor/vm_monitor.py

Simulate a failure (fast demo โ€” no deallocation)

az vm stop -g <resource-group> -n <vm-name> --skip-shutdown

Expected Output

๐Ÿ‘๏ธ  Starting monitor for VM: autoheal-test-vm
   Polling every 30s | Unhealthy states: {'stopped', 'deallocated', 'stopping', 'unknown'}

21:00:25  โœ… autoheal-test-vm โ†’ running
21:00:58  โŒ autoheal-test-vm โ†’ stopped

๐Ÿšจ VM is [stopped] โ€” triggering auto-heal...
โณ Waiting for VM to start (timeout: 120s)...
โœ… VM successfully healed and is now starting up!

   Total heals performed: 1
21:01:30  โœ… autoheal-test-vm โ†’ running

Key Learnings

Concept Detail
begin_start() Returns an LROPoller โ€” Azure long-running operation
poller.result(timeout=120) Blocks max 120s, then lets next poll verify state
--skip-shutdown Stops VM without deallocating โ€” hardware kept, faster recovery
Portal "Stop" button Always deallocates โ€” use CLI for demos

๐Ÿš€ Stage 3 โ€” Multi-VM Fleet Monitor (Parallel Self-Healing)

Upgrades from single-VM monitoring to watching the entire resource group fleet. Discovers all VMs automatically and monitors + heals them in parallel using background threads.

What it does

  • Auto-discovers all VMs in the resource group at startup
  • Checks health of all VMs in parallel (ThreadPoolExecutor)
  • Fires begin_start() heals in background daemon threads โ€” polling loop never blocks
  • Renders a live fleet status table every 30 seconds
  • Tracks cumulative heal count across the session

Run Stage 3

python monitor/fleet_monitor.py

Simulate multi-VM failure (the wow moment)

# Two terminals at once โ€” take down the whole fleet!
az vm stop -g <resource-group> -n autoheal-test-vm --skip-shutdown
az vm stop -g <resource-group> -n Dynatrace123 --skip-shutdown

Expected Output

๐Ÿ” Discovering VMs in resource group: rg-cp-darshan-dinesh-bhandary
Found 2 VM(s): Dynatrace123, autoheal-test-vm

 ๐Ÿ–ฅ๏ธ  Fleet Status  [21:27:58]  |  Heals: 5
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ VM Name          โ”ƒ Power State โ”ƒ Health โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ Dynatrace123     โ”‚ stopped     โ”‚   โŒ   โ”‚
โ”‚ autoheal-test-vm โ”‚ stopped     โ”‚   โŒ   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โšก Auto-healed 2 VM(s) this cycle

โœ… Dynatrace123 healed successfully
โœ… autoheal-test-vm healed successfully

 ๐Ÿ–ฅ๏ธ  Fleet Status  [21:28:28]  |  Heals: 5
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ VM Name          โ”ƒ Power State โ”ƒ Health โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ Dynatrace123     โ”‚ running     โ”‚   โœ…   โ”‚
โ”‚ autoheal-test-vm โ”‚ running     โ”‚   โœ…   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Learnings

Concept Detail
virtual_machines.list() Auto-discovers all VMs โ€” no hardcoded names
ThreadPoolExecutor Parallel health checks across all VMs simultaneously
daemon=True threads Heals run in background โ€” poll loop never blocked
Non-blocking design Polling stays on schedule regardless of Azure LRO speed

๐Ÿš€ Stage 4 โ€” AI-Powered Diagnosis & Incident Reports

Upgrades the fleet monitor with gpt-4o intelligence via GitHub Models. Instead of blindly restarting VMs, the system now diagnoses failures, recommends actions, and writes incident reports automatically.

What it does

  • Calls gpt-4o via GitHub Models (OpenAI-compatible, free with GitHub PAT)
  • AI diagnoses the failure based on VM name, state, and failure history
  • AI recommends the action: start, restart, or escalate (if too many failures)
  • Executes the recommended action automatically
  • AI writes a natural language incident report after each heal
  • Tracks per-VM failure history across the session

Run Stage 4

python monitor/ai_healer.py

Get a GitHub PAT (free, no special scopes needed)

  1. Go to github.com/settings/tokens
  2. Click Generate new token (classic)
  3. No scopes needed โ€” just create and copy it
  4. Add to monitor/.env as GITHUB_TOKEN=ghp_xxxx

Expected Output

๐Ÿ”Œ Connecting to Azure...
โœ… Azure connected!
๐Ÿค– Initializing AI (gpt-4o via GitHub Models)...
โœ… AI ready!

๐Ÿ–ฅ๏ธ  AI Fleet Monitor  [14:12:23]  |  Heals: 0
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ VM Name          โ”ƒ Power State โ”ƒ Health โ”ƒ Failures โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ autoheal-test-vm โ”‚ stopped     โ”‚   โŒ   โ”‚    -     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿšจ FAILURE DETECTED: autoheal-test-vm โ†’ stopped
๐Ÿค– Asking AI to diagnose...

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿง  AI Analysis โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Diagnosis: VM stopped likely due to OS instability.  โ”‚
โ”‚ Action:    start                                     โ”‚
โ”‚ Reason:    First failure โ€” safe to auto-recover.     โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โณ Executing [start] on autoheal-test-vm...
โœ… autoheal-test-vm healed in 34s
๐Ÿ“ Generating AI incident report...

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿ“‹ Incident Report โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ At 14:12 UTC, autoheal-test-vm entered a stopped     โ”‚
โ”‚ state. Automated recovery via begin_start() was      โ”‚
โ”‚ triggered and completed in ~34 seconds. Recommend    โ”‚
โ”‚ investigating OS crash logs to prevent recurrence.   โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Key Learnings

Concept Detail
GitHub Models Free gpt-4o inference using your GitHub PAT
OpenAI SDK + base_url Point any OpenAI-compatible client at GitHub Models
AI escalation logic After 3+ failures, AI recommends human escalation
Failure history context AI gets richer diagnosis with each subsequent failure

๐Ÿ—บ๏ธ Workshop Stages

Stage Description Status
Stage 1 Connect to Azure & read VM power state โœ… Done
Stage 2 Monitoring loop โ€” detect VM failures + auto-heal โœ… Done
Stage 3 Multi-VM fleet monitor โ€” parallel self-healing โœ… Done
Stage 4 AI-powered diagnosis + incident reports (GitHub Models) โœ… Done

๐Ÿค Contributing

This is a workshop repository for HackersMang April 2026.
Presented by @darshandineshbhandary

About

Building Self-Healing Cloud Systems with GitHub Copilot (talk)

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages