Merge pull request #15 from rtreffer/master

Make TLS configuration optional
This commit is contained in:
Bart Vercoulen 2020-06-30 17:48:17 +02:00 committed by GitHub
commit 9fe40f5f81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -365,7 +365,7 @@ func CollectFromSocket(socketFamily string, host string, tlsConfig *tls.Config,
err error
)
if socketFamily == "unix" {
if socketFamily == "unix" || tlsConfig == nil {
conn, err = net.Dial(socketFamily, host)
} else {
conn, err = tls.Dial(socketFamily, host, tlsConfig)
@ -383,7 +383,7 @@ func CollectFromSocket(socketFamily string, host string, tlsConfig *tls.Config,
type UnboundExporter struct {
socketFamily string
host string
tlsConfig tls.Config
tlsConfig *tls.Config
}
func NewUnboundExporter(host string, ca string, cert string, key string) (*UnboundExporter, error) {
@ -396,7 +396,13 @@ func NewUnboundExporter(host string, ca string, cert string, key string) (*Unbou
return &UnboundExporter{
socketFamily: u.Scheme,
host: u.Path,
tlsConfig: tls.Config{},
}, nil
}
if ca == "" && cert == "" {
return &UnboundExporter{
socketFamily: u.Scheme,
host: u.Host,
}, nil
}
@ -426,8 +432,8 @@ func NewUnboundExporter(host string, ca string, cert string, key string) (*Unbou
return &UnboundExporter{
socketFamily: u.Scheme,
host: u.Host,
tlsConfig: tls.Config{
host: u.Host,
tlsConfig: &tls.Config{
Certificates: []tls.Certificate{keyPair},
RootCAs: roots,
ServerName: "unbound",
@ -443,7 +449,7 @@ func (e *UnboundExporter) Describe(ch chan<- *prometheus.Desc) {
}
func (e *UnboundExporter) Collect(ch chan<- prometheus.Metric) {
err := CollectFromSocket(e.socketFamily, e.host, &e.tlsConfig, ch)
err := CollectFromSocket(e.socketFamily, e.host, e.tlsConfig, ch)
if err == nil {
ch <- prometheus.MustNewConstMetric(
unboundUpDesc,