add option to specify influx host

This commit is contained in:
Rob Pearce 2022-01-16 20:35:49 +11:00
parent 32923583f5
commit 2646bf5aec
1 changed files with 16 additions and 7 deletions

View File

@ -56,6 +56,7 @@ function usage() {
echo " -h Show this text."
echo " -c Cron mode. Only show output if actions were taken."
echo " -i x.x.x.x Specify IP address for aircon (default is $DEFAULT_AIRCON_IP)"
echo " -D dbhost Specify influxdb hostname for -I and -A options (default: localhost)"
echo " -I db Log all zone temperatures to given influxdb database, then exit (see -o)."
echo " -A db Log actions to given influxdb database."
echo " -f file Specify an alternate config file."
@ -1487,9 +1488,9 @@ function influx_insert() { # $1 == cmd
fi
cmd="$1"
if [[ $DOIT -eq 1 ]]; then
${influx} -database "$influxdb" -execute "$cmd"
${influx} -host "$influxhost" -database "$influxdb" -execute "$cmd"
else
echo "${influx} -database $influxdb -execute $cmd"
echo "${influx} -host "$influxhost" -database $influxdb -execute $cmd"
thisrv=0
fi
thisrv=$?
@ -1510,9 +1511,9 @@ function influx_init() { # $1 == dbname
error "influx executable not found in path."
return 1
fi
dbfound=$(${influx} -database "$influxdb" -execute "SHOW DATABASES" | grep -w ^${influxdb})
dbfound=$(${influx} -host "$influxhost" -database "$influxdb" -execute "SHOW DATABASES" | grep -w ^${influxdb})
if [[ -z $dbfound ]]; then
error "Couldn't find influx database '$influxdb'"
error "Couldn't find influx database '$influxdb' on host $influxhost"
return 1
fi
influx_clear
@ -1548,6 +1549,7 @@ modelock="n/a"
cronmode=0
logmode=0 #0=none, 1=csv_file, 2=local influxdb
influxdb=""
influxhost="127.0.0.1"
showwho=0
limit=$DEFAULTLIMIT
profiler=0
@ -1572,7 +1574,7 @@ fi
ALLARGS="$ALLARGS $*"
optstring="A:cf:hHi:I:k:l:Lo:pmsSt:T:wx:y"
optstring="A:cDf:hHi:I:k:l:Lo:pmsSt:T:wx:y"
while getopts "$optstring" i $ALLARGS; do
case "$i" in
h)
@ -1588,12 +1590,15 @@ while getopts "$optstring" i $ALLARGS; do
i)
AIRCON_IP=${OPTARG}
;;
D)
influxhost=${OPTARG}
;;
I)
logmode=2
influx_init "$OPTARG" || exit 1
influxdb="$OPTARG"
;;
A)
influx_init "$OPTARG" || exit 1
influxdb="$OPTARG"
;;
k)
KILLFILE=${OPTARG}
@ -1646,6 +1651,10 @@ while getopts "$optstring" i $ALLARGS; do
done
shift $((OPTIND - 1))
if [[ -n $influxdb ]]; then
influx_init "$influxdb" || exit 1
fi
if [[ $makeconfig -eq 1 ]]; then
gen_config
rv=$?