Skip to content

Commit

Permalink
Temporarily disable connection debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan committed May 2, 2024
1 parent 5a77acd commit bfda300
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/modbus/configuration_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ func TestRequestMultipleSlavesOneFail(t *testing.T) {
actual := acc.GetTelegrafMetrics()
testutil.RequireMetricsEqual(t, expected, actual, testutil.IgnoreTime(), testutil.SortMetrics())
require.Len(t, acc.Errors, 1)
require.EqualError(t, acc.FirstError(), "slave 2: modbus: exception '11' (gateway target device failed to respond), function '131'")
require.ErrorContains(t, acc.FirstError(), "slave 2: modbus: exception '11' (gateway target device failed to respond)")
}

func TestRequestOptimizationShrink(t *testing.T) {
Expand Down
25 changes: 15 additions & 10 deletions plugins/inputs/modbus/modbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,27 @@ func (m *Modbus) initClient() error {
handler := mb.NewTCPClientHandler(host + ":" + port)
handler.Timeout = time.Duration(m.Timeout)
if m.DebugConnection {
handler.Logger = m
m.Log.Warn("Connection debugging currently not supported")
//nolint:gocritic // We want to bring this back as soon as grid-x/modbus#86 is merged
// handler.Logger = m
}
m.handler = handler
case "RTUoverTCP":
handler := mb.NewRTUOverTCPClientHandler(host + ":" + port)
handler.Timeout = time.Duration(m.Timeout)
if m.DebugConnection {
handler.Logger = m
m.Log.Warn("Connection debugging currently not supported")
//nolint:gocritic // We want to bring this back as soon as grid-x/modbus#86 is merged
// handler.Logger = m
}
m.handler = handler
case "ASCIIoverTCP":
handler := mb.NewASCIIOverTCPClientHandler(host + ":" + port)
handler.Timeout = time.Duration(m.Timeout)
if m.DebugConnection {
handler.Logger = m
m.Log.Warn("Connection debugging currently not supported")
//nolint:gocritic // We want to bring this back as soon as grid-x/modbus#86 is merged
// handler.Logger = m
}
m.handler = handler
default:
Expand All @@ -306,7 +312,9 @@ func (m *Modbus) initClient() error {
handler.Parity = m.Parity
handler.StopBits = m.StopBits
if m.DebugConnection {
handler.Logger = m
m.Log.Warn("Connection debugging currently not supported")
//nolint:gocritic // We want to bring this back as soon as grid-x/modbus#86 is merged
// handler.Logger = m
}
if m.RS485 != nil {
handler.RS485.Enabled = true
Expand All @@ -325,7 +333,9 @@ func (m *Modbus) initClient() error {
handler.Parity = m.Parity
handler.StopBits = m.StopBits
if m.DebugConnection {
handler.Logger = m
m.Log.Warn("Connection debugging currently not supported")
//nolint:gocritic // We want to bring this back as soon as grid-x/modbus#86 is merged
// handler.Logger = m
}
if m.RS485 != nil {
handler.RS485.Enabled = true
Expand Down Expand Up @@ -539,11 +549,6 @@ func (m *Modbus) collectFields(acc telegraf.Accumulator, timestamp time.Time, ta
}
}

// Implement the logger interface of the modbus client
func (m *Modbus) Printf(format string, v ...interface{}) {
m.Log.Debugf(format, v...)
}

// Add this plugin to telegraf
func init() {
inputs.Add("modbus", func() telegraf.Input { return &Modbus{} })
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/modbus/modbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func TestRetryFailExhausted(t *testing.T) {

require.NoError(t, modbus.Gather(&acc))
require.Len(t, acc.Errors, 1)
require.EqualError(t, acc.FirstError(), "slave 1: modbus: exception '6' (server device busy), function '129'")
require.ErrorContains(t, acc.FirstError(), "slave 1: modbus: exception '6' (server device busy)")
}

func TestRetryFailIllegal(t *testing.T) {
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestRetryFailIllegal(t *testing.T) {

require.NoError(t, modbus.Gather(&acc))
require.Len(t, acc.Errors, 1)
require.EqualError(t, acc.FirstError(), "slave 1: modbus: exception '1' (illegal function), function '129'")
require.ErrorContains(t, acc.FirstError(), "slave 1: modbus: exception '1' (illegal function)")
require.Equal(t, 1, counter)
}

Expand Down

0 comments on commit bfda300

Please sign in to comment.