@@ -19,19 +19,19 @@ import (
19
19
20
20
const servicePort = "4840"
21
21
22
- type OPCTags struct {
23
- Name string
24
- Namespace string
25
- IdentifierType string
26
- Identifier string
27
- Want interface {}
22
+ type opcTags struct {
23
+ name string
24
+ namespace string
25
+ identifierType string
26
+ identifier string
27
+ want interface {}
28
28
}
29
29
30
- func MapOPCTag (tags OPCTags ) (out input.NodeSettings ) {
31
- out .FieldName = tags .Name
32
- out .Namespace = tags .Namespace
33
- out .IdentifierType = tags .IdentifierType
34
- out .Identifier = tags .Identifier
30
+ func mapOPCTag (tags opcTags ) (out input.NodeSettings ) {
31
+ out .FieldName = tags .name
32
+ out .Namespace = tags .namespace
33
+ out .IdentifierType = tags .identifierType
34
+ out .Identifier = tags .identifier
35
35
return out
36
36
}
37
37
@@ -52,13 +52,13 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
52
52
require .NoError (t , err , "failed to start container" )
53
53
defer container .Terminate ()
54
54
55
- testopctags := []OPCTags {
55
+ testopctags := []opcTags {
56
56
{"ProductName" , "1" , "i" , "2261" , "open62541 OPC UA Server" },
57
57
{"ProductUri" , "0" , "i" , "2262" , "http://open62541.org" },
58
58
{"ManufacturerName" , "0" , "i" , "2263" , "open62541" },
59
59
}
60
60
61
- readConfig := ReadClientConfig {
61
+ readConfig := readClientConfig {
62
62
InputClientConfig : input.InputClientConfig {
63
63
OpcUAClientConfig : opcua.OpcUAClientConfig {
64
64
Endpoint : fmt .Sprintf ("opc.tcp://%s:%s" , container .Address , container .Ports [servicePort ]),
@@ -83,14 +83,14 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
83
83
}
84
84
85
85
for _ , tags := range testopctags {
86
- g .Nodes = append (g .Nodes , MapOPCTag (tags ))
86
+ g .Nodes = append (g .Nodes , mapOPCTag (tags ))
87
87
}
88
88
readConfig .Groups = append (readConfig .Groups , g )
89
89
90
90
logger := & testutil.CaptureLogger {}
91
- readClient , err := readConfig .CreateReadClient (logger )
91
+ readClient , err := readConfig .createReadClient (logger )
92
92
require .NoError (t , err )
93
- err = readClient .Connect ()
93
+ err = readClient .connect ()
94
94
require .NoError (t , err )
95
95
}
96
96
@@ -111,7 +111,7 @@ func TestReadClientIntegration(t *testing.T) {
111
111
require .NoError (t , err , "failed to start container" )
112
112
defer container .Terminate ()
113
113
114
- testopctags := []OPCTags {
114
+ testopctags := []opcTags {
115
115
{"ProductName" , "0" , "i" , "2261" , "open62541 OPC UA Server" },
116
116
{"ProductUri" , "0" , "i" , "2262" , "http://open62541.org" },
117
117
{"ManufacturerName" , "0" , "i" , "2263" , "open62541" },
@@ -120,7 +120,7 @@ func TestReadClientIntegration(t *testing.T) {
120
120
{"DateTime" , "1" , "i" , "51037" , "0001-01-01T00:00:00Z" },
121
121
}
122
122
123
- readConfig := ReadClientConfig {
123
+ readConfig := readClientConfig {
124
124
InputClientConfig : input.InputClientConfig {
125
125
OpcUAClientConfig : opcua.OpcUAClientConfig {
126
126
Endpoint : fmt .Sprintf ("opc.tcp://%s:%s" , container .Address , container .Ports [servicePort ]),
@@ -138,17 +138,17 @@ func TestReadClientIntegration(t *testing.T) {
138
138
}
139
139
140
140
for _ , tags := range testopctags {
141
- readConfig .RootNodes = append (readConfig .RootNodes , MapOPCTag (tags ))
141
+ readConfig .RootNodes = append (readConfig .RootNodes , mapOPCTag (tags ))
142
142
}
143
143
144
- client , err := readConfig .CreateReadClient (testutil.Logger {})
144
+ client , err := readConfig .createReadClient (testutil.Logger {})
145
145
require .NoError (t , err )
146
146
147
- err = client .Connect ()
148
- require .NoError (t , err , "Connect" )
147
+ err = client .connect ()
148
+ require .NoError (t , err )
149
149
150
150
for i , v := range client .LastReceivedData {
151
- require .Equal (t , testopctags [i ].Want , v .Value )
151
+ require .Equal (t , testopctags [i ].want , v .Value )
152
152
}
153
153
}
154
154
@@ -168,7 +168,7 @@ func TestReadClientIntegrationAdditionalFields(t *testing.T) {
168
168
require .NoError (t , container .Start (), "failed to start container" )
169
169
defer container .Terminate ()
170
170
171
- testopctags := []OPCTags {
171
+ testopctags := []opcTags {
172
172
{"ProductName" , "0" , "i" , "2261" , "open62541 OPC UA Server" },
173
173
{"ProductUri" , "0" , "i" , "2262" , "http://open62541.org" },
174
174
{"ManufacturerName" , "0" , "i" , "2263" , "open62541" },
@@ -196,17 +196,17 @@ func TestReadClientIntegrationAdditionalFields(t *testing.T) {
196
196
for i , x := range testopctags {
197
197
now := time .Now ()
198
198
tags := map [string ]string {
199
- "id" : fmt .Sprintf ("ns=%s;%s=%s" , x .Namespace , x .IdentifierType , x .Identifier ),
199
+ "id" : fmt .Sprintf ("ns=%s;%s=%s" , x .namespace , x .identifierType , x .identifier ),
200
200
}
201
201
fields := map [string ]interface {}{
202
- x .Name : x .Want ,
202
+ x .name : x .want ,
203
203
"Quality" : testopcquality [i ],
204
204
"DataType" : testopctypes [i ],
205
205
}
206
206
expectedopcmetrics = append (expectedopcmetrics , metric .New ("testing" , tags , fields , now ))
207
207
}
208
208
209
- readConfig := ReadClientConfig {
209
+ readConfig := readClientConfig {
210
210
InputClientConfig : input.InputClientConfig {
211
211
OpcUAClientConfig : opcua.OpcUAClientConfig {
212
212
Endpoint : fmt .Sprintf ("opc.tcp://%s:%s" , container .Address , container .Ports [servicePort ]),
@@ -225,13 +225,13 @@ func TestReadClientIntegrationAdditionalFields(t *testing.T) {
225
225
}
226
226
227
227
for _ , tags := range testopctags {
228
- readConfig .RootNodes = append (readConfig .RootNodes , MapOPCTag (tags ))
228
+ readConfig .RootNodes = append (readConfig .RootNodes , mapOPCTag (tags ))
229
229
}
230
230
231
- client , err := readConfig .CreateReadClient (testutil.Logger {})
231
+ client , err := readConfig .createReadClient (testutil.Logger {})
232
232
require .NoError (t , err )
233
233
234
- require .NoError (t , client .Connect ())
234
+ require .NoError (t , client .connect ())
235
235
236
236
actualopcmetrics := make ([]telegraf.Metric , 0 , len (client .LastReceivedData ))
237
237
for i := range client .LastReceivedData {
@@ -258,13 +258,13 @@ func TestReadClientIntegrationWithPasswordAuth(t *testing.T) {
258
258
require .NoError (t , err , "failed to start container" )
259
259
defer container .Terminate ()
260
260
261
- testopctags := []OPCTags {
261
+ testopctags := []opcTags {
262
262
{"ProductName" , "0" , "i" , "2261" , "open62541 OPC UA Server" },
263
263
{"ProductUri" , "0" , "i" , "2262" , "http://open62541.org" },
264
264
{"ManufacturerName" , "0" , "i" , "2263" , "open62541" },
265
265
}
266
266
267
- readConfig := ReadClientConfig {
267
+ readConfig := readClientConfig {
268
268
InputClientConfig : input.InputClientConfig {
269
269
OpcUAClientConfig : opcua.OpcUAClientConfig {
270
270
Endpoint : fmt .Sprintf ("opc.tcp://%s:%s" , container .Address , container .Ports [servicePort ]),
@@ -284,17 +284,17 @@ func TestReadClientIntegrationWithPasswordAuth(t *testing.T) {
284
284
}
285
285
286
286
for _ , tags := range testopctags {
287
- readConfig .RootNodes = append (readConfig .RootNodes , MapOPCTag (tags ))
287
+ readConfig .RootNodes = append (readConfig .RootNodes , mapOPCTag (tags ))
288
288
}
289
289
290
- client , err := readConfig .CreateReadClient (testutil.Logger {})
290
+ client , err := readConfig .createReadClient (testutil.Logger {})
291
291
require .NoError (t , err )
292
292
293
- err = client .Connect ()
294
- require .NoError (t , err , "Connect" )
293
+ err = client .connect ()
294
+ require .NoError (t , err )
295
295
296
296
for i , v := range client .LastReceivedData {
297
- require .Equal (t , testopctags [i ].Want , v .Value )
297
+ require .Equal (t , testopctags [i ].want , v .Value )
298
298
}
299
299
}
300
300
@@ -369,17 +369,17 @@ use_unregistered_reads = true
369
369
o , ok := c .Inputs [0 ].Input .(* OpcUA )
370
370
require .True (t , ok )
371
371
372
- require .Equal (t , "localhost" , o .ReadClientConfig .MetricName )
373
- require .Equal (t , "opc.tcp://localhost:4840" , o .ReadClientConfig .Endpoint )
374
- require .Equal (t , config .Duration (10 * time .Second ), o .ReadClientConfig .ConnectTimeout )
375
- require .Equal (t , config .Duration (5 * time .Second ), o .ReadClientConfig .RequestTimeout )
376
- require .Equal (t , "auto" , o .ReadClientConfig .SecurityPolicy )
377
- require .Equal (t , "auto" , o .ReadClientConfig .SecurityMode )
378
- require .Equal (t , "/etc/telegraf/cert.pem" , o .ReadClientConfig .Certificate )
379
- require .Equal (t , "/etc/telegraf/key.pem" , o .ReadClientConfig .PrivateKey )
380
- require .Equal (t , "Anonymous" , o .ReadClientConfig .AuthMethod )
381
- require .True (t , o .ReadClientConfig .Username .Empty ())
382
- require .True (t , o .ReadClientConfig .Password .Empty ())
372
+ require .Equal (t , "localhost" , o .readClientConfig .MetricName )
373
+ require .Equal (t , "opc.tcp://localhost:4840" , o .readClientConfig .Endpoint )
374
+ require .Equal (t , config .Duration (10 * time .Second ), o .readClientConfig .ConnectTimeout )
375
+ require .Equal (t , config .Duration (5 * time .Second ), o .readClientConfig .RequestTimeout )
376
+ require .Equal (t , "auto" , o .readClientConfig .SecurityPolicy )
377
+ require .Equal (t , "auto" , o .readClientConfig .SecurityMode )
378
+ require .Equal (t , "/etc/telegraf/cert.pem" , o .readClientConfig .Certificate )
379
+ require .Equal (t , "/etc/telegraf/key.pem" , o .readClientConfig .PrivateKey )
380
+ require .Equal (t , "Anonymous" , o .readClientConfig .AuthMethod )
381
+ require .True (t , o .readClientConfig .Username .Empty ())
382
+ require .True (t , o .readClientConfig .Password .Empty ())
383
383
require .Equal (t , []input.NodeSettings {
384
384
{
385
385
FieldName : "name" ,
@@ -396,7 +396,7 @@ use_unregistered_reads = true
396
396
TagsSlice : [][]string {{"tag0" , "val0" }, {"tag00" , "val00" }},
397
397
DefaultTags : map [string ]string {"tag6" : "val6" },
398
398
},
399
- }, o .ReadClientConfig .RootNodes )
399
+ }, o .readClientConfig .RootNodes )
400
400
require .Equal (t , []input.NodeGroupSettings {
401
401
{
402
402
MetricName : "foo" ,
@@ -424,10 +424,10 @@ use_unregistered_reads = true
424
424
Identifier : "4001" ,
425
425
}},
426
426
},
427
- }, o .ReadClientConfig .Groups )
428
- require .Equal (t , opcua.OpcUAWorkarounds {AdditionalValidStatusCodes : []string {"0xC0" }}, o .ReadClientConfig .Workarounds )
429
- require .Equal (t , ReadClientWorkarounds {UseUnregisteredReads : true }, o .ReadClientConfig .ReadClientWorkarounds )
430
- require .Equal (t , []string {"DataType" }, o .ReadClientConfig .OptionalFields )
427
+ }, o .readClientConfig .Groups )
428
+ require .Equal (t , opcua.OpcUAWorkarounds {AdditionalValidStatusCodes : []string {"0xC0" }}, o .readClientConfig .Workarounds )
429
+ require .Equal (t , readClientWorkarounds {UseUnregisteredReads : true }, o .readClientConfig .ReadClientWorkarounds )
430
+ require .Equal (t , []string {"DataType" }, o .readClientConfig .OptionalFields )
431
431
err = o .Init ()
432
432
require .NoError (t , err )
433
433
require .Len (t , o .client .NodeMetricMapping , 5 , "incorrect number of nodes" )
0 commit comments