summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/zookeeper/init.go
blob: 1910e9a0bc81e4de790f5a5a77220b5173e46d61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: GPL-3.0-or-later

package zookeeper

import (
	"crypto/tls"
	"errors"
	"fmt"

	"github.com/netdata/netdata/go/go.d.plugin/pkg/socket"
	"github.com/netdata/netdata/go/go.d.plugin/pkg/tlscfg"
)

func (z *Zookeeper) verifyConfig() error {
	if z.Address == "" {
		return errors.New("address not set")
	}
	return nil
}

func (z *Zookeeper) initZookeeperFetcher() (fetcher, error) {
	var tlsConf *tls.Config
	var err error

	if z.UseTLS {
		tlsConf, err = tlscfg.NewTLSConfig(z.TLSConfig)
		if err != nil {
			return nil, fmt.Errorf("creating tls config : %v", err)
		}
	}

	sock := socket.New(socket.Config{
		Address:        z.Address,
		ConnectTimeout: z.Timeout.Duration(),
		ReadTimeout:    z.Timeout.Duration(),
		WriteTimeout:   z.Timeout.Duration(),
		TLSConf:        tlsConf,
	})

	return &zookeeperFetcher{Client: sock}, nil
}