diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/modules/hddtemp/client.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/modules/hddtemp/client.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/modules/hddtemp/client.go b/src/go/collectors/go.d.plugin/modules/hddtemp/client.go new file mode 100644 index 000000000..626381ee8 --- /dev/null +++ b/src/go/collectors/go.d.plugin/modules/hddtemp/client.go @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package hddtemp + +import ( + "github.com/netdata/netdata/go/go.d.plugin/pkg/socket" +) + +func newHddTempConn(conf Config) hddtempConn { + return &hddtempClient{conn: socket.New(socket.Config{ + Address: conf.Address, + ConnectTimeout: conf.Timeout.Duration(), + ReadTimeout: conf.Timeout.Duration(), + WriteTimeout: conf.Timeout.Duration(), + })} +} + +type hddtempClient struct { + conn socket.Client +} + +func (c *hddtempClient) connect() error { + return c.conn.Connect() +} + +func (c *hddtempClient) disconnect() { + _ = c.conn.Disconnect() +} + +func (c *hddtempClient) queryHddTemp() (string, error) { + var i int + var s string + err := c.conn.Command("", func(bytes []byte) bool { + if i++; i > 1 { + return false + } + s = string(bytes) + return true + }) + if err != nil { + return "", err + } + return s, nil +} |