#!/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)" type="$(jq -r '.type' < $data | head -n 1)" if [[ "$type" == "ping" ]]; then timedata="$(jq -r '.time' < $data | tail -n $lim)" while read line; do echo -n 's@'"'"'>'"$line"' $tmp elif [[ "$type" == "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@'"'"'>'"$line"' $tmp elif [[ "$type" == "port" ]]; then timedata="$(jq -r '.status' < $data | tail -n $lim)" 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@'"'"'>'"$line"' $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