Merge pull request #15 from rtreffer/master
Make TLS configuration optional
This commit is contained in:
commit
9fe40f5f81
|
@ -365,7 +365,7 @@ func CollectFromSocket(socketFamily string, host string, tlsConfig *tls.Config,
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
if socketFamily == "unix" {
|
if socketFamily == "unix" || tlsConfig == nil {
|
||||||
conn, err = net.Dial(socketFamily, host)
|
conn, err = net.Dial(socketFamily, host)
|
||||||
} else {
|
} else {
|
||||||
conn, err = tls.Dial(socketFamily, host, tlsConfig)
|
conn, err = tls.Dial(socketFamily, host, tlsConfig)
|
||||||
|
@ -383,7 +383,7 @@ func CollectFromSocket(socketFamily string, host string, tlsConfig *tls.Config,
|
||||||
type UnboundExporter struct {
|
type UnboundExporter struct {
|
||||||
socketFamily string
|
socketFamily string
|
||||||
host string
|
host string
|
||||||
tlsConfig tls.Config
|
tlsConfig *tls.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUnboundExporter(host string, ca string, cert string, key string) (*UnboundExporter, error) {
|
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{
|
return &UnboundExporter{
|
||||||
socketFamily: u.Scheme,
|
socketFamily: u.Scheme,
|
||||||
host: u.Path,
|
host: u.Path,
|
||||||
tlsConfig: tls.Config{},
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if ca == "" && cert == "" {
|
||||||
|
return &UnboundExporter{
|
||||||
|
socketFamily: u.Scheme,
|
||||||
|
host: u.Host,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,8 +432,8 @@ func NewUnboundExporter(host string, ca string, cert string, key string) (*Unbou
|
||||||
|
|
||||||
return &UnboundExporter{
|
return &UnboundExporter{
|
||||||
socketFamily: u.Scheme,
|
socketFamily: u.Scheme,
|
||||||
host: u.Host,
|
host: u.Host,
|
||||||
tlsConfig: tls.Config{
|
tlsConfig: &tls.Config{
|
||||||
Certificates: []tls.Certificate{keyPair},
|
Certificates: []tls.Certificate{keyPair},
|
||||||
RootCAs: roots,
|
RootCAs: roots,
|
||||||
ServerName: "unbound",
|
ServerName: "unbound",
|
||||||
|
@ -443,7 +449,7 @@ func (e *UnboundExporter) Describe(ch chan<- *prometheus.Desc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *UnboundExporter) Collect(ch chan<- prometheus.Metric) {
|
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 {
|
if err == nil {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
unboundUpDesc,
|
unboundUpDesc,
|
||||||
|
|
Loading…
Reference in New Issue