|
| 1 | +--- |
| 2 | +name: awf-debug-tools |
| 3 | +description: Practical Python scripts for debugging awf - parse logs, diagnose issues, inspect containers, test domains |
| 4 | +allowed-tools: Bash(python:*), Bash(docker:*), Bash(sudo:*), Read |
| 5 | +--- |
| 6 | + |
| 7 | +# AWF Debug Tools |
| 8 | + |
| 9 | +A collection of practical Python scripts that help agents efficiently debug and operate the awf firewall. These scripts reduce verbose Docker/log output by 80%+ and provide actionable insights instead of raw data dumps. |
| 10 | + |
| 11 | +## Why These Scripts? |
| 12 | + |
| 13 | +**Problem:** Docker commands and log files are verbose and hard for agents to parse. Diagnosing issues requires 10+ manual commands and produces noisy output that wastes tokens. |
| 14 | + |
| 15 | +**Solution:** One script replaces 5-10 manual commands with clean, filtered output optimized for agent consumption. All scripts support JSON format for easy parsing. |
| 16 | + |
| 17 | +## Available Scripts |
| 18 | + |
| 19 | +All scripts are located in `.claude/skills/awf-debug-tools/scripts/`: |
| 20 | + |
| 21 | +1. **parse-squid-logs.py** - Parse Squid logs and extract blocked domains with counts |
| 22 | +2. **diagnose-awf.py** - Run automated diagnostic checks on container health and configuration |
| 23 | +3. **inspect-containers.py** - Show concise container status without verbose docker output |
| 24 | +4. **test-domain.py** - Test if specific domain is reachable through the firewall |
| 25 | + |
| 26 | +## Quick Start |
| 27 | + |
| 28 | +### Parse Logs to Find Blocked Domains |
| 29 | + |
| 30 | +```bash |
| 31 | +# Auto-discover logs and show all domains |
| 32 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py |
| 33 | + |
| 34 | +# Show only blocked domains |
| 35 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --blocked-only |
| 36 | + |
| 37 | +# Filter by domain |
| 38 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --domain github.com |
| 39 | + |
| 40 | +# Show top 10, JSON output |
| 41 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --top 10 --format json |
| 42 | +``` |
| 43 | + |
| 44 | +### Run Automated Diagnostics |
| 45 | + |
| 46 | +```bash |
| 47 | +# Quick health check |
| 48 | +python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py |
| 49 | + |
| 50 | +# Detailed output |
| 51 | +python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py --verbose |
| 52 | + |
| 53 | +# JSON output for agent parsing |
| 54 | +python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py --format json |
| 55 | +``` |
| 56 | + |
| 57 | +### Inspect Container Status |
| 58 | + |
| 59 | +```bash |
| 60 | +# Inspect all containers |
| 61 | +python .claude/skills/awf-debug-tools/scripts/inspect-containers.py |
| 62 | + |
| 63 | +# Specific container only |
| 64 | +python .claude/skills/awf-debug-tools/scripts/inspect-containers.py --container awf-squid |
| 65 | + |
| 66 | +# Show only logs |
| 67 | +python .claude/skills/awf-debug-tools/scripts/inspect-containers.py --logs-only |
| 68 | + |
| 69 | +# JSON output |
| 70 | +python .claude/skills/awf-debug-tools/scripts/inspect-containers.py --format json |
| 71 | +``` |
| 72 | + |
| 73 | +### Test Domain Reachability |
| 74 | + |
| 75 | +```bash |
| 76 | +# Test if domain is allowed |
| 77 | +python .claude/skills/awf-debug-tools/scripts/test-domain.py github.com |
| 78 | + |
| 79 | +# Test blocked domain with fix suggestion |
| 80 | +python .claude/skills/awf-debug-tools/scripts/test-domain.py npmjs.org --suggest-fix |
| 81 | + |
| 82 | +# Check allowlist only (no log lookup) |
| 83 | +python .claude/skills/awf-debug-tools/scripts/test-domain.py api.github.com --check-allowlist |
| 84 | + |
| 85 | +# JSON output |
| 86 | +python .claude/skills/awf-debug-tools/scripts/test-domain.py github.com --format json |
| 87 | +``` |
| 88 | + |
| 89 | +## Common Workflows |
| 90 | + |
| 91 | +### Workflow 1: Debugging Blocked Requests |
| 92 | + |
| 93 | +When a command fails due to blocked domain: |
| 94 | + |
| 95 | +```bash |
| 96 | +# 1. Run diagnostics to check overall health |
| 97 | +python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py |
| 98 | + |
| 99 | +# 2. Parse logs to find which domains were blocked |
| 100 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --blocked-only |
| 101 | + |
| 102 | +# 3. Test specific domain and get fix suggestion |
| 103 | +python .claude/skills/awf-debug-tools/scripts/test-domain.py npmjs.org --suggest-fix |
| 104 | + |
| 105 | +# 4. Apply the suggested fix |
| 106 | +sudo awf --allow-domains github.com,npmjs.org 'your-command' |
| 107 | +``` |
| 108 | + |
| 109 | +### Workflow 2: Container Health Check |
| 110 | + |
| 111 | +When containers aren't starting or behaving unexpectedly: |
| 112 | + |
| 113 | +```bash |
| 114 | +# 1. Check container status and recent logs |
| 115 | +python .claude/skills/awf-debug-tools/scripts/inspect-containers.py |
| 116 | + |
| 117 | +# 2. Run full diagnostics |
| 118 | +python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py --verbose |
| 119 | + |
| 120 | +# 3. If issues found, check Squid logs for errors |
| 121 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py |
| 122 | +``` |
| 123 | + |
| 124 | +### Workflow 3: Agent Automated Debugging |
| 125 | + |
| 126 | +For agents to diagnose issues without human intervention: |
| 127 | + |
| 128 | +```bash |
| 129 | +# Run all checks with JSON output |
| 130 | +python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py --format json | jq . |
| 131 | + |
| 132 | +# Parse blocked domains |
| 133 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --blocked-only --format json | jq . |
| 134 | + |
| 135 | +# Test each blocked domain |
| 136 | +python .claude/skills/awf-debug-tools/scripts/test-domain.py npmjs.org --format json | jq . |
| 137 | +``` |
| 138 | + |
| 139 | +## Output Formats |
| 140 | + |
| 141 | +All scripts support two output formats: |
| 142 | + |
| 143 | +- **table/text** (default): Human-readable format with clear sections and alignment |
| 144 | +- **json**: Machine-readable format optimized for agent parsing |
| 145 | + |
| 146 | +Use `--format json` to get structured output that's easy to parse programmatically. |
| 147 | + |
| 148 | +## Exit Codes |
| 149 | + |
| 150 | +All scripts use consistent exit codes: |
| 151 | + |
| 152 | +- **0**: Success (no issues found, domain allowed, etc.) |
| 153 | +- **1**: Issues found (blocked domains, failed checks, domain blocked) |
| 154 | +- **2**: Error (missing logs, invalid arguments, etc.) |
| 155 | + |
| 156 | +## No Dependencies |
| 157 | + |
| 158 | +All scripts use Python 3.8+ stdlib only. No `pip install` required. They work out of the box on any system with Python 3.8+. |
| 159 | + |
| 160 | +## Script Reference |
| 161 | + |
| 162 | +### parse-squid-logs.py |
| 163 | + |
| 164 | +**Purpose:** Extract blocked domains from Squid logs with counts and statistics. |
| 165 | + |
| 166 | +**Key Options:** |
| 167 | +- `--blocked-only` - Show only blocked domains |
| 168 | +- `--domain DOMAIN` - Filter by specific domain |
| 169 | +- `--top N` - Show top N domains by request count |
| 170 | +- `--format {table,json}` - Output format |
| 171 | + |
| 172 | +**Auto-discovers logs** from running containers, preserved logs, or work directories. |
| 173 | + |
| 174 | +### diagnose-awf.py |
| 175 | + |
| 176 | +**Purpose:** Run automated diagnostic checks and report issues with fixes. |
| 177 | + |
| 178 | +**Checks:** |
| 179 | +- Container status (running/stopped/missing) |
| 180 | +- Container health (Squid healthcheck) |
| 181 | +- Network connectivity (Squid reachable from agent) |
| 182 | +- DNS configuration |
| 183 | +- Squid config validation |
| 184 | +- Common issues (port conflicts, orphaned containers) |
| 185 | + |
| 186 | +**Key Options:** |
| 187 | +- `--verbose` - Show detailed check output |
| 188 | +- `--format {text,json}` - Output format |
| 189 | + |
| 190 | +### inspect-containers.py |
| 191 | + |
| 192 | +**Purpose:** Show concise container status without verbose docker output. |
| 193 | + |
| 194 | +**Shows:** |
| 195 | +- Container status and exit codes |
| 196 | +- IP addresses and network info |
| 197 | +- Health check status |
| 198 | +- Top 5 processes |
| 199 | +- Recent logs (last 5 lines) |
| 200 | + |
| 201 | +**Key Options:** |
| 202 | +- `--container NAME` - Inspect specific container only |
| 203 | +- `--logs-only` - Show only recent logs |
| 204 | +- `--tail N` - Number of log lines (default: 5) |
| 205 | +- `--format {text,json}` - Output format |
| 206 | + |
| 207 | +### test-domain.py |
| 208 | + |
| 209 | +**Purpose:** Test if domain is reachable through the firewall. |
| 210 | + |
| 211 | +**Checks:** |
| 212 | +- If domain is in Squid allowlist |
| 213 | +- If domain appears in recent Squid logs |
| 214 | +- Whether requests were allowed or blocked |
| 215 | + |
| 216 | +**Key Options:** |
| 217 | +- `--check-allowlist` - Only check allowlist, don't check logs |
| 218 | +- `--suggest-fix` - Show suggested --allow-domains flag |
| 219 | +- `--format {text,json}` - Output format |
| 220 | + |
| 221 | +## Integration with Existing Skills |
| 222 | + |
| 223 | +- For manual debugging commands, see the `debug-firewall` skill |
| 224 | +- For MCP Gateway integration, see the `awf-mcp-gateway` skill |
| 225 | +- For general troubleshooting, see `docs/troubleshooting.md` |
| 226 | + |
| 227 | +## Performance |
| 228 | + |
| 229 | +All scripts are designed for fast execution: |
| 230 | + |
| 231 | +- `parse-squid-logs.py`: <2 seconds for typical log files |
| 232 | +- `diagnose-awf.py`: <3 seconds for all checks |
| 233 | +- `inspect-containers.py`: <2 seconds for both containers |
| 234 | +- `test-domain.py`: <1 second for domain check |
| 235 | + |
| 236 | +## Examples |
| 237 | + |
| 238 | +### Example 1: Find Blocked Domains |
| 239 | + |
| 240 | +```bash |
| 241 | +$ python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --blocked-only |
| 242 | + |
| 243 | +Blocked Domains (sorted by count): |
| 244 | + |
| 245 | + Domain Blocked Allowed Total |
| 246 | + ================================================= |
| 247 | + registry.npmjs.org 45 0 45 |
| 248 | + example.com 12 0 12 |
| 249 | + |
| 250 | +Total requests: 1234 |
| 251 | +Blocked: 57 (4.6%) |
| 252 | +Allowed: 1177 (95.4%) |
| 253 | +``` |
| 254 | + |
| 255 | +### Example 2: Diagnose Issues |
| 256 | + |
| 257 | +```bash |
| 258 | +$ python .claude/skills/awf-debug-tools/scripts/diagnose-awf.py |
| 259 | + |
| 260 | +AWF Diagnostic Report |
| 261 | +======================================== |
| 262 | +[✓] Containers: awf-squid (running), awf-agent (exited:0) |
| 263 | +[✓] Health: Squid healthy |
| 264 | +[✓] Network: awf-net exists ([{Subnet:172.30.0.0/24 Gateway:172.30.0.1}]) |
| 265 | +[✓] Connectivity: Squid reachable on 172.30.0.10:3128 |
| 266 | +[✓] DNS: DNS servers: 127.0.0.11, 8.8.8.8, 8.8.4.4 |
| 267 | +[✓] Config: 3 domains in allowlist (github.com, .github.com, api.github.com) |
| 268 | + |
| 269 | +Summary: All checks passed ✓ |
| 270 | +``` |
| 271 | + |
| 272 | +### Example 3: Test Domain |
| 273 | + |
| 274 | +```bash |
| 275 | +$ python .claude/skills/awf-debug-tools/scripts/test-domain.py npmjs.org --suggest-fix |
| 276 | + |
| 277 | +Testing: npmjs.org |
| 278 | + |
| 279 | +[✗] Allowlist check: Not in allowlist |
| 280 | +[✗] Reachability: Blocked (403 TCP_DENIED:HIER_NONE) |
| 281 | +[✗] Status: BLOCKED |
| 282 | + |
| 283 | +Suggested fix: |
| 284 | + awf --allow-domains github.com,npmjs.org 'your-command' |
| 285 | +``` |
| 286 | + |
| 287 | +## Tips for Agents |
| 288 | + |
| 289 | +1. **Use JSON output** for easy parsing: `--format json | jq .` |
| 290 | +2. **Chain commands** to get complete picture: diagnose → parse logs → test domain |
| 291 | +3. **Check exit codes** to determine if action needed (0 = ok, 1 = issues) |
| 292 | +4. **Use --suggest-fix** to get ready-to-use awf commands |
| 293 | +5. **Scripts auto-discover logs** - no need to specify paths in most cases |
| 294 | + |
| 295 | +## Troubleshooting |
| 296 | + |
| 297 | +**Script not found:** |
| 298 | +```bash |
| 299 | +# Use absolute path |
| 300 | +python /home/mossaka/developer/gh-aw-repos/gh-aw-firewall/.claude/skills/awf-debug-tools/scripts/parse-squid-logs.py |
| 301 | +``` |
| 302 | + |
| 303 | +**Permission denied on logs:** |
| 304 | +```bash |
| 305 | +# Squid logs require sudo to read |
| 306 | +sudo python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py --log-file /tmp/squid-logs-*/access.log |
| 307 | +``` |
| 308 | + |
| 309 | +**No logs found:** |
| 310 | +```bash |
| 311 | +# Run awf first to generate logs |
| 312 | +sudo awf --allow-domains github.com 'curl https://api.github.com' |
| 313 | + |
| 314 | +# Then parse |
| 315 | +python .claude/skills/awf-debug-tools/scripts/parse-squid-logs.py |
| 316 | +``` |
| 317 | + |
| 318 | +## Future Enhancements |
| 319 | + |
| 320 | +Planned scripts for future versions: |
| 321 | +- `analyze-traffic.py` - Analyze traffic patterns over time |
| 322 | +- `generate-allowlist.py` - Auto-generate allowlist from logs |
| 323 | +- `cleanup-awf.py` - Clean up orphaned resources |
| 324 | +- `benchmark-awf.py` - Performance testing utilities |
0 commit comments