Skip to content

[inputs.modbus] requests starting with omitted signal do not work #11105

@TimurDela

Description

@TimurDela

Relevant telegraf.conf

[[inputs.modbus.request]]
  slave_id=1
  register="holding"
  measurement="PQube3"
  fields=[
    { name = "L1-E_Volt_(RMS)",  type="FLOAT32", scale=1.0, address=7000, omit=true},
    { name = "L2-E_Volt_(RMS)",  type="FLOAT32", scale=1.0, address=7002, omit=false},
    { name = "L3-E_Volt_(RMS)",  type="FLOAT32", scale=1.0, address=7004, omit=false},
    { name = "N-E_Volt_(RMS)",   type="FLOAT32", scale=1.0, address=7006, omit=true},
    { name = "L1-N_Volt_(RMS)",  type="FLOAT32", scale=1.0, address=7008, omit=true},
  ]

Logs from Telegraf

2022-05-17T05:40:35Z D! [agent] Starting service inputs
2022-05-17T05:40:35Z D! [inputs.modbus] trying to read holding@29696[4]...
2022-05-17T05:40:35Z D! [inputs.modbus] trying to read holding@7000[125]...
2022-05-17T05:40:35Z D! [inputs.modbus] got holding@7000[125]: [67 107 107 48 67 108 210 144 67 109 17 116 63 238 22 0 67 107 170 20 67 108 120 184 67 109 8 120 67 204 29 32 67 205 105 140 67 204 181 220 64 32 15 0 64 31 216 0 0 0 0 0 66 71 249 98 63 212 157 110 63 184 193 76 63 252 52 144 0 0 0 0 196 66 43 66 68 145 213 217 0 0 0 0 67 8 237 156 66 75 220 232 66 35 67 179 198 202 74 4 197 162 110 208 197 118 109 47 71 5 127 251 70 242 74 42 70 189 43 200 201 164 146 54 74 21 140 27 63 222 230 129 66 211 245 178 54 206 207 201 64 131 217 10 61 5 2 66 62 37 240 210 62 18 83 86 0 0 0 0 65 213 58 202 191 125 178 46 127 192 0 0 127 192 0 0 127 192 0 0 127 192 0 0 0 0 5 27 72 191 128 6 63 167 70 128 67 107 131 141 0 0 0 0 67 108 86 27 67 112 76 186 67 108 254 131 66 239 244 178 63 142 90 179 67 43 174 241 63 95 227 185 66 133 134 48 63 174 51 239 67 153 173 99 7 229 0 10 0 14]
2022-05-17T05:40:35Z D! [inputs.modbus]   field L1-E_Volt_(RMS) with offset 0 with len 4: [67 107 107 48] --> 235.418701171875
2022-05-17T05:40:35Z D! [inputs.modbus]   field L2-E_Volt_(RMS) with offset 4 with len 4: [67 108 210 144] --> 236.822509765625
2022-05-17T05:40:35Z D! [inputs.modbus]   field L3-E_Volt_(RMS) with offset 8 with len 4: [67 109 17 116] --> 237.06817626953125
2022-05-17T05:40:35Z D! [inputs.modbus]   field L1-L2_Volt_(RMS) with offset 28 with len 4: [67 204 29 32] --> 408.2275390625
2022-05-17T05:40:35Z D! [inputs.modbus]   field L2-L3_Volt_(RMS) with offset 32 with len 4: [67 205 105 140] --> 410.8245849609375
2022-05-17T05:40:35Z D! [inputs.modbus]   field L3-L1_Volt_(RMS) with offset 36 with len 4: [67 204 181 220] --> 409.4207763671875
2022-05-17T05:40:35Z D! [inputs.modbus]   field L1_Flicker_Pinst_— with offset 144 with len 4: [61 5 2 66] --> 0.03247285634279251
2022-05-17T05:40:35Z D! [inputs.modbus]   field L1_Flicker_PST_— with offset 148 with len 4: [62 37 240 210] --> 0.1620514690876007
2022-05-17T05:40:35Z D! [inputs.modbus]   field L1_Flicker_PLT_— with offset 152 with len 4: [62 18 83 86] --> 0.14289602637290955
2022-05-17T05:40:35Z D! [inputs.modbus] trying to read holding@7125[63]...
2022-05-17T05:40:35Z D! [inputs.modbus] got holding@7125[63]: [7 229 0 10 0 14 7 229 0 10 0 14 7 229 0 10 0 14 7 230 0 5 0 17 0 7 0 40 0 34 64 0 0 0 67 203 239 250 67 205 52 113 67 204 130 172 63 141 233 197 63 93 183 249 63 173 215 192 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 62 185 133 110 65 173 6 221 54 206 207 201 64 131 217 10 0 0 0 0 0 0 0 0 0 0 0 0]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x25b1bbb]

goroutine 91 [running]:
github.com/influxdata/telegraf/plugins/inputs/modbus.(*Modbus).gatherRequestsHolding(0xc0003eb600, {0xc0002b8000, 0x15, 0x0})
	/go/src/github.com/influxdata/telegraf/plugins/inputs/modbus/modbus.go:422 +0x41b
github.com/influxdata/telegraf/plugins/inputs/modbus.(*Modbus).gatherFields(0xc0003eb600)
	/go/src/github.com/influxdata/telegraf/plugins/inputs/modbus/modbus.go:342 +0x131
github.com/influxdata/telegraf/plugins/inputs/modbus.(*Modbus).Gather(0xc0003eb600, {0x5ecd800, 0xc001139180})
	/go/src/github.com/influxdata/telegraf/plugins/inputs/modbus/modbus.go:206 +0x139
github.com/influxdata/telegraf/agent.(*Agent).testRunInputs.func2(0xc001a09f40)
	/go/src/github.com/influxdata/telegraf/agent/agent.go:421 +0x2f8
created by github.com/influxdata/telegraf/agent.(*Agent).testRunInputs
	/go/src/github.com/influxdata/telegraf/agent/agent.go:390 +0xcd

System info

telegraf 1.22.0 Ubuntu 20.04

Docker

No response

Steps to reproduce

  1. Create an input configuration with the new syntax [[inputs.modbus.request]]
  2. Add many fields in the list (if possible many more than the request limit
  3. Set the property omit=true for the first field of any request block
  4. Start telegraf

Expected behavior

Grouped requests should never start with omitted fields and no request with only omitted fields should be sent.
When deciding how many requests telegraf should send, it should check that these conditions are met.

Actual behavior

A request where all the fields are omitted has no memory allocated to store the values and this creates a panic.

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/modbusbugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions