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

This commit is contained in:
Sebastian Spaink 2022-08-31 16:56:30 -05:00 committed by GitHub
parent 93e6941495
commit 15c7bc51f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import (
) )
// DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data. // DO NOT REMOVE THE NEXT TWO LINES! This is required to embed the sampleConfig data.
//
//go:embed sample.conf //go:embed sample.conf
var sampleConfig string var sampleConfig string
@ -205,7 +206,7 @@ func tagsSliceToMap(tags [][]string) (map[string]string, error) {
return m, nil return m, nil
} }
//InitNodes Method on OpcUA // InitNodes Method on OpcUA
func (o *OpcUA) InitNodes() error { func (o *OpcUA) InitNodes() error {
for _, node := range o.RootNodes { for _, node := range o.RootNodes {
o.nodes = append(o.nodes, Node{ o.nodes = append(o.nodes, Node{
@ -295,7 +296,7 @@ func newMP(n *Node) metricParts {
func (o *OpcUA) validateOPCTags() error { func (o *OpcUA) validateOPCTags() error {
nameEncountered := map[metricParts]struct{}{} nameEncountered := map[metricParts]struct{}{}
for _, node := range o.nodes { for i, node := range o.nodes {
mp := newMP(&node) mp := newMP(&node)
//check empty name //check empty name
if node.tag.FieldName == "" { if node.tag.FieldName == "" {
@ -322,10 +323,10 @@ func (o *OpcUA) validateOPCTags() error {
return fmt.Errorf("invalid identifier type '%s' in '%s'", node.tag.IdentifierType, node.tag.FieldName) 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 //parse NodeIds and NodeIds errors
nid, niderr := ua.ParseNodeID(node.idStr) nid, niderr := ua.ParseNodeID(o.nodes[i].idStr)
// build NodeIds and Errors // build NodeIds and Errors
o.nodeIDs = append(o.nodeIDs, nid) o.nodeIDs = append(o.nodeIDs, nid)
o.nodeIDerror = append(o.nodeIDerror, niderr) o.nodeIDerror = append(o.nodeIDerror, niderr)