Merge pull request #245 from Icinga/feature/add-mysql-unix-domain-socket-228

Add support mysql unix domain socket
This commit is contained in:
Noah Hilverling 2021-02-17 10:47:54 +01:00 committed by GitHub
commit 9570975494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View file

@ -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.

13
main.go
View file

@ -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)
}