#!/bin/sh
myhost=$(/bin/hostname -f)
CURL="/usr/bin/curl -is -o /dev/null -w \"%{http_code}\\\n\" -u user:password -XPOST 'http://influxdb.url/write?db=jpi' --data-binary "
AWK="/usr/bin/awk"
WC="/usr/bin/wc"
DF="/bin/df -t ext4 "
SED="/bin/sed -e 1d"
CHRONY="/usr/bin/chronyc -nc tracking"

z=$(basename $0)
IAM="${z%.*}"

tmpfile="$FLUXPLUGHOME"/tmp/"$IAM"
datafile="$FLUXPLUGHOME"/data/"$IAM"

MAXLINES=10

sendfile() {
datfile="$1"
echo $CURL" @$datfile"
}

writeline() {
line="$1"
length="$2"
        echo "$line" >> "$tmpfile"
        lines=$("$WC" -l < "$tmpfile")
        if [ "$lines" -ge $length ]; then
                mv "$tmpfile" "$datafile"
                sendfile "$datafile"
        fi


}

