Document and add support to input plugins for logging alias (#6357)

This commit is contained in:
Greg
2019-09-23 16:39:50 -06:00
committed by Daniel Nelson
parent e42d2e39c6
commit 817c9a69a9
111 changed files with 961 additions and 659 deletions

View File

@@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net"
"strings"
"sync"
@@ -54,6 +53,8 @@ type CiscoTelemetryGNMI struct {
acc telegraf.Accumulator
cancel context.CancelFunc
wg sync.WaitGroup
Log telegraf.Logger
}
// Subscription for a GNMI client
@@ -211,8 +212,8 @@ func (c *CiscoTelemetryGNMI) subscribeGNMI(ctx context.Context, address string,
return fmt.Errorf("failed to send subscription request: %v", err)
}
log.Printf("D! [inputs.cisco_telemetry_gnmi]: Connection to GNMI device %s established", address)
defer log.Printf("D! [inputs.cisco_telemetry_gnmi]: Connection to GNMI device %s closed", address)
c.Log.Debugf("Connection to GNMI device %s established", address)
defer c.Log.Debugf("Connection to GNMI device %s closed", address)
for ctx.Err() == nil {
var reply *gnmi.SubscribeResponse
if reply, err = subscribeClient.Recv(); err != nil {
@@ -267,7 +268,7 @@ func (c *CiscoTelemetryGNMI) handleSubscribeResponse(address string, reply *gnmi
if alias, ok := c.aliases[aliasPath]; ok {
name = alias
} else {
log.Printf("D! [inputs.cisco_telemetry_gnmi]: No measurement alias for GNMI path: %s", name)
c.Log.Debugf("No measurement alias for GNMI path: %s", name)
}
}

View File

@@ -104,8 +104,10 @@ func TestGNMIError(t *testing.T) {
acc := &testutil.Accumulator{}
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 0, server: server, acc: acc})
c := &CiscoTelemetryGNMI{Addresses: []string{listener.Addr().String()},
Username: "theuser", Password: "thepassword", Encoding: "proto",
c := &CiscoTelemetryGNMI{
Log: testutil.Logger{},
Addresses: []string{listener.Addr().String()},
Username: "theuser", Password: "thepassword", Encoding: "proto",
Redial: internal.Duration{Duration: 1 * time.Second}}
require.NoError(t, c.Start(acc))
@@ -174,8 +176,10 @@ func TestGNMIMultiple(t *testing.T) {
acc := &testutil.Accumulator{}
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 1, server: server, acc: acc})
c := &CiscoTelemetryGNMI{Addresses: []string{listener.Addr().String()},
Username: "theuser", Password: "thepassword", Encoding: "proto",
c := &CiscoTelemetryGNMI{
Log: testutil.Logger{},
Addresses: []string{listener.Addr().String()},
Username: "theuser", Password: "thepassword", Encoding: "proto",
Redial: internal.Duration{Duration: 1 * time.Second},
Subscriptions: []Subscription{{Name: "alias", Origin: "type", Path: "/model", SubscriptionMode: "sample"}},
}
@@ -215,8 +219,10 @@ func TestGNMIMultipleRedial(t *testing.T) {
acc := &testutil.Accumulator{}
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 2, server: server, acc: acc})
c := &CiscoTelemetryGNMI{Addresses: []string{listener.Addr().String()},
Username: "theuser", Password: "thepassword", Encoding: "proto",
c := &CiscoTelemetryGNMI{
Log: testutil.Logger{},
Addresses: []string{listener.Addr().String()},
Username: "theuser", Password: "thepassword", Encoding: "proto",
Redial: internal.Duration{Duration: 10 * time.Millisecond},
Subscriptions: []Subscription{{Name: "alias", Origin: "type", Path: "/model", SubscriptionMode: "sample"}},
}