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