Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inputs.opcua missing support for arrays #8475

Closed
mirkocomparetti-synesis opened this issue Nov 26, 2020 · 5 comments
Closed

inputs.opcua missing support for arrays #8475

mirkocomparetti-synesis opened this issue Nov 26, 2020 · 5 comments
Labels
area/opcua bug unexpected problem or unintended behavior

Comments

@mirkocomparetti-synesis
Copy link

mirkocomparetti-synesis commented Nov 26, 2020

Relevant telegraf.conf:

[[inputs.opcua]]
   name = "codesys"
   endpoint = "opc.tcp://192.168.2.247:4840"
   connect_timeout = "10s"
   request_timeout = "5s"
   interval = "1s"
   security_policy = "None"
   security_mode = "None"
   auth_method = "Anonymous"
   nodes = [
     {name="joints", namespace="4", identifier_type="s", identifier="|var|CODESYS.Joints", data_type="float", description="Joint values"},
   ]

System info:

Ubuntu 20.04, Telegraf 1.16.2 (git: release-1.16 962082f), InfluxDB v1.8.3 (git: 1.8 563e6c3d1a7a2790763c6289501095dbec19244e)

Steps to reproduce:

  1. Define an array value in OPCUA like in the picture
    image
  2. import it into telegraf with above configuration

Expected behavior:

Arrays should be imported as separated fields, just like it happens in mqtt consumer when an array is fed to the plugin in json format.

Actual behavior:

Array values are not imported, as shown in picture
image

Additional info:

As an example, this json

{
	"data_epoch": 1606398721.25,
	"J": {
		"1": 0.8607293824546176,
		"2": 4.381520765315148,
		"3": 0.8909938918704291,
		"4": 3.6710059274584418,
		"5": 4.801455750458236,
		"6": 5.99702671486787,
		"7": 6.237032901194868
	}
}

is correctly translated into multiple fields by the mqtt consumer with this configuration

[[inputs.mqtt_consumer]]
  servers = ["tcp://1.2.3.4:4321"]
  connection_timeout = "15s"
  topics = [
    "some/#",
  ]
  tag_keys = [
    "sometagA",
    "sometagB"
  ]
  tagexclude = [
    "host",
    "topic"
  ]
  persistent_session = true
  client_id = "someid"

  data_format = "json"
  json_name_key = "measurement"
  json_time_key = "data_epoch"
  json_time_format = "unix"

see picture below
image

Thanks!

@mirkocomparetti-synesis mirkocomparetti-synesis added the bug unexpected problem or unintended behavior label Nov 26, 2020
@mirkocomparetti-synesis
Copy link
Author

This can be potentially achieved using a combination of processors and aggregators, but the configuration for an array becomes very long and not practical. Adding the possibility to handle this automatically would be better.

Thanks

@sjwang90
Copy link
Contributor

Thanks for the issue and info @mirkocomparetti-synesis. I'm going to link this to #8083 and close this issue so we don't have duplicates open. Feel free to add any information to that issue.

@nicolasj92
Copy link

nicolasj92 commented Feb 10, 2022

I also would very much appreciate this feature! In the meantime I wrote a quick and dirty workaround that stores the array as a string in influx

func arrayToString(a interface{}, delim string) interface{} {
    if reflect.TypeOf(a).Kind() == reflect.Slice {
	    return strings.Trim(strings.Replace(fmt.Sprint(a), " ", delim, -1), "[]")
    } else {
	    return a
    }
}

@werbungvonmir
Copy link

Hi! I am trying to import arrays and am wondering if there is a solution available that I have not stumpled across so far. I have not been successfull in importing arrays as of now.

If you have any advice that can help me I would be delighted!

@alexmc1510
Copy link

alexmc1510 commented Mar 15, 2024

Hello @nicolasj92 , could you explain how you have implemented the function? Inside telegraf?

@mirkocomparetti-synesis , do you have an idea about the processors and aggregators that I should use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/opcua bug unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants