diff --git a/plugins/inputs/opcua/opcua.go b/plugins/inputs/opcua/opcua.go index 470717a15..4295c2db9 100644 --- a/plugins/inputs/opcua/opcua.go +++ b/plugins/inputs/opcua/opcua.go @@ -208,9 +208,16 @@ func tagsSliceToMap(tags [][]string) (map[string]string, error) { // InitNodes Method on OpcUA func (o *OpcUA) InitNodes() error { for _, node := range o.RootNodes { + nodeTags, err := tagsSliceToMap(node.TagsSlice) + + if err != nil { + return err + } + o.nodes = append(o.nodes, Node{ metricName: o.MetricName, tag: node, + metricTags: nodeTags, }) } diff --git a/plugins/inputs/opcua/opcua_test.go b/plugins/inputs/opcua/opcua_test.go index 63c1e0c29..5e6180f85 100644 --- a/plugins/inputs/opcua/opcua_test.go +++ b/plugins/inputs/opcua/opcua_test.go @@ -186,8 +186,8 @@ auth_method = "Anonymous" username = "" password = "" nodes = [ - {name="name", namespace="1", identifier_type="s", identifier="one"}, - {name="name2", namespace="2", identifier_type="s", identifier="two"}, + {name="name", namespace="1", identifier_type="s", identifier="one", tags=[["tag0", "val0"]]}, + {name="name2", namespace="2", identifier_type="s", identifier="two", tags=[["tag0", "val0"], ["tag00", "val00"]]}, ] [[inputs.opcua.group]] name = "foo" @@ -226,6 +226,8 @@ additional_valid_status_codes = ["0xC0"] require.NoError(t, o.InitNodes()) require.Len(t, o.nodes, 4) + require.Len(t, o.nodes[0].metricTags, 1) + require.Len(t, o.nodes[1].metricTags, 2) require.Len(t, o.nodes[2].metricTags, 3) require.Len(t, o.nodes[3].metricTags, 2)