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

fix(inputs.opcua): Assign node id correctly #11723

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions plugins/inputs/opcua/opcua.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//
//go:embed sample.conf
var sampleConfig string

Expand Down Expand Up @@ -205,7 +206,7 @@ func tagsSliceToMap(tags [][]string) (map[string]string, error) {
return m, nil
}

//InitNodes Method on OpcUA
// InitNodes Method on OpcUA
func (o *OpcUA) InitNodes() error {
for _, node := range o.RootNodes {
o.nodes = append(o.nodes, Node{
Expand Down Expand Up @@ -295,7 +296,7 @@ func newMP(n *Node) metricParts {

func (o *OpcUA) validateOPCTags() error {
nameEncountered := map[metricParts]struct{}{}
for _, node := range o.nodes {
for i, node := range o.nodes {
mp := newMP(&node)
//check empty name
if node.tag.FieldName == "" {
Expand All @@ -322,10 +323,10 @@ func (o *OpcUA) validateOPCTags() error {
return fmt.Errorf("invalid identifier type '%s' in '%s'", node.tag.IdentifierType, node.tag.FieldName)
}

node.idStr = BuildNodeID(node.tag)
o.nodes[i].idStr = BuildNodeID(node.tag)

//parse NodeIds and NodeIds errors
nid, niderr := ua.ParseNodeID(node.idStr)
nid, niderr := ua.ParseNodeID(o.nodes[i].idStr)
// build NodeIds and Errors
o.nodeIDs = append(o.nodeIDs, nid)
o.nodeIDerror = append(o.nodeIDerror, niderr)
Expand Down