Add struct tags for jti_openconfig_telemetry plugin

This commit is contained in:
Daniel Nelson 2019-06-21 12:29:34 -07:00
parent 131f85db73
commit 1dc3028237
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
2 changed files with 20 additions and 27 deletions

View File

@ -42,6 +42,7 @@ This plugin reads Juniper Networks implementation of OpenConfig telemetry data f
]
## Optional TLS Config
# enable_tls = true
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"

View File

@ -1,7 +1,6 @@
package jti_openconfig_telemetry
import (
"crypto/tls"
"fmt"
"log"
"net"
@ -24,23 +23,20 @@ import (
)
type OpenConfigTelemetry struct {
Servers []string
Sensors []string
Username string
Password string
Servers []string `toml:"servers"`
Sensors []string `toml:"sensors"`
Username string `toml:"username"`
Password string `toml:"password"`
ClientID string `toml:"client_id"`
SampleFrequency internal.Duration `toml:"sample_frequency"`
StrAsTags bool `toml:"str_as_tags"`
RetryDelay internal.Duration `toml:"retry_delay"`
sensorsConfig []sensorConfig
// GRPC settings
grpcClientConns []*grpc.ClientConn
EnableTLS bool `toml:"enable_tls"`
EnableTLS bool `toml:"enable_tls"`
internaltls.ClientConfig
wg *sync.WaitGroup
sensorsConfig []sensorConfig
grpcClientConns []*grpc.ClientConn
wg *sync.WaitGroup
}
var (
@ -81,6 +77,7 @@ var (
]
## Optional TLS Config
# enable_tls = true
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
@ -353,23 +350,18 @@ func (m *OpenConfigTelemetry) collectData(ctx context.Context,
func (m *OpenConfigTelemetry) Start(acc telegraf.Accumulator) error {
var tlscfg *tls.Config
var opts []grpc.DialOption
var err error
// Build sensors config
if m.splitSensorConfig() == 0 {
return fmt.Errorf("E! No valid sensor configuration available")
}
// Parse TLS config
var opts []grpc.DialOption
if m.EnableTLS {
if tlscfg, err = m.ClientConfig.TLSConfig(); err != nil {
tlscfg, err := m.ClientConfig.TLSConfig()
if err != nil {
return err
}
}
if tlscfg != nil {
opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(tlscfg)))
} else {
opts = append(opts, grpc.WithInsecure())