#!/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 . . settings for lib in lib/* do source $lib done read_query_string template=AP:Explorer:Seer:XM:Walked:Builder:Connector:Mind_Controller:MU:Longest_Link:Largest_Field:Recharger:Liberator:Pioneer:Engineer:Purifier:Neutralized:Links_Destroyed:Fields_Destroyed:Guardian:Link_Maintained:Link_Length_x_Days:Field_Held:Field_x_Days:Mercenary:Hacker:Translator:Hackaton:Recruiter if [[ $REQUEST_METHOD == POST ]] then declare -A POST exprdsname='^[[:upper:][:lower:]_]+$' while read dsname value do if [[ $dsname =~ $exprdsname ]] then POST["$dsname"]="$value" fi done < <( sed 's/&/\n/g;s/=/ /g' ) POST["data"]="${POST["data"]//%0D%0A/ }" POST["data"]="${POST["data"]//%3A/:}" POST["data"]="${POST["data"]//+/ }" cat <<-EOHead Content-type: text/plain 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') EOHead cat <<-EOHead refresh: 0,url=/cgi/$webuser/?start=${POST["start"]}&end=${POST["end"]} EOHead echo if [[ $webuser == $AUTH_USER || $webuser == dev ]] then echo "Welcome agent $webuser"$'!\n\n' else echo 'Nice try!' exit fi while read ds junk do ds="${ds//ds[/}" ds="${ds//]*/}" datasets+=("$ds") done < <(rrdtool info "$rrdfile" |grep index) for ds in ${dsnames[@]} do if [[ ! ${datasets[@]} =~ $ds ]] then cp -f "$rrdfile" "$rrdfile".bak_add_$ds ./dsaddtor.pl "$rrdfile" $ds GAUGE $((48*60*60)) 0 NaN fi done while read date hour data do data=$(date -d "$date $hour" +%s):${data// /:} rrdtool update "$rrdfile" -t $template "${data//:0/:U}" 2>&1 done <<<"${POST["data"]}" else import_images & send_headers <<-EOHead content-type: text/xml EOHead cat <<-EOHTML IngRRD - $webuser - Import Data
EOHTML if ! [ -w "$rrdfile" ] then rrdcreate || { cat <<-EOHTML

Cannot create $rrdfile

EOHTML exit } fi readlast medals get_current_level cat <<-EOHTML

Import data from e.g. https://www.agent-stats.com/
Expected format: YYYY-MM-DD hh:mm:ss ${template[@]//:/ }

Latest data: $(date +"%Y-%m-%d %H:%M:%S" -d @${last[time]%:})