fix(inputs.opcua): add more data to error log (#10465)
This commit is contained in:
parent
c3b831649f
commit
525fb9cebc
|
|
@ -529,7 +529,9 @@ func (o *OpcUA) getData() error {
|
|||
for i, d := range resp.Results {
|
||||
o.nodeData[i].Quality = d.Status
|
||||
if !o.checkStatusCode(d.Status) {
|
||||
o.Log.Errorf("status not OK for node %v: %v", o.nodes[i].tag.FieldName, d.Status)
|
||||
mp := newMP(&o.nodes[i])
|
||||
o.Log.Errorf("status not OK for node '%s'(metric name '%s', tags '%s')",
|
||||
mp.fieldName, mp.metricName, mp.tags)
|
||||
continue
|
||||
}
|
||||
o.nodeData[i].TagName = o.nodes[i].tag.FieldName
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package opcua_client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
|
||||
"github.com/gopcua/opcua/ua"
|
||||
"github.com/influxdata/telegraf/config"
|
||||
|
|
@ -21,6 +24,71 @@ type OPCTags struct {
|
|||
Want interface{}
|
||||
}
|
||||
|
||||
func TestGetDataBadNodeContainerIntegration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
}
|
||||
|
||||
// Spin-up the container
|
||||
ctx := context.Background()
|
||||
req := testcontainers.GenericContainerRequest{
|
||||
ContainerRequest: testcontainers.ContainerRequest{
|
||||
Image: "open62541/open62541:1.0",
|
||||
ExposedPorts: []string{"4840/tcp"},
|
||||
WaitingFor: wait.ForListeningPort("4840/tcp"),
|
||||
},
|
||||
Started: true,
|
||||
}
|
||||
container, err := testcontainers.GenericContainer(ctx, req)
|
||||
require.NoError(t, err, "starting container failed")
|
||||
defer func() {
|
||||
require.NoError(t, container.Terminate(ctx), "terminating container failed")
|
||||
}()
|
||||
|
||||
// Get the connection details from the container
|
||||
addr, err := container.Host(ctx)
|
||||
require.NoError(t, err, "getting container host address failed")
|
||||
p, err := container.MappedPort(ctx, "4840/tcp")
|
||||
require.NoError(t, err, "getting container host port failed")
|
||||
port := p.Port()
|
||||
|
||||
var testopctags = []OPCTags{
|
||||
{"ProductName", "1", "i", "2261", "open62541 OPC UA Server"},
|
||||
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
|
||||
{"ManufacturerName", "0", "i", "2263", "open62541"},
|
||||
}
|
||||
|
||||
var o OpcUA
|
||||
o.MetricName = "testing"
|
||||
o.Endpoint = fmt.Sprintf("opc.tcp://%s:%s", addr, port)
|
||||
fmt.Println(o.Endpoint)
|
||||
o.AuthMethod = "Anonymous"
|
||||
o.ConnectTimeout = config.Duration(10 * time.Second)
|
||||
o.RequestTimeout = config.Duration(1 * time.Second)
|
||||
o.SecurityPolicy = "None"
|
||||
o.SecurityMode = "None"
|
||||
o.codes = []ua.StatusCode{ua.StatusOK}
|
||||
logger := &testutil.CaptureLogger{}
|
||||
o.Log = logger
|
||||
|
||||
g := GroupSettings{
|
||||
MetricName: "anodic_current",
|
||||
TagsSlice: [][]string{
|
||||
{"pot", "2002"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tags := range testopctags {
|
||||
g.Nodes = append(g.Nodes, MapOPCTag(tags))
|
||||
}
|
||||
o.Groups = append(o.Groups, g)
|
||||
err = o.Init()
|
||||
require.NoError(t, err)
|
||||
err = Connect(&o)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, logger.LastError, "E! [] status not OK for node 'ProductName'(metric name 'anodic_current', tags 'pot=2002')")
|
||||
}
|
||||
|
||||
func TestClient1Integration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
|
|
|
|||
Loading…
Reference in New Issue