diff --git a/doc/03-Configuration.md b/doc/03-Configuration.md index ab995ce6..8af05a94 100644 --- a/doc/03-Configuration.md +++ b/doc/03-Configuration.md @@ -23,7 +23,7 @@ Data resource where IcingaDB stores synced data and historical events. Option | Description -------------------------|----------------------------------------------- -host | **Optional.** MySQL host. Defaults to `127.0.0.1`. +host | **Optional.** MySQL host or absolute Unix socket path. Defaults to `127.0.0.1`. port | **Optional.** MySQL port. Defaults to `3306`. database | **Optional.** MySQL database. Defaults to `icingadb`. user | **Optional.** MySQL username. diff --git a/main.go b/main.go index 354efa5a..d3242085 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,7 @@ import ( log "github.com/sirupsen/logrus" "os" "os/signal" + "path/filepath" "regexp" "sync" "syscall" @@ -106,10 +107,14 @@ func main() { redisConn := connection.NewRDBWrapper(redisInfo.Host+":"+redisInfo.Port, redisInfo.Password, redisInfo.PoolSize) - mysqlConn, err := connection.NewDBWrapper( - mysqlInfo.User+":"+mysqlInfo.Password+"@tcp("+mysqlInfo.Host+":"+mysqlInfo.Port+")/"+mysqlInfo.Database, - mysqlInfo.MaxOpenConns, - ) + var dbDSN string + if filepath.IsAbs(mysqlInfo.Host) { + dbDSN = mysqlInfo.User+":"+mysqlInfo.Password+"@unix("+mysqlInfo.Host+")/"+mysqlInfo.Database + } else { + dbDSN = mysqlInfo.User+":"+mysqlInfo.Password+"@tcp("+mysqlInfo.Host+":"+mysqlInfo.Port+")/"+mysqlInfo.Database + } + + mysqlConn, err := connection.NewDBWrapper(dbDSN, mysqlInfo.MaxOpenConns) if err != nil { log.Fatal(err) }