diff --git a/docker/bench/run-ab.sh b/docker/bench/run-ab.sh index 815f1f3..f1868b4 100644 --- a/docker/bench/run-ab.sh +++ b/docker/bench/run-ab.sh @@ -30,8 +30,8 @@ upload_to_hastebin() { } parse_to_csv() { - local input=$log_file - local output=/log/scan.csv + local input="$1" + local output="$2" local output_dir=$(dirname "$output") # Ensure the output directory exists @@ -45,18 +45,35 @@ parse_to_csv() { exit 1 fi - : > "$output" # Clear output file before appending + # Write CSV header + echo "URL,Time (ms),Status,Test Type" > "$output" - grep -Eo 'https?://[^ ]+' "$input" | sort -u | while read -r url; do - local ttfb_line=$(grep -m 1 "$url" "$input" | grep 'TTFB test passed' | awk -F'Mean TTFB: ' '{print $2}') - local ab_line=$(grep -m 1 "$url" "$input" | grep 'ApacheBench test passed' | awk -F'Average time: ' '{print $2}') - local ttfb_test=${ttfb_line%ms.*} - local ab_test=${ab_line% milliseconds.*} - if [[ -n "$ttfb_test" || -n "$ab_test" ]]; then - if [[ -z "$ttfb_test" ]]; then ttfb_test="N/A"; fi - if [[ -z "$ab_test" ]]; then ab_test="N/A"; fi - echo "$url,$ttfb_test,$ab_test" >> "$output" + grep -E 'TTFB test|ApacheBench test' "$input" | while IFS= read -r line; do + local url=$(echo "$line" | grep -Eo 'https?://[^ ]+') + local time + local status + local test_type + + if [[ "$line" =~ "TTFB test passed" ]]; then + time=$(echo "$line" | awk -F'Mean TTFB: ' '{print $2}' | awk '{print $1}') + status="pass" + test_type="TTFB" + elif [[ "$line" =~ "ApacheBench test passed" ]]; then + time=$(echo "$line" | awk -F'Average time: ' '{print $2}' | awk '{print $1}') + status="pass" + test_type="AB" + elif [[ "$line" =~ "TTFB test failed" ]]; then + time="N/A" # Indicate not applicable or failed to obtain time + status="fail" + test_type="TTFB" + elif [[ "$line" =~ "ApacheBench test failed" ]]; then + time="N/A" # Indicate not applicable or failed to obtain time + status="fail" + test_type="AB" fi + + # Output to CSV + echo "$url,$time,$status,$test_type" >> "$output" done }