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

Opcua input plugin + authentication options #8009

Merged
merged 14 commits into from
Sep 2, 2020

Conversation

chrishayles
Copy link
Contributor

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

Opcua plugin. Adapted from PR: 7213
#7213

Changes include authentication and encryption options.

Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the plugin. Have some change requests for you.

plugins/inputs/opcua/opcua_client.go Outdated Show resolved Hide resolved
Comment on lines +37 to +39
ReadSuccess int
ReadError int
NumberOfTags int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These would be good as selfstat.Stat instances. See other plugins for examples. selfstats are reported automatically as part of [[inputs.internal]]

Comment on lines +27 to +28
Interval string `toml:"time_interval"`
TimeOut int `toml:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should both be a config.Duration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may have been a solid reason for interval using a string. I'll look into it and change as appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look into this? It seems error prone to allow people to set the interval as a string. The docs say 5s or 10s which is the format config.Duration uses.

plugins/inputs/opcua/opcua_client.go Show resolved Hide resolved
plugins/inputs/opcua/README.md Show resolved Hide resolved
metric/builder.go Outdated Show resolved Hide resolved
@sjwang90
Copy link
Contributor

@fdamador if you're interesting in testing this code with authentication options based off your original PR that would be really helpful.

plugins/inputs/opcua/README.md Show resolved Hide resolved
Comment on lines +62 to +68
## Guide:
## An OPC UA node ID may resemble: "n=3,s=Temperature"
## In this example, n=3 is indicating the namespace is '3'.
## s=Temperature is indicting that the identifier type is a 'string' and the indentifier value is 'Temperature'
## This temperature node may have a current value of 79.0, which would possibly make the value a 'float'.
## To gather data from this node you would need to enter the following line into 'nodes' property above:
## {name="SomeLabel", namespace="3", identifier_type="s", identifier="Temperature", data_type="float", description="Some description."},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be in the sample config? Could bring it out as just plain text in the README

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds clearer to me too. Maybe make a subsection under configuration to describe how to use the nodes setting. See https://github.com/influxdata/telegraf/blob/master/plugins/inputs/EXAMPLE_README.md

@@ -0,0 +1,76 @@
# Telegraf Input Plugin: opcua_client

The opcua_client plugin retrieves data from OPCUA slave devices
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "slave devices" to "client devices"

var err error

o.Name = "testing"
o.Endpoint = "opc.tcp://opcua.rocks:4840"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't depend on an internet test service in unit tests because the tests run in CI and need to be reliable. Either mock the endpoint you need for the test or disable the test in the short test set used in CI.

	if testing.Short() {
		t.Skip("Skipping integration test in short mode")
	}


```toml

# ## Connection Configuration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up the comments in the example config here and in sampleConfig. They need to match the commenting and indentation style because they are used when generating a config. See https://github.com/influxdata/telegraf/wiki/SampleConfig

Accurate default values should be included here and commented out with a single hash. Documentation is commented out with two hashes, not hash space hash hash

plugins/inputs/opcua/README.md Show resolved Hide resolved
Comment on lines +27 to +28
Interval string `toml:"time_interval"`
TimeOut int `toml:"timeout"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look into this? It seems error prone to allow people to set the interval as a string. The docs say 5s or 10s which is the format config.Duration uses.

timeout = 30
#
# # Time Inteval, default = 10s
time_interval = "5s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in opcua_client.go says time_interval defaults to opcua.DefaultSubscriptionInterval. The gopcua docs say that's 100ms. https://godoc.org/github.com/gopcua/opcua#pkg-constants

Which default is right? 10s, 5s, 100ms?

Comment on lines +62 to +68
## Guide:
## An OPC UA node ID may resemble: "n=3,s=Temperature"
## In this example, n=3 is indicating the namespace is '3'.
## s=Temperature is indicting that the identifier type is a 'string' and the indentifier value is 'Temperature'
## This temperature node may have a current value of 79.0, which would possibly make the value a 'float'.
## To gather data from this node you would need to enter the following line into 'nodes' property above:
## {name="SomeLabel", namespace="3", identifier_type="s", identifier="Temperature", data_type="float", description="Some description."},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds clearer to me too. Maybe make a subsection under configuration to describe how to use the nodes setting. See https://github.com/influxdata/telegraf/blob/master/plugins/inputs/EXAMPLE_README.md

Comment on lines +56 to +60
nodes = [
{name="ProductName", namespace="0", identifier_type="i", identifier="2261", data_type="string", description="open62541 OPC UA Server"},
{name="ProductUri", namespace="0", identifier_type="i", identifier="2262", data_type="string", description="http://open62541.org"},
{name="ManufacturerName", namespace="0", identifier_type="i", identifier="2263", data_type="string", description="open62541"},
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this out of the sample config. It's a good config example and it makes sense to have it in the readme but we don't want to include it in everyone's config.

plugins/inputs/opcua/README.md Show resolved Hide resolved
Comment on lines +27 to +32
# # Security policy: None, Basic128Rsa15, Basic256, Basic256Sha256. Default: auto
security_policy = "None"
#
# # Security mode: None, Sign, SignAndEncrypt. Default: auto
security_mode = "None"
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include auto in the list of valid values. Don't set them to "None" in the sample config if they default to auto.

Also, where in the code do these default to auto? I didn't find it in a quick review.

# # password = "mypassword"
#
# ## Measurements
# ## node id to subscribe to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use full sentences with punctuation and capitalization.

@reimda reimda merged commit 160e1d1 into influxdata:master Sep 2, 2020
@sjwang90 sjwang90 mentioned this pull request Sep 8, 2020
3 tasks
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants