vierbergenlars / bareos_exporter

MIT License
12 stars 7 forks source link

DSN is handled incorrectly #8

Open karlism opened 3 years ago

karlism commented 3 years ago

Hello,

There is an issue with DSN string handling, let me show you an example:

$ ./bareos_exporter -dsn=postgres://bareos:bareospw@localhost/bareos
panic: missing "=" after "bareos:bareospw@localhost/bareos" in connection info string"

goroutine 1 [running]:
main.main()
    /github/workspace/main.go:52 +0x46d

It is perfectly valid URL, but bareos_exporter expects it to have = symbol in it. If I add additional connection parameters, it is working fine (the system is not running PostgreSQL locally, so connection refused is fine in this case):

$ ./bareos_exporter -dsn=postgres://bareos:bareospw@localhost/bareos?readOnly=true
panic: dial tcp [::1]:5432: connect: connection refused
vierbergenlars commented 3 years ago

Sorry, it looks like I missed your issue for some time.

This looks like a small issue indeed. To determine which database driver to use, I split the string by ://, and only pass the righthand side to the database driver.

libpq on the other hand expects the full DSN to be passed, or a list of option=value, separated by spaces, which I guess where the weird error message comes from.

The second DSN is probably also not handled correctly, but you have an option named bareos:bareospw@localhost/bareos?readOnly with value true (which is then just ignored by the driver, and it defaults to connect to localhost.