influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.63k stars 5.58k forks source link

inputs.Fibaro: support HC3 devices - plugin error line 74 defining "dead" as sting instead of bool property #10128

Closed torneset closed 1 year ago

torneset commented 2 years ago

Relevent telegraf.conf

// Devices contains devices informations
type Devices struct {
    ID         uint16 `json:"id"`
    Name       string `json:"name"`
    RoomID     uint16 `json:"roomID"`
    Type       string `json:"type"`
    Enabled    bool   `json:"enabled"`
    Properties struct {
        BatteryLevel *string     `json:"batteryLevel"`
----->>     Dead         string      `json:"dead"`
        Energy       *string     `json:"energy"`
        Power        *string     `json:"power"`
        Value        interface{} `json:"value"`
        Value2       *string     `json:"value2"`
    } `json:"properties"`

System info

Telegraf agent on Windows running fibaro plugin

Docker

No response

Steps to reproduce

  1. Run telegraf agent with fibaro plugin config against Fibaro Home Center 3 Errormessage; 2021-11-18T18:11:20Z E! [inputs.fibaro] Error in plugin: json: cannot unmarshal bool into Go struct field .properties.dead of type string
  2. ...

Expected behavior

Handle .properties,dead as boolean (true/false) and continue data ingestion to influx

Actual behavior

2021-11-18T18:11:20Z E! [inputs.fibaro] Error in plugin: json: cannot unmarshal bool into Go struct field .properties.dead of type string

And then it sleeps untlig new realod from HC3 api and tries to structure data for ingestion again. Same message every 20 second.

No data ingested to InfluxDB Cloud.

Additional info

No response

sspaink commented 2 years ago

Hello, thanks for using Telegraf! So I am not familiar with Fibaro, but we looked up the API documentation and found for HC2 that the dead variable in the devices JSON should be a string link to HC2 REST API Doc and then the only documentation for the REST API for HC3 we could find is this link to HC3 which also labels the dead variable as a string and not a boolean. Do you know about any other documentation that does say it should be a boolean? We need to be cautious changing this so we don't introduce a breaking change for people still using HC2 if it did change in HC3.

Another snippet of information is this comment stating the API's between HC3 and HC2 should be identical: https://forum.fibaro.com/topic/52658-any-api-for-remote-access-to-connect-the-fibaro-hc2-or-hc3-outside-local-network/?do=findComment&comment=220371

torneset commented 2 years ago

Thank you for your feedback

Maybe it actually is a difference in the two platforms and there should be one HC2 and one HC3 telegraf plugin. I have attached the swagger doc for devices-api downloaded from my HC3.

As I found in this thread there might be other undocumented changes in these values between HC2 and HC3 https://forum.fibaro.com/topic/52658-any-api-for-remote-access-to-connect-the-fibaro-hc2-or-hc3-outside-local-network/#comment-220371

HC3-swaggerAPI-devices-json.txt .

powersj commented 2 years ago

If there is now a difference between the two products I would suggest we create a new version of the plugin for those devices. While the proposed change might fix HC3 inputs unless HC2 suddenly changed as well you will inadvertently break all HC2 devices using telegraf.

torneset commented 2 years ago

@powersj I agree with that, and the existing telegraf plugin for HC2 should be marked with HC2. How do we proceed with this?

powersj commented 1 year ago

Next steps: add a config option for device version. With 2.x as the default, let someone choose 3.x and then use the updated structs. Can use the above swagger (need to check for a newer version) as well.

powersj commented 1 year ago

@torneset - if you access to an HC3 device, could you try out the artifacts found in #13754 please?

BrackenAlistair commented 1 year ago

Tried out the artefacts from 13754 (the windows version), behavior changed but it still does not work. Now the error reads: 2023-08-23T15:34:50Z E! [inputs.fibaro] Error in plugin: json: cannot unmarshal number into Go struct field .properties.energy of type string Everything else is unchanged, error repeats every 10s, no data is loaded.

powersj commented 1 year ago

@BrackenAlistair - thanks for giving this a shot. Looks like a few more values switched. I see the power, energy, and battery level fields look like numeric types now, so I've updated the PR to make them floats.

In 20-30mins, there will be new artifacts, can you give those a shot?

Thanks!

BrackenAlistair commented 1 year ago

Still not working, now the whole telegraf crashes on startup with following error: panic: interface conversion: interface {} is float64, not string

goroutine 50 [running]: github.com/influxdata/telegraf/plugins/inputs/fibaro/hc3.Parse({0x7f61740, 0xc000b37980}, {0xc000146600, 0x2e, 0x200}, {0xc002016000, 0xde, 0x200}, {0xc00208e000, 0xfb3f, ...}) /go/src/github.com/influxdata/telegraf/plugins/inputs/fibaro/hc3/parser.go:73 +0xac5 github.com/influxdata/telegraf/plugins/inputs/fibaro.(Fibaro).Gather(0xc000134cd0, {0x7f61740, 0xc000b37980}) /go/src/github.com/influxdata/telegraf/plugins/inputs/fibaro/fibaro.go:112 +0x22e github.com/influxdata/telegraf/models.(RunningInput).Gather(0xc00012ed20, {0x7f61740, 0xc000b37980}) /go/src/github.com/influxdata/telegraf/models/running_input.go:149 +0x5a github.com/influxdata/telegraf/agent.(Agent).gatherOnce.func1() /go/src/github.com/influxdata/telegraf/agent/agent.go:575 +0x2e created by github.com/influxdata/telegraf/agent.(Agent).gatherOnce /go/src/github.com/influxdata/telegraf/agent/agent.go:574 +0x12a

powersj commented 1 year ago

@BrackenAlistair,

Thanks - would you be willing to grab the /api/devices endpoint so I can see what all is there? May run into this for value2 as well, and I'd rather just check based on your data itself.

If you do not want to post that directly to the issue, you can email me at jpowers at influxdata.com

Thanks!

BrackenAlistair commented 1 year ago

Sent the requested data to provided email.

powersj commented 1 year ago

@BrackenAlistair thank you for the data, very helpful! I have pushed another fix that will be available in 20-30mins after this message.

Thanks again!

BrackenAlistair commented 1 year ago

It seems to be working now. Thank you very much for your help.

powersj commented 1 year ago

Awesome, thank you for confirming and again for sharing your data!