IngRRD/add.html
Vincent Riquer 9bf4e00e16 Create RRD
2014-06-20 20:28:56 +02:00

149 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
# IngRRD (https://forge.riquer.fr/p/ingrrd/)
# Copyright (C) 2014 Vincent Riquer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. settings
if [ -n "$QUERY_STRING" ]
then
query_data="${QUERY_STRING//&/
}"
exprtime='[[:alnum:]-]+'
exprgraph='[[:alpha:]_]+'
while read name value
do
case $name in
start)
[[ $value =~ $exprtime ]] && start=$value
;;
end)
[[ $value =~ $exprtime ]] && end=$value
;;
esac
done <<<"${query_data//=/ }"
fi
readprevvalues() {
shift
for arg
do
prevvalues+=( "$arg" )
done
}
readprevvalues $(rrdtool lastupdate ingress.rrd | tail -n1)
cat <<-EOHTML
content-type: text/xml
Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>IngRRD - Add data</title>
</head>
<body>
<table style="border:1px solid black; border-collapse:collapse">
<tr>
<td style="border:1px solid black"><a href="/cgi/$webuser/?start=$start&amp;end=$end">Overview</a></td>
<td style="border:1px solid black">
<table>
<tr>
<td rowspan="2"><a href="?hist&amp;start=$start&amp;end=$end">History /</a></td>
<td>
<a href="?hist&amp;start=$start&amp;end=$end">Medals</a>
</td>
</tr>
<tr>
<td>
<a href="?hist&amp;show=all&amp;start=$start&amp;end=$end">All</a>
</td>
</tr>
</table>
</td>
<td style="background:black; color:white">Add data</td>
</tr>
</table>
EOHTML
if ! [ -w "$rrdfile" ]
then
rrdtool create ingress.rrd -s $((60*60)) \
DS:AP:GAUGE:$((2*24*60*60)):0:NaN \
DS:Explorer:GAUGE:$((48*60*60)):0:NaN \
DS:Seer:GAUGE:$((48*60*60)):0:NaN \
DS:XM:GAUGE:$((48*60*60)):0:NaN \
DS:Hacker:GAUGE:$((48*60*60)):0:NaN \
DS:Builder:GAUGE:$((48*60*60)):0:NaN \
DS:Connector:GAUGE:$((48*60*60)):0:NaN \
DS:Mind_Controller:GAUGE:$((48*60*60)):0:NaN \
DS:MU:GAUGE:$((48*60*60)):0:NaN \
DS:Longest_Link:GAUGE:$((48*60*60)):0:NaN \
DS:Largest_Field:GAUGE:$((48*60*60)):0:NaN \
DS:Recharger:GAUGE:$((48*60*60)):0:NaN \
DS:Liberator:GAUGE:$((48*60*60)):0:NaN \
DS:Pioneer:GAUGE:$((48*60*60)):0:NaN \
DS:Purifier:GAUGE:$((48*60*60)):0:NaN \
DS:Neutralized:GAUGE:$((48*60*60)):0:NaN \
DS:Links_Destroyed:GAUGE:$((48*60*60)):0:NaN \
DS:Fields_Destroyed:GAUGE:$((48*60*60)):0:NaN \
DS:Walked:GAUGE:$((48*60*60)):0:NaN \
DS:Guardian:GAUGE:$((48*60*60)):0:NaN \
DS:Link_Maintained:GAUGE:$((48*60*60)):0:NaN \
DS:Link_Length_x_Days:GAUGE:$((48*60*60)):0:NaN \
DS:Field_Held:GAUGE:$((48*60*60)):0:NaN \
DS:Field_x_Days:GAUGE:$((48*60*60)):0:NaN \
RRA:HWPREDICT:8760:8e-1:8e-1:$((24)) \
RRA:AVERAGE:99e-2:1:$((24*15)) \
RRA:MAX:99e-2:1:$((24*15)) \
RRA:AVERAGE:99e-2:4:$((24*180)) \
RRA:MAX:99e-2:4:$((24*180)) \
RRA:AVERAGE:99e-2:24:$(((4*365)+1)) \
RRA:MAX:99e-2:24:$(((4*365)+1)) \
RRA:AVERAGE:99e-2:$((24*30)):$(((32*365)+8)) \
RRA:MAX:99e-2:$((24*30)):$(((32*365)+8)) \
|| {
cat <<-EOHTML
<h1 style="color:red">Cannot create $rrdfile</h1>
</body>
</html>
EOHTML
exit
}
fi
cat <<-EOHTML
<form method="post" action="add">
<ul>
EOHTML
for indice in ${!uinames[@]}
do
echo "<li><input type=\"text\" name=\"${dsnames[indice]}\" value=\"${prevvalues[indice]}\" /> ${uinames[indice]}</li>"
done
cat <<-EOHTML
</ul>
<input type="hidden" name="time" value="$(date +%s)" />
<input type="hidden" name="start" value="$start" />
<input type="hidden" name="end" value="$end" />
<button type="submit" name="submit" value="send">Send</button>
</form>
</body>
</html>
EOHTML