| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package hddtemp |
| 4 | |
| 5 | import ( |
| 6 | "time" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket" |
| 9 | ) |
| 10 | |
| 11 | type hddtempConn interface { |
| 12 | queryHddTemp() (string, error) |
| 13 | } |
| 14 | |
| 15 | func newHddTempConn(conf Config) hddtempConn { |
| 16 | return &hddtempClient{ |
| 17 | address: conf.Address, |
| 18 | timeout: conf.Timeout.Duration(), |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | type hddtempClient struct { |
| 23 | address string |
| 24 | timeout time.Duration |
| 25 | } |
| 26 | |
| 27 | func (c *hddtempClient) queryHddTemp() (string, error) { |
| 28 | cfg := socket.Config{ |
| 29 | Address: c.address, |
| 30 | Timeout: c.timeout, |
| 31 | } |
| 32 | |
| 33 | var s string |
| 34 | err := socket.ConnectAndRead(cfg, func(bs []byte) (bool, error) { |
| 35 | s = string(bs) |
| 36 | return false, nil |
| 37 | }) |
| 38 | if err != nil { |
| 39 | return "", err |
| 40 | } |
| 41 | |
| 42 | return s, nil |
| 43 | } |