Последняя активность 1 month ago

gistfile1.txt Исходник
1function cmd::logs::show_wg_events() {
2 local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}" \
3 limit="${4:-50}" collapse="${5:-1}" \
4 since="${6:-}" filter_event="${7:-}" sort_order="${8:-desc}"
5
6 [[ ! -f "$WG_EVENTS_LOG" ]] && return 0
7
8 local data
9 data=$(json::wg_events \
10 "$WG_EVENTS_LOG" "$filter_name" "$filter_type" \
11 "$limit" "$collapse" "$since" "$filter_event" \
12 "$(ctx::endpoint_cache)" "$sort_order" \
13 2>/dev/null)
14
15 [[ -z "$data" ]] && return 0
16
17 # Resolve endpoints and measure column widths
18 local w_client=16 w_endpoint=16
19 local resolved_data=""
20 while IFS='|' read -r ts client endpoint event count gap_seconds; do
21 [[ -z "$ts" ]] && continue
22 (( ${#client} > w_client )) && w_client=${#client}
23 # Estimate endpoint column width — raw IP + " → resolved_name"
24 # Max annotation is " → " (3) + ~12 chars for hostname = ~15 extra
25 local ep_len=${#endpoint}
26 [[ -z "$endpoint" ]] && ep_len=1
27 (( ep_len > w_endpoint )) && w_endpoint=$ep_len
28 done <<< "$data"
29 (( w_client += 2 ))
30 # Add extra width for annotation (resolved name after →)
31 (( w_endpoint += 18 )) # " → resolved_name" typical max
32
33 echo "DEBUG: data_lines=$(echo "$data" | wc -l) resolved_lines=$(echo "$resolved_data" | wc -l)" >&2
34
35 ui::logs::wg_section_header
36 while IFS='|' read -r ts client endpoint event count gap_seconds resolved; do
37 [[ -z "$ts" ]] && continue
38 ui::logs::wg_row "$ts" "$client" "$endpoint" "$event" \
39 "$count" "$w_client" "$w_endpoint" "$gap_seconds" "$resolved"
40 done <<< "$resolved_data"
41 printf "\n"
42}