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 ## Optional TLS Config
# enable_tls = true
# tls_ca = "/etc/telegraf/ca.pem" # tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem" # tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem" # tls_key = "/etc/telegraf/key.pem"

View File

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