dtr/webroot/uwu.shs

45 lines
1.4 KiB
Bash

#!/bin/bash
lim=120
if [[ "$1" != '' ]]; then
data="storage/data/$(basename $1)"
elif [[ "${get_data[id]}" != '' ]]; then
data="storage/data/$(basename ${get_data[id]})"
header "Content-Type: image/svg+xml"
else
exit 0
fi
label="$(jq -r '.label' < $data | head -n 1 | tr ' ' '_')"
start_date="$(jq -r '.date' < $data | tail -n $lim | head -n1)"
end_date="$(jq -r '.date' < $data | tail -n1)"
tmp="$(mktemp)"
if [[ "$(jq -r '.type' < $data | head -n 1)" == "ping" ]]; then
timedata="$(jq -r '.time' < $data | tail -n $lim)"
while read line; do
echo -n 's@'"'"'></circle@'"'"'><title>'"$line"'</title></circle@;'
done <<< "$(jq -r '"Name: \(.label)\\\\nPing time: \(.time)ms\\\\nDate: \(.date)"' < "$data" | tail -n $lim)" > $tmp
elif [[ "$(jq -r '.type' < $data | head -n 1)" == "req" ]]; then
timedata="$(jq -r '.status' < $data | tail -n $lim)"
a=""
for i in $timedata; do
if [[ "$i" -gt 0 ]]; then
a="${a}0#"
elif [[ "$i" == "0" ]]; then
a="${a}1#"
fi
done
timedata="$(tr '#' '\n' <<< "$a")"
while read line; do
echo -n 's@'"'"'></circle@'"'"'><title>'"$line"'</title></circle@;'
done <<< "$(jq -r '"Name: \(.label)\\\\nDate: \(.date)"' < "$data" | tail -n $lim)" > $tmp
fi
svg="$(echo -e "$label\n$timedata" | awk -f "${cfg[namespace]}/code/plot.awk")"
tr -d '\n' <<< "$svg" | sed -f $tmp | sed 's@###START_DATE###@'"$start_date"'@;s@###END_DATE###@'"$end_date"'@'
rm $tmp