nuno ревизий этого фрагмента 1 month ago. К ревизии
1 file changed, 39 insertions
gistfile1.txt(файл создан)
| @@ -0,0 +1,39 @@ | |||
| 1 | + | function 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 | + | local endpoint_display | |
| 23 | + | endpoint_display=$(resolve::ip "$endpoint") | |
| 24 | + | [[ -z "$endpoint_display" ]] && endpoint_display="$endpoint" | |
| 25 | + | resolved_data+="${ts}|${client}|${endpoint_display}|${event}|${count}|${gap_seconds}"$'\n' | |
| 26 | + | (( ${#client} > w_client )) && w_client=${#client} | |
| 27 | + | (( ${#endpoint_display} > w_endpoint )) && w_endpoint=${#endpoint_display} | |
| 28 | + | done <<< "$data" | |
| 29 | + | (( w_client += 2 )) | |
| 30 | + | (( w_endpoint += 2 )) | |
| 31 | + | ||
| 32 | + | ui::logs::wg_section_header | |
| 33 | + | while IFS='|' read -r ts client endpoint event count gap_seconds; do | |
| 34 | + | [[ -z "$ts" ]] && continue | |
| 35 | + | ui::logs::wg_row "$ts" "$client" "$endpoint" "$event" \ | |
| 36 | + | "$count" "$w_client" "$w_endpoint" "$gap_seconds" | |
| 37 | + | done <<< "$resolved_data" | |
| 38 | + | printf "\n" | |
| 39 | + | } | |
Новее
Позже