pkazlenka | 4690e83 | 2024-10-24 13:28:37 +0200 | [diff] [blame] | 1 | get_timestamp() { |
| 2 | # "update_latest_report" depends on this pattern (it looks for '%Y' which |
| 3 | # should match "20[0-9]{2} in this century). |
| 4 | # Make changes in "update_latest_report" if you change timestamp here |
| 5 | date +%Y-%m-%dT%H-%M |
| 6 | } |
| 7 | |
| 8 | update_latest_report_to() { |
| 9 | cp "$1" "$(echo $1|sed s/20[0-9]\\{2\\}.*/latest.html/)" |
Ievgeniia Zadorozhna | bed5b40 | 2025-09-04 13:36:16 +0200 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | check_cluster_deployment_exists() { |
| 13 | local cluster_name="$1" |
| 14 | echo "" |
| 15 | echo "Checking if ClusterDeployment '$cluster_name' exists..." |
| 16 | if ! kubectl get cld -A -o name | grep -q "/$cluster_name$"; then |
| 17 | echo "Error: ClusterDeployment '$cluster_name' not found in any namespace" |
| 18 | return 1 |
| 19 | fi |
| 20 | echo -e "ClusterDeployment '$cluster_name' found" |
| 21 | return 0 |
| 22 | } |
| 23 | |
| 24 | check_file_exists() { |
| 25 | local path="$1" |
| 26 | local desc="$2" |
| 27 | if [[ ! -f "$path" ]]; then |
| 28 | echo "Error: $desc file not found at $path" |
| 29 | return 1 |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | txt2html_net_ping_report() { |
| 34 | local in="$1" |
| 35 | local cluster_name="$2" |
| 36 | local out="$3" |
| 37 | |
| 38 | [[ -z "$in" ]] && { echo "Usage: txt2html_net_ping_report <input.txt> [cluster_name] [output.html]"; return 2; } |
| 39 | [[ ! -f "$in" ]] && { echo "No such file: $in"; return 2; } |
| 40 | |
| 41 | if [[ -z "$out" ]]; then |
| 42 | out="${in%.txt}.html" |
| 43 | [[ "$out" == "$in" ]] && out="$in.html" |
| 44 | fi |
| 45 | mkdir -p "$(dirname "$out")" || return 1 |
| 46 | |
| 47 | local ts |
| 48 | ts="$(get_timestamp)" |
| 49 | local cluster_esc_name="$cluster_name" |
| 50 | cluster_esc_name="${cluster_esc_name//&/&}" |
| 51 | cluster_esc_name="${cluster_esc_name//</<}" |
| 52 | cluster_esc_name="${cluster_esc_name//>/>}" |
| 53 | local title="Network Ping Report" |
| 54 | [[ -n "$cluster_esc_name" ]] && title="Network Ping Report [$cluster_esc_name]" |
| 55 | |
| 56 | { |
| 57 | |
| 58 | cat <<EOF |
| 59 | <!doctype html> |
| 60 | <html lang="en"><head> |
| 61 | <meta charset="utf-8"> |
| 62 | <title>$title</title> |
| 63 | <style> |
| 64 | body { font:14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin:20px; } |
| 65 | .summary { font-weight:600; margin:0 0 8px; } |
| 66 | .net { color:#0366d6; font-weight:600; } |
| 67 | .from { color:#555; font-weight:600; display:block; margin-top: 18px; margin-bottom: -12px; } |
| 68 | .pass { color:#1a7f37; font-weight:600; } |
| 69 | .fail { color:#e53935; font-weight:600; } |
| 70 | pre { background:#fafafa; border:1px solid #e5e5e5; padding:12px; overflow:auto; } |
| 71 | </style> |
| 72 | </head><body> |
| 73 | <h2>$title</h2> |
| 74 | <p style="color: gray; font-style: italic; font-size: 10px;">Generated at $ts</p> |
| 75 | <pre> |
| 76 | EOF |
| 77 | |
| 78 | awk ' |
| 79 | function esc(s){ gsub("&","&",s); gsub("<","<"); gsub(">",">"); return s } |
| 80 | { |
| 81 | raw=$0 |
| 82 | line=esc(raw) |
| 83 | gsub(/\+ PASS:/,"<span class=\"pass\">+ PASS:</span>",line) |
| 84 | gsub(/\- FAIL:/,"<span class=\"fail\">- FAIL:</span>",line) |
| 85 | if (raw ~ /^# Summary/) { print "<span class=\"summary\">" line "</span>"; next } |
| 86 | if (raw ~ /^--->/) { print "<span class=\"net\">" line "</span>"; next } |
| 87 | if (raw ~ /^=+/) { print "<span class=\"from\">" line "</span>"; next } |
| 88 | print line |
| 89 | }' "$in" |
| 90 | |
| 91 | cat <<'EOF' |
| 92 | </pre> |
| 93 | </body></html> |
| 94 | EOF |
| 95 | } > "$out" |
| 96 | |
| 97 | echo "Done: $out" |
| 98 | } |