blob: 245d1743fcfa7ffe1b57d8161709972b32ae6672 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// SPDX-License-Identifier: GPL-3.0-or-later
package dovecot
import (
"bytes"
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket"
)
type dovecotConn interface {
connect() error
disconnect()
queryExportGlobal() ([]byte, error)
}
func newDovecotConn(conf Config) dovecotConn {
return &dovecotClient{conn: socket.New(socket.Config{
Address: conf.Address,
ConnectTimeout: conf.Timeout.Duration(),
ReadTimeout: conf.Timeout.Duration(),
WriteTimeout: conf.Timeout.Duration(),
})}
}
type dovecotClient struct {
conn socket.Client
}
func (c *dovecotClient) connect() error {
return c.conn.Connect()
}
func (c *dovecotClient) disconnect() {
_ = c.conn.Disconnect()
}
func (c *dovecotClient) queryExportGlobal() ([]byte, error) {
var b bytes.Buffer
var n int
err := c.conn.Command("EXPORT\tglobal\n", func(bs []byte) bool {
b.Write(bs)
b.WriteByte('\n')
n++
return n < 2
})
if err != nil {
return nil, err
}
return b.Bytes(), nil
}
|