HackersMang April 2026 Workshop
A hands-on workshop demonstrating how GitHub Copilot accelerates the development of self-healing systems on Azure.
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
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
- Python 3.10+
- Azure CLI installed
- An active Azure subscription
Demonstrates how GitHub Copilot generates the Azure SDK integration to authenticate and fetch live VM power states from Azure.
- Authenticates using
DefaultAzureCredentialโ automatically picks upaz loginsession (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)
1. Login to Azure
az login2. 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/activate3. Install dependencies
pip install -r monitor/requirements.txt4. 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-4o5. Run Stage 1
python monitor/vm_connector.py๐ 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
| 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) |
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.
- Infinite polling loop with configurable interval
- Color-coded live health status in the terminal
- Detects
stopped/deallocated/stoppingstates - Triggers
begin_start()with a 120s timeout โ non-blocking, picks up on next poll if Azure is slow - Tracks total heals performed per session
python monitor/vm_monitor.pyaz vm stop -g <resource-group> -n <vm-name> --skip-shutdown๐๏ธ 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
| 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 |
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.
- 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
python monitor/fleet_monitor.py# 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๐ 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 โ โ
โ
โโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโ
| 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 |
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.
- Calls
gpt-4ovia 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, orescalate(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
python monitor/ai_healer.py- Go to github.com/settings/tokens
- Click Generate new token (classic)
- No scopes needed โ just create and copy it
- Add to
monitor/.envasGITHUB_TOKEN=ghp_xxxx
๐ 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. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
| 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 |
| 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 |
This is a workshop repository for HackersMang April 2026.
Presented by @darshandineshbhandary