| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package zookeeper |
| 4 | |
| 5 | import ( |
| 6 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket" |
| 7 | ) |
| 8 | |
| 9 | type fetcher interface { |
| 10 | fetch(command string) ([]string, error) |
| 11 | } |
| 12 | |
| 13 | type zookeeperFetcher struct { |
| 14 | socket.Client |
| 15 | } |
| 16 | |
| 17 | func (c *zookeeperFetcher) fetch(command string) (rows []string, err error) { |
| 18 | if err = c.Connect(); err != nil { |
| 19 | return nil, err |
| 20 | } |
| 21 | defer func() { _ = c.Disconnect() }() |
| 22 | |
| 23 | if err := c.Command(command, func(b []byte) (bool, error) { |
| 24 | rows = append(rows, string(b)) |
| 25 | return true, nil |
| 26 | }); err != nil { |
| 27 | return nil, err |
| 28 | } |
| 29 | |
| 30 | return rows, nil |
| 31 | } |