Skip to content

Commit e8272bb

Browse files
CopilotMossaka
andcommitted
docs: add documentation for awf logs stats and summary commands
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
1 parent 7205ca2 commit e8272bb

4 files changed

Lines changed: 261 additions & 4 deletions

File tree

docs-site/src/content/docs/reference/cli-reference.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,118 @@ awf logs --source running -f
232232
Log sources are auto-discovered in this order: running containers, `AWF_LOGS_DIR` environment variable, then preserved log directories in `/tmp/squid-logs-*`.
233233
:::
234234

235+
### `awf logs stats`
236+
237+
Show aggregated statistics from firewall logs.
238+
239+
```bash
240+
awf logs stats [options]
241+
```
242+
243+
:::note[stats vs summary]
244+
Use `awf logs stats` for terminal output (defaults to colorized `pretty` format). Use `awf logs summary` for CI/CD integration (defaults to `markdown` format for `$GITHUB_STEP_SUMMARY`). Both commands provide the same data in different default formats.
245+
:::
246+
247+
#### Options
248+
249+
| Option | Type | Default | Description |
250+
|--------|------|---------|-------------|
251+
| `--format <format>` | string | `pretty` | Output format: `json`, `markdown`, `pretty` |
252+
| `--source <path>` | string | auto | Path to log directory or `running` for live container |
253+
254+
#### Output Formats
255+
256+
| Format | Description |
257+
|--------|-------------|
258+
| `pretty` | Colorized terminal output with summary and domain breakdown (default) |
259+
| `markdown` | Markdown table format suitable for documentation |
260+
| `json` | Structured JSON for programmatic consumption |
261+
262+
#### Examples
263+
264+
```bash
265+
# Show stats with colorized terminal output
266+
awf logs stats
267+
268+
# Get stats in JSON format for scripting
269+
awf logs stats --format json
270+
271+
# Get stats in markdown format
272+
awf logs stats --format markdown
273+
274+
# Use a specific log directory
275+
awf logs stats --source /tmp/squid-logs-1234567890
276+
```
277+
278+
#### Example Output (Pretty)
279+
280+
```
281+
Firewall Statistics
282+
────────────────────────────────────────
283+
284+
Total Requests: 150
285+
Allowed: 145 (96.7%)
286+
Denied: 5 (3.3%)
287+
Unique Domains: 12
288+
289+
Domains:
290+
api.github.com 50 allowed, 0 denied
291+
registry.npmjs.org 95 allowed, 0 denied
292+
evil.com 0 allowed, 5 denied
293+
```
294+
295+
### `awf logs summary`
296+
297+
Generate summary report optimized for GitHub Actions step summaries.
298+
299+
```bash
300+
awf logs summary [options]
301+
```
302+
303+
#### Options
304+
305+
| Option | Type | Default | Description |
306+
|--------|------|---------|-------------|
307+
| `--format <format>` | string | `markdown` | Output format: `json`, `markdown`, `pretty` |
308+
| `--source <path>` | string | auto | Path to log directory or `running` for live container |
309+
310+
:::tip[GitHub Actions]
311+
The `summary` command defaults to markdown format, making it perfect for piping directly to `$GITHUB_STEP_SUMMARY`.
312+
:::
313+
314+
#### Examples
315+
316+
```bash
317+
# Generate markdown summary (default)
318+
awf logs summary
319+
320+
# Add to GitHub Actions step summary
321+
awf logs summary >> $GITHUB_STEP_SUMMARY
322+
323+
# Get summary in JSON format
324+
awf logs summary --format json
325+
326+
# Get summary with colorized terminal output
327+
awf logs summary --format pretty
328+
```
329+
330+
#### Example Output (Markdown)
331+
332+
```markdown
333+
### Firewall Activity
334+
335+
<details>
336+
<summary>150 requests | 145 allowed | 5 blocked | 12 unique domains</summary>
337+
338+
| Domain | Allowed | Denied |
339+
|--------|---------|--------|
340+
| api.github.com | 50 | 0 |
341+
| registry.npmjs.org | 95 | 0 |
342+
| evil.com | 0 | 5 |
343+
344+
</details>
345+
```
346+
235347
## See Also
236348

237349
- [Quick Start Guide](/gh-aw-firewall/quickstart) - Getting started with examples

docs/github_actions.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,79 @@ If you currently have manual Squid proxy configuration, you can replace it with
8787
'copilot --prompt "..."'
8888
```
8989
90+
## Generating Firewall Summaries
91+
92+
The `awf logs summary` command generates markdown output optimized for GitHub Actions step summaries, eliminating the need for manual log parsing scripts.
93+
94+
### Basic Usage
95+
96+
```yaml
97+
- name: Run command through firewall
98+
run: |
99+
sudo awf \
100+
--allow-domains github.com,api.github.com \
101+
'your-command-here'
102+
103+
- name: Generate firewall summary
104+
if: always()
105+
run: awf logs summary >> $GITHUB_STEP_SUMMARY
106+
```
107+
108+
### Complete Example
109+
110+
```yaml
111+
jobs:
112+
test:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- uses: actions/checkout@v4
116+
117+
- name: Install Firewall
118+
run: |
119+
curl -sSL https://raw.githubusercontent.com/githubnext/gh-aw-firewall/main/install.sh | sudo bash
120+
121+
- name: Test with Firewall
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.COPILOT_CLI_TOKEN }}
124+
run: |
125+
sudo -E awf \
126+
--allow-domains github.com,api.github.com,registry.npmjs.org \
127+
'npx @github/copilot@latest --prompt "Hello"'
128+
129+
- name: Generate firewall summary
130+
if: always()
131+
run: awf logs summary >> $GITHUB_STEP_SUMMARY
132+
```
133+
134+
The summary appears as a collapsible section in your workflow run showing:
135+
- Total requests, allowed, and blocked counts
136+
- Table of all domains with their allowed/denied request counts
137+
138+
### Output Formats
139+
140+
```bash
141+
# Default: Markdown (for $GITHUB_STEP_SUMMARY)
142+
awf logs summary
143+
144+
# JSON format for programmatic processing
145+
awf logs summary --format json
146+
147+
# Pretty format for terminal output
148+
awf logs summary --format pretty
149+
```
150+
151+
### Getting Statistics
152+
153+
For detailed statistics without adding to step summary:
154+
155+
```bash
156+
# Pretty terminal output
157+
awf logs stats
158+
159+
# JSON for scripting
160+
awf logs stats --format json
161+
```
162+
90163
## MCP Server Configuration for Copilot CLI
91164

92165
### Overview

docs/logging_quickref.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,50 @@ docker exec awf-squid grep "curl" /var/log/squid/access.log
188188

189189
## Statistics
190190

191-
### Total Requests
191+
### Using `awf logs stats`
192+
193+
Get aggregated statistics including total requests, allowed/denied counts, and per-domain breakdown:
194+
195+
```bash
196+
# Pretty terminal output (default)
197+
awf logs stats
198+
199+
# JSON format for scripting
200+
awf logs stats --format json
201+
202+
# Markdown format
203+
awf logs stats --format markdown
204+
```
205+
206+
### Using `awf logs summary` for GitHub Actions
207+
208+
Generate a markdown summary optimized for GitHub Actions step summaries:
209+
210+
```bash
211+
# Add summary to GitHub Actions step summary
212+
awf logs summary >> $GITHUB_STEP_SUMMARY
213+
```
214+
215+
### Manual Statistics Queries
216+
217+
#### Total Requests
192218
```bash
193219
docker exec awf-squid wc -l /var/log/squid/access.log
194220
```
195221

196-
### Blocked vs Allowed Count
222+
#### Blocked vs Allowed Count
197223
```bash
198224
echo "Blocked: $(docker exec awf-squid grep -c TCP_DENIED /var/log/squid/access.log)"
199225
echo "Allowed: $(docker exec awf-squid grep -cE 'TCP_TUNNEL|TCP_MISS' /var/log/squid/access.log)"
200226
```
201227

202-
### Top 10 Accessed Domains
228+
#### Top 10 Accessed Domains
203229
```bash
204230
docker exec awf-squid awk '{print $3}' /var/log/squid/access.log | \
205231
sort | uniq -c | sort -rn | head -10
206232
```
207233

208-
### Unique Client IPs
234+
#### Unique Client IPs
209235
```bash
210236
docker exec awf-squid awk '{split($2,a,":"); print a[1]}' /var/log/squid/access.log | sort -u
211237
```

docs/usage.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,52 @@ awf logs --format json | jq -s 'group_by(.isAllowed) | map({allowed: .[0].isAllo
538538

539539
## Log Analysis
540540

541+
### Using `awf logs stats`
542+
543+
Get aggregated statistics from firewall logs including total requests, allowed/denied counts, and per-domain breakdown:
544+
545+
```bash
546+
# Pretty terminal output (default)
547+
awf logs stats
548+
549+
# JSON format for scripting
550+
awf logs stats --format json
551+
552+
# Markdown format
553+
awf logs stats --format markdown
554+
```
555+
556+
Example output:
557+
```
558+
Firewall Statistics
559+
────────────────────────────────────────
560+
561+
Total Requests: 150
562+
Allowed: 145 (96.7%)
563+
Denied: 5 (3.3%)
564+
Unique Domains: 12
565+
566+
Domains:
567+
api.github.com 50 allowed, 0 denied
568+
registry.npmjs.org 95 allowed, 0 denied
569+
evil.com 0 allowed, 5 denied
570+
```
571+
572+
### Using `awf logs summary` (GitHub Actions)
573+
574+
Generate a markdown summary optimized for GitHub Actions:
575+
576+
```bash
577+
# Generate markdown summary and append to step summary
578+
awf logs summary >> $GITHUB_STEP_SUMMARY
579+
```
580+
581+
This creates a collapsible summary in your GitHub Actions workflow output showing all allowed and blocked domains.
582+
583+
### Manual Log Queries
584+
585+
For more granular analysis, you can query the logs directly:
586+
541587
Find all blocked domains:
542588
```bash
543589
docker exec awf-squid grep "TCP_DENIED" /var/log/squid/access.log | awk '{print $3}' | sort -u

0 commit comments

Comments
 (0)