forked from criteo/blackbox-prober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.go
95 lines (78 loc) · 1.9 KB
/
endpoint.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"crypto/tls"
"fmt"
"regexp"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
as "github.com/aerospike/aerospike-client-go"
)
var (
setExtractionRegex, _ = regexp.Compile("ns=([a-zA-Z0-9]+):")
)
type AerospikeEndpoint struct {
Name string
clusterLevel bool
Client *as.Client
Config AerospikeClientConfig
Logger log.Logger
namespaces map[string]struct{}
}
func (e *AerospikeEndpoint) GetHash() string {
return e.Name
}
func (e *AerospikeEndpoint) GetName() string {
return e.Name
}
func (e *AerospikeEndpoint) IsCluster() bool {
return e.clusterLevel
}
func (e *AerospikeEndpoint) Connect() error {
clientPolicy := as.NewClientPolicy()
if e.Config.tlsEnabled {
// Setup TLS Config
tlsConfig := &tls.Config{
InsecureSkipVerify: e.Config.tlsSkipVerify,
PreferServerCipherSuites: true,
}
clientPolicy.TlsConfig = tlsConfig
}
if e.Config.authEnabled {
if e.Config.authExternal {
clientPolicy.AuthMode = as.AuthModeExternal
} else {
clientPolicy.AuthMode = as.AuthModeInternal
}
clientPolicy.User = e.Config.username
clientPolicy.Password = e.Config.password
}
client, err := as.NewClientWithPolicyAndHost(clientPolicy, &e.Config.host)
if err != nil {
return err
}
e.Client = client
e.Refresh()
return nil
}
func (e *AerospikeEndpoint) Refresh() error {
nodes := e.Client.GetNodes()
infop := as.NewInfoPolicy()
e.namespaces = make(map[string]struct{})
for _, n := range nodes {
data, err := n.RequestInfo(infop, fmt.Sprintln("sets"))
if err != nil {
return err
}
for _, val := range data {
matches := setExtractionRegex.FindStringSubmatch(val)
if len(matches) > 1 {
e.namespaces[matches[1]] = struct{}{}
}
}
}
level.Debug(e.Logger).Log("msg", fmt.Sprintf("Refresh finished: current namespaces: %s", e.namespaces))
return nil
}
func (e *AerospikeEndpoint) Close() error {
return nil
}