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 (
@ -50,8 +46,8 @@ var (
## List of device addresses to collect telemetry from ## List of device addresses to collect telemetry from
servers = ["localhost:1883"] servers = ["localhost:1883"]
## Authentication details. Username and password are must if device expects ## Authentication details. Username and password are must if device expects
## authentication. Client ID must be unique when connecting from multiple instances ## authentication. Client ID must be unique when connecting from multiple instances
## of telegraf to the same device ## of telegraf to the same device
username = "user" username = "user"
password = "pass" password = "pass"
@ -63,16 +59,16 @@ var (
## Sensors to subscribe for ## Sensors to subscribe for
## A identifier for each sensor can be provided in path by separating with space ## A identifier for each sensor can be provided in path by separating with space
## Else sensor path will be used as identifier ## Else sensor path will be used as identifier
## When identifier is used, we can provide a list of space separated sensors. ## When identifier is used, we can provide a list of space separated sensors.
## A single subscription will be created with all these sensors and data will ## A single subscription will be created with all these sensors and data will
## be saved to measurement with this identifier name ## be saved to measurement with this identifier name
sensors = [ sensors = [
"/interfaces/", "/interfaces/",
"collection /components/ /lldp", "collection /components/ /lldp",
] ]
## We allow specifying sensor group level reporting rate. To do this, specify the ## We allow specifying sensor group level reporting rate. To do this, specify the
## reporting rate in Duration at the beginning of sensor paths / collection ## reporting rate in Duration at the beginning of sensor paths / collection
## name. For entries without reporting rate, we use configured sample frequency ## name. For entries without reporting rate, we use configured sample frequency
sensors = [ sensors = [
"1000ms customReporting /interfaces /lldp", "1000ms customReporting /interfaces /lldp",
@ -81,12 +77,13 @@ 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"
## Use TLS but skip chain & host verification ## Use TLS but skip chain & host verification
# insecure_skip_verify = false # insecure_skip_verify = false
## Delay between retry attempts of failed RPC calls or streams. Defaults to 1000ms. ## Delay between retry attempts of failed RPC calls or streams. Defaults to 1000ms.
## Failed streams/calls will not be retried if 0 is provided ## Failed streams/calls will not be retried if 0 is provided
retry_delay = "1000ms" retry_delay = "1000ms"
@ -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())