mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Merge pull request #458 from Icinga/451
Support *nix sockets as documented
This commit is contained in:
commit
c9d6a5ba7c
2 changed files with 18 additions and 5 deletions
|
|
@ -11,7 +11,7 @@ Configuration of the Redis that Icinga writes to.
|
|||
|
||||
Option | Description
|
||||
-------------------------|-----------------------------------------------
|
||||
address | **Required.** Redis host:port address.
|
||||
address | **Required.** Redis host:port address or absolute Unix socket path.
|
||||
password | **Optional.** The password to use.
|
||||
tls | **Optional.** Whether to use TLS.
|
||||
cert | **Optional.** Path to TLS client certificate.
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -45,8 +46,15 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) {
|
|||
|
||||
config.User = d.User
|
||||
config.Passwd = d.Password
|
||||
config.Net = "tcp"
|
||||
config.Addr = net.JoinHostPort(d.Host, fmt.Sprint(d.Port))
|
||||
|
||||
if strings.HasPrefix(d.Host, "/") {
|
||||
config.Net = "unix"
|
||||
config.Addr = d.Host
|
||||
} else {
|
||||
config.Net = "tcp"
|
||||
config.Addr = net.JoinHostPort(d.Host, fmt.Sprint(d.Port))
|
||||
}
|
||||
|
||||
config.DBName = d.Database
|
||||
config.Timeout = time.Minute
|
||||
config.Params = map[string]string{"sql_mode": "ANSI_QUOTES"}
|
||||
|
|
@ -68,15 +76,20 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) {
|
|||
uri := &url.URL{
|
||||
Scheme: "postgres",
|
||||
User: url.UserPassword(d.User, d.Password),
|
||||
Host: net.JoinHostPort(d.Host, strconv.FormatInt(int64(d.Port), 10)),
|
||||
Path: "/" + url.PathEscape(d.Database),
|
||||
}
|
||||
|
||||
query := url.Values{"connect_timeout": {"60"}, "binary_parameters": {"yes"}}
|
||||
if strings.HasPrefix(d.Host, "/") {
|
||||
query["host"] = []string{d.Host} // https://github.com/lib/pq/issues/796
|
||||
} else {
|
||||
uri.Host = net.JoinHostPort(d.Host, strconv.FormatInt(int64(d.Port), 10))
|
||||
}
|
||||
|
||||
if _, err := d.TlsOptions.MakeConfig(uri.Host); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
query := url.Values{"connect_timeout": {"60"}, "binary_parameters": {"yes"}}
|
||||
if d.TlsOptions.Enable {
|
||||
if d.TlsOptions.Insecure {
|
||||
query["sslmode"] = []string{"require"}
|
||||
|
|
|
|||
Loading…
Reference in a new issue