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 " -h Show this text."
echo " -c Cron mode. Only show output if actions were taken." 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 " -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 " -I db Log all zone temperatures to given influxdb database, then exit (see -o)."
echo " -A db Log actions to given influxdb database." echo " -A db Log actions to given influxdb database."
echo " -f file Specify an alternate config file." echo " -f file Specify an alternate config file."
@ -1487,9 +1488,9 @@ function influx_insert() { # $1 == cmd
fi fi
cmd="$1" cmd="$1"
if [[ $DOIT -eq 1 ]]; then if [[ $DOIT -eq 1 ]]; then
${influx} -database "$influxdb" -execute "$cmd" ${influx} -host "$influxhost" -database "$influxdb" -execute "$cmd"
else else
echo "${influx} -database $influxdb -execute $cmd" echo "${influx} -host "$influxhost" -database $influxdb -execute $cmd"
thisrv=0 thisrv=0
fi fi
thisrv=$? thisrv=$?
@ -1510,9 +1511,9 @@ function influx_init() { # $1 == dbname
error "influx executable not found in path." error "influx executable not found in path."
return 1 return 1
fi 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 if [[ -z $dbfound ]]; then
error "Couldn't find influx database '$influxdb'" error "Couldn't find influx database '$influxdb' on host $influxhost"
return 1 return 1
fi fi
influx_clear influx_clear
@ -1548,6 +1549,7 @@ modelock="n/a"
cronmode=0 cronmode=0
logmode=0 #0=none, 1=csv_file, 2=local influxdb logmode=0 #0=none, 1=csv_file, 2=local influxdb
influxdb="" influxdb=""
influxhost="127.0.0.1"
showwho=0 showwho=0
limit=$DEFAULTLIMIT limit=$DEFAULTLIMIT
profiler=0 profiler=0
@ -1572,7 +1574,7 @@ fi
ALLARGS="$ALLARGS $*" 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 while getopts "$optstring" i $ALLARGS; do
case "$i" in case "$i" in
h) h)
@ -1588,12 +1590,15 @@ while getopts "$optstring" i $ALLARGS; do
i) i)
AIRCON_IP=${OPTARG} AIRCON_IP=${OPTARG}
;; ;;
D)
influxhost=${OPTARG}
;;
I) I)
logmode=2 logmode=2
influx_init "$OPTARG" || exit 1 influxdb="$OPTARG"
;; ;;
A) A)
influx_init "$OPTARG" || exit 1 influxdb="$OPTARG"
;; ;;
k) k)
KILLFILE=${OPTARG} KILLFILE=${OPTARG}
@ -1646,6 +1651,10 @@ while getopts "$optstring" i $ALLARGS; do
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
if [[ -n $influxdb ]]; then
influx_init "$influxdb" || exit 1
fi
if [[ $makeconfig -eq 1 ]]; then if [[ $makeconfig -eq 1 ]]; then
gen_config gen_config
rv=$? rv=$?