OH3 authorization issues with influxDB2.0

Hi All
I’m having difficulty getting OH3 to authorize itself with my instance of influxDB 2.0.7

Setup as follows:

influxDB
user: openhab
organization: warrimoo
bucket: warrimoo01

token is set up as All-Access
password is setup and working

OH3
influxDB persistence add-on is installed

/etc/openhab/services/influxdb.cfg

# The database URL, e.g. http://127.0.0.1:8086 or https://127.0.0.1:8084 .
# Defaults to: http://127.0.0.1:8086
url=http://192.168.1.33:8086
version=V2
# The name of the database user, e.g. openhab.
# Defaults to: openhab
user=openhab

# The password of the database user.
#password=**********
token=Kc-1Nh0lIw3VyRTGE6Tww2Wo8AeKSBbSDnGS-_Z9aHH_woOKlrIuHGOT7xFzr_vn9z8z4qDFhb2ikdiGbQbreA==
# The name of the database, e.g. openhab.
# Defaults to: openhab
db=warrimoo
retentionPolicy=warrimoo01

Note: I have left the token visible so that its structure can be seen particularly the use of dashes and equals signs. (The token has long since been deleted from my running system :slightly_smiling_face:)

/etc/openhab/persistence/influxdb.persist

Strategies {
    everyMinute : "0 * * * * ?"
    everyHour   : "0 0 * * * ?"
    everyDay    : "0 0 0 * * ?"
}

Items {
    Miflora_OneDot_Light, Color1000_Temperature : strategy = everyMinute
}

I don’t think the issue is in the .persist file as I get the following error message from the influxdb.service on the influxdb server

msg=Unauthorized log_id=0VNsKDiW000 error="authorization not found"

I have tested the org/bucket/token combination from the influxdb-cli on the influxdb server and I can write data to the bucket using the token with no problem.

I have also tested write access to the bucket using postman from another machine and this also works fine. I will note that the token passing is a little twitchy…

Here’s the url

http://192.168.1.33:8086/api/v2/write?bucket=warrimoo01&org=warrimoo&precision=s

It also needs a separate header added for the token. The word “Token” is essential and it must be capitalized.

Key: Authorization
Value: Token Kc-1Nh0lIw3VyRTGE6Tww2Wo8AeKSBbSDnGS-_Z9aHH_woOKlrIuHGOT7xFzr_vn9z8z4qDFhb2ikdiGbQbreA==

In my attempts to connect OH3 to the influxdb server I have tried all possible variations of the influxdb.cfg file

No inverted commas - no spaces between keys and values i.e.

key=value

No inverted commas - spaces between keys and values i.e.

key = value

Single inverted commas - no spaces between keys and values i.e.

key='value'

Single inverted commas - spaces between keys and values i.e.

key = 'value'

Double inverted commas - no spaces between keys and values i.e.

key="value"

Double inverted commas - spaces between keys and values i.e.

key = "value"

I have my suspicions that the correct configuration entry syntax is

   No inverted commas - no spaces between keys and values

and that the existence of the “==” in the token is giving the config parser a problem.

I reason this way because

a) with single inverted commas around the token OH3 attempts to connect to influxdb and I get the authorization not found error

in combination with

b) without the inverted commas OH3 stops trying to access the influxdb server as if there was a config error

If anyone has any suggestions as to how this can be fixed I would be most grateful.
Perhaps there are escape sequences I can use?
Maybe the parser can be modified if that is the issue?

Many thanks in advance
Regards
Ian Carson

Have you tried configuring through the UI? Not saying this should be the only way (I can understand those who prefer config files), but it’s most of the time less error prone, and if it works there it could indicate that your suspicions are correct regarding the handling of special chars.

Edit: Looking at my /var/lib/openhab/config/org/openhab/influxdb.config (configured via UI) it looks like this:

:org.apache.felix.configadmin.revision:=L"2"
db="alfredsson"
retentionPolicy="openhab"
service.pid="org.openhab.influxdb"
token="UL<REDACTED>whg\=\="
url="http://127.0.0.1:8086"
user="openhab"
version="V2"

I.e the =-signs are escaped using backslashes. Have you tried that?

Thanks for the pointer @pacive

I wasn’t aware of the UI configuration page until you mentioned it. I found it right at the bottom of the listings on the main Settings page and made some appropriate changes.

I also deleted /etc/openhab/services/influxdb.cfg so as to avoid possible conflicts

I did notice that the retention policy on the UI page would not retain the changes I made after pressing the save button. I think there is a bug here between the UI and the config file at /var/lib/openhab/config/org/openhab/influxdb.config

The config file shows the retentionpolicy key with a lowercase “p” but I suspect the mechanism to update the UI is looking for a key with an uppercase "P’ and as it doesn’t find it it doesn’t update the UI page.

I temporarily changed the key to have a “P” and restarted openhab eh voila the correct bucket name appears in the UI. I then reverted the key to having a lowercase “p” and once again restarted.

Now my data is flowing to influx, Fanstastic! :smiley:

Note: For those of you getting influxdb up and running also be aware that there is a section under Settings, System Services called “Persistence”. This allows you to set the default persistence system for openhab.

The standard RRD4J is there from the start but it looks like when the first new persistence model is added the default setting seems to get unchecked which turns off access to the data which provides the nice sparklines in the Item displays.

You’ll need to recheck the RRD4J entry to ensure that you retain data on those items the persistence for which is not being managed by your newly added persistence model

I’d like to correct my last post.

The changing of the key name in /var/lib/openhab/config/org/openhab/influxdb.config needs to be permanent to get the connection to work.

Specifically

“retentionpolicy” should read “retentionPolicy”

otherwise the value reverts to “autogen” and the connection to influxDB2.0 fails