vierbergenlars / bareos_exporter

MIT License
12 stars 7 forks source link

posrgres dosent work #4

Closed trondk closed 3 years ago

trondk commented 3 years ago

i have been trying to get the postgres lookup to work. and get at ERRO[0002] pq: password authentication failed for user "root" args="[2020-10-05]" query="SELECT DISTINCT Name FROM job WHERE SchedTime >= $1" panic: runtime error: invalid memory address or nil pointer dereference

But i have created a small test program to test the connection and run the query

package main

import ( "database/sql" "fmt" "time" _ "github.com/lib/pq" )

const ( host = "10.1.79.41" port = 5432 user = "bareos" password = "<>" dbname = "bareos_catalog" )

func main() { psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+ "password=%s dbname=%s sslmode=disable", host, port, user, password, dbname) db, err := sql.Open("postgres", psqlInfo) if err != nil { panic(err) } date := time.Now().AddDate(0, 0, -7).Format("2006-01-02") rows, err := db.Query("SELECT DISTINCT Name FROM job WHERE SchedTime >= $1",date) //rows, err := db.Query("SELECT DISTINCT Name FROM job") checkErr(err) for rows.Next() { var name string err = rows.Scan(&name) checkErr(err) fmt.Println(name) }

defer db.Close()

err = db.Ping() if err != nil { panic(err) }

fmt.Println("Successfully connected!") }

func checkErr(err error) { if err != nil { panic(err) } }

and that works ? i cant seem to find the error, but i stops in the collector.go with var servers, getServerListErr = collector.connection.GetServerList()

cant you please help

vierbergenlars commented 3 years ago

Sorry, I totally missed your issue. For some reason I wasn't notified.

ERRO[0002] pq: password authentication failed for user "root" args="[2020-10-05]" query="SELECT DISTINCT Name FROM job WHERE SchedTime >= $1"

It looks like either your password is incorrect, or you specified a wrong connection string. (since it is using user root here, and your example program is using user bareos)

Please see the libpq documentation on how to create a connection string: https://pkg.go.dev/github.com/lib/pq#ParseURL

See also: #2