diff --git a/Makefile b/Makefile index e3bf473f9..fcaa2a76f 100644 --- a/Makefile +++ b/Makefile @@ -126,11 +126,11 @@ generate_plugins_%: build_generator go generate -run="plugindata/main.go$$" ./plugins/$*/... .PHONY: generate -generate: insert_config_to_readme_inputs generate_plugins_outputs generate_plugins_processors generate_plugins_aggregators +generate: insert_config_to_readme_inputs insert_config_to_readme_outputs generate_plugins_processors generate_plugins_aggregators .PHONY: generate-clean generate-clean: - go generate -run="plugindata/main.go --clean" ./plugins/outputs/... ./plugins/processors/... ./plugins/aggregators/... + go generate -run="plugindata/main.go --clean" ./plugins/processors/... ./plugins/aggregators/... .PHONY: build build: diff --git a/plugins/outputs/amon/README.md b/plugins/outputs/amon/README.md index b713462ec..2f5ddaf3c 100644 --- a/plugins/outputs/amon/README.md +++ b/plugins/outputs/amon/README.md @@ -11,7 +11,7 @@ Metrics are grouped by converting any `_` characters to `.` in the Point Name. ## Configuration -```toml +```toml @sample.conf # Configuration for Amon Server to send metrics to. [[outputs.amon]] ## Amon Server Key diff --git a/plugins/outputs/amon/amon.go b/plugins/outputs/amon/amon.go index c29b9e906..988a480ba 100644 --- a/plugins/outputs/amon/amon.go +++ b/plugins/outputs/amon/amon.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package amon import ( "bytes" + _ "embed" "encoding/json" "fmt" "net/http" @@ -13,6 +15,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Amon struct { ServerKey string `toml:"server_key"` AmonInstance string `toml:"amon_instance"` @@ -33,6 +39,10 @@ type Metric struct { type Point [2]float64 +func (*Amon) SampleConfig() string { + return sampleConfig +} + func (a *Amon) Connect() error { if a.ServerKey == "" || a.AmonInstance == "" { return fmt.Errorf("serverkey and amon_instance are required fields for amon output") diff --git a/plugins/outputs/amon/amon_sample_config.go b/plugins/outputs/amon/amon_sample_config.go deleted file mode 100644 index f363d2efa..000000000 --- a/plugins/outputs/amon/amon_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package amon - -func (a *Amon) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/amqp/README.md b/plugins/outputs/amqp/README.md index d7af5e01d..e8a33a91b 100644 --- a/plugins/outputs/amqp/README.md +++ b/plugins/outputs/amqp/README.md @@ -12,7 +12,7 @@ For an introduction to AMQP see: ## Configuration -```toml +```toml @sample.conf # Publishes metrics to an AMQP broker [[outputs.amqp]] ## Broker to publish to. diff --git a/plugins/outputs/amqp/amqp.go b/plugins/outputs/amqp/amqp.go index 2643d2685..925fb0cbc 100644 --- a/plugins/outputs/amqp/amqp.go +++ b/plugins/outputs/amqp/amqp.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package amqp import ( "bytes" + _ "embed" "strings" "time" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( DefaultURL = "amqp://localhost:5672/influxdb" DefaultAuthMethod = "PLAIN" @@ -71,6 +77,10 @@ type Client interface { Close() error } +func (*AMQP) SampleConfig() string { + return sampleConfig +} + func (q *AMQP) SetSerializer(serializer serializers.Serializer) { q.serializer = serializer } diff --git a/plugins/outputs/amqp/amqp_sample_config.go b/plugins/outputs/amqp/amqp_sample_config.go deleted file mode 100644 index 1d0227c94..000000000 --- a/plugins/outputs/amqp/amqp_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package amqp - -func (q *AMQP) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/application_insights/README.md b/plugins/outputs/application_insights/README.md index 182b06f17..251d073ef 100644 --- a/plugins/outputs/application_insights/README.md +++ b/plugins/outputs/application_insights/README.md @@ -5,7 +5,7 @@ Insights](https://azure.microsoft.com/en-us/services/application-insights/). ## Configuration -```toml +```toml @sample.conf # Send metrics to Azure Application Insights [[outputs.application_insights]] ## Instrumentation key of the Application Insights resource. diff --git a/plugins/outputs/application_insights/application_insights.go b/plugins/outputs/application_insights/application_insights.go index 507bf7f8e..e7f942bd7 100644 --- a/plugins/outputs/application_insights/application_insights.go +++ b/plugins/outputs/application_insights/application_insights.go @@ -1,17 +1,24 @@ +//go:generate ../../../tools/readme_config_includer/generator package application_insights import ( + _ "embed" "fmt" "math" "time" "unsafe" + "github.com/microsoft/ApplicationInsights-Go/appinsights" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/outputs" - "github.com/microsoft/ApplicationInsights-Go/appinsights" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type TelemetryTransmitter interface { Track(appinsights.Telemetry) Close() <-chan struct{} @@ -39,6 +46,10 @@ var ( is32BitChecked bool ) +func (*ApplicationInsights) SampleConfig() string { + return sampleConfig +} + func (a *ApplicationInsights) Connect() error { if a.InstrumentationKey == "" { return fmt.Errorf("instrumentation key is required") diff --git a/plugins/outputs/application_insights/application_insights_sample_config.go b/plugins/outputs/application_insights/application_insights_sample_config.go deleted file mode 100644 index d9a6b427b..000000000 --- a/plugins/outputs/application_insights/application_insights_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package application_insights - -func (a *ApplicationInsights) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/azure_data_explorer/README.md b/plugins/outputs/azure_data_explorer/README.md index b8f5c0946..35cc7489a 100644 --- a/plugins/outputs/azure_data_explorer/README.md +++ b/plugins/outputs/azure_data_explorer/README.md @@ -15,7 +15,7 @@ of logs, metrics and time series data. ## Configuration -```toml +```toml @sample.conf # Sends metrics to Azure Data Explorer [[outputs.azure_data_explorer]] ## The URI property of the Azure Data Explorer resource on Azure diff --git a/plugins/outputs/azure_data_explorer/azure_data_explorer.go b/plugins/outputs/azure_data_explorer/azure_data_explorer.go index 84a14443f..0bc599915 100644 --- a/plugins/outputs/azure_data_explorer/azure_data_explorer.go +++ b/plugins/outputs/azure_data_explorer/azure_data_explorer.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package azure_data_explorer import ( "bytes" "context" + _ "embed" "errors" "fmt" "io" @@ -13,6 +15,7 @@ import ( "github.com/Azure/azure-kusto-go/kusto/ingest" "github.com/Azure/azure-kusto-go/kusto/unsafe" "github.com/Azure/go-autorest/autorest/azure/auth" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/outputs" @@ -20,6 +23,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/json" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type AzureDataExplorer struct { Endpoint string `toml:"endpoint_url"` Database string `toml:"database"` @@ -55,6 +62,10 @@ type ingestorFactory func(localClient, string, string) (localIngestor, error) const createTableCommand = `.create-merge table ['%s'] (['fields']:dynamic, ['name']:string, ['tags']:dynamic, ['timestamp']:datetime);` const createTableMappingCommand = `.create-or-alter table ['%s'] ingestion json mapping '%s_mapping' '[{"column":"fields", "Properties":{"Path":"$[\'fields\']"}},{"column":"name", "Properties":{"Path":"$[\'name\']"}},{"column":"tags", "Properties":{"Path":"$[\'tags\']"}},{"column":"timestamp", "Properties":{"Path":"$[\'timestamp\']"}}]'` +func (*AzureDataExplorer) SampleConfig() string { + return sampleConfig +} + func (adx *AzureDataExplorer) Connect() error { authorizer, err := auth.NewAuthorizerFromEnvironmentWithResource(adx.Endpoint) if err != nil { diff --git a/plugins/outputs/azure_data_explorer/azure_data_explorer_sample_config.go b/plugins/outputs/azure_data_explorer/azure_data_explorer_sample_config.go deleted file mode 100644 index 0b92bcfef..000000000 --- a/plugins/outputs/azure_data_explorer/azure_data_explorer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package azure_data_explorer - -func (adx *AzureDataExplorer) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/azure_monitor/README.md b/plugins/outputs/azure_monitor/README.md index 0def32cff..766609607 100644 --- a/plugins/outputs/azure_monitor/README.md +++ b/plugins/outputs/azure_monitor/README.md @@ -16,7 +16,7 @@ dimension on each Azure Monitor metric. ## Configuration -```toml +```toml @sample.conf # Send aggregate metrics to Azure Monitor [[outputs.azure_monitor]] ## Timeout for HTTP writes. diff --git a/plugins/outputs/azure_monitor/azure_monitor.go b/plugins/outputs/azure_monitor/azure_monitor.go index 462f75cf0..73345ad40 100644 --- a/plugins/outputs/azure_monitor/azure_monitor.go +++ b/plugins/outputs/azure_monitor/azure_monitor.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package azure_monitor import ( "bytes" "compress/gzip" "context" + _ "embed" "encoding/binary" "encoding/json" "fmt" @@ -25,6 +27,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // AzureMonitor allows publishing of metrics to the Azure Monitor custom metrics // service type AzureMonitor struct { @@ -103,6 +109,10 @@ const ( maxRequestBodySize = 4000000 ) +func (*AzureMonitor) SampleConfig() string { + return sampleConfig +} + // Connect initializes the plugin and validates connectivity func (a *AzureMonitor) Connect() error { a.cache = make(map[time.Time]map[uint64]*aggregate, 36) diff --git a/plugins/outputs/azure_monitor/azure_monitor_sample_config.go b/plugins/outputs/azure_monitor/azure_monitor_sample_config.go deleted file mode 100644 index aa978eaec..000000000 --- a/plugins/outputs/azure_monitor/azure_monitor_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package azure_monitor - -func (a *AzureMonitor) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/bigquery/README.md b/plugins/outputs/bigquery/README.md index 9467022c5..6aa670967 100644 --- a/plugins/outputs/bigquery/README.md +++ b/plugins/outputs/bigquery/README.md @@ -10,7 +10,7 @@ Be aware that this plugin accesses APIs that are ## Configuration -```toml +```toml @sample.conf # Configuration for Google Cloud BigQuery to send entries [[outputs.bigquery]] ## Credentials File diff --git a/plugins/outputs/bigquery/bigquery.go b/plugins/outputs/bigquery/bigquery.go index 9fbc2ce5e..8f499ab0a 100644 --- a/plugins/outputs/bigquery/bigquery.go +++ b/plugins/outputs/bigquery/bigquery.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package bigquery import ( "context" + _ "embed" "fmt" "reflect" "strings" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const timeStampFieldName = "timestamp" var defaultTimeout = config.Duration(5 * time.Second) @@ -36,6 +42,10 @@ type BigQuery struct { warnedOnHyphens map[string]bool } +func (*BigQuery) SampleConfig() string { + return sampleConfig +} + func (s *BigQuery) Connect() error { if s.Project == "" { return fmt.Errorf("Project is a required field for BigQuery output") diff --git a/plugins/outputs/bigquery/bigquery_sample_config.go b/plugins/outputs/bigquery/bigquery_sample_config.go deleted file mode 100644 index acd42201e..000000000 --- a/plugins/outputs/bigquery/bigquery_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package bigquery - -func (s *BigQuery) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/cloud_pubsub/README.md b/plugins/outputs/cloud_pubsub/README.md index 5092fba7b..aa1373242 100644 --- a/plugins/outputs/cloud_pubsub/README.md +++ b/plugins/outputs/cloud_pubsub/README.md @@ -5,7 +5,7 @@ as one of the supported [output data formats][]. ## Configuration -```toml +```toml @sample.conf # Publish Telegraf metrics to a Google Cloud PubSub topic [[outputs.cloud_pubsub]] ## Required. Name of Google Cloud Platform (GCP) Project that owns diff --git a/plugins/outputs/cloud_pubsub/cloud_pubsub.go b/plugins/outputs/cloud_pubsub/cloud_pubsub.go index e147eb1b0..10f043b64 100644 --- a/plugins/outputs/cloud_pubsub/cloud_pubsub.go +++ b/plugins/outputs/cloud_pubsub/cloud_pubsub.go @@ -1,22 +1,29 @@ +//go:generate ../../../tools/readme_config_includer/generator package cloud_pubsub import ( "context" + _ "embed" "encoding/base64" "fmt" "sync" "time" "cloud.google.com/go/pubsub" + "golang.org/x/oauth2/google" + "google.golang.org/api/option" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/internal" "github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/serializers" - "golang.org/x/oauth2/google" - "google.golang.org/api/option" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type PubSub struct { CredentialsFile string `toml:"credentials_file"` Project string `toml:"project"` @@ -41,6 +48,10 @@ type PubSub struct { publishResults []publishResult } +func (*PubSub) SampleConfig() string { + return sampleConfig +} + func (ps *PubSub) SetSerializer(serializer serializers.Serializer) { ps.serializer = serializer } diff --git a/plugins/outputs/cloud_pubsub/cloud_pubsub_sample_config.go b/plugins/outputs/cloud_pubsub/cloud_pubsub_sample_config.go deleted file mode 100644 index c07b8e983..000000000 --- a/plugins/outputs/cloud_pubsub/cloud_pubsub_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cloud_pubsub - -func (ps *PubSub) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/cloudwatch/README.md b/plugins/outputs/cloudwatch/README.md index 5cdf09c14..a1a521ac1 100644 --- a/plugins/outputs/cloudwatch/README.md +++ b/plugins/outputs/cloudwatch/README.md @@ -29,7 +29,7 @@ The IAM user needs only the `cloudwatch:PutMetricData` permission. ## Configuration -```toml +```toml @sample.conf # Configuration for AWS CloudWatch output. [[outputs.cloudwatch]] ## Amazon REGION diff --git a/plugins/outputs/cloudwatch/cloudwatch.go b/plugins/outputs/cloudwatch/cloudwatch.go index 288864a59..cd2d563ca 100644 --- a/plugins/outputs/cloudwatch/cloudwatch.go +++ b/plugins/outputs/cloudwatch/cloudwatch.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package cloudwatch import ( "context" + _ "embed" "math" "sort" "strings" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type CloudWatch struct { Namespace string `toml:"namespace"` // CloudWatch Metrics Namespace HighResolutionMetrics bool `toml:"high_resolution_metrics"` @@ -148,6 +154,10 @@ func (f *valueField) buildDatum() []types.MetricDatum { } } +func (*CloudWatch) SampleConfig() string { + return sampleConfig +} + func (c *CloudWatch) Connect() error { cfg, err := c.CredentialConfig.Credentials() if err != nil { diff --git a/plugins/outputs/cloudwatch/cloudwatch_sample_config.go b/plugins/outputs/cloudwatch/cloudwatch_sample_config.go deleted file mode 100644 index 2e9c84c46..000000000 --- a/plugins/outputs/cloudwatch/cloudwatch_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cloudwatch - -func (c *CloudWatch) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/cloudwatch_logs/README.md b/plugins/outputs/cloudwatch_logs/README.md index 6113bf188..d4bf6eabf 100644 --- a/plugins/outputs/cloudwatch_logs/README.md +++ b/plugins/outputs/cloudwatch_logs/README.md @@ -33,7 +33,7 @@ The IAM user needs the following permissions (see this [reference][4] for more): ## Configuration -```toml +```toml @sample.conf # Configuration for AWS CloudWatchLogs output. [[outputs.cloudwatch_logs]] ## The region is the Amazon region that you wish to connect to. diff --git a/plugins/outputs/cloudwatch_logs/cloudwatch_logs.go b/plugins/outputs/cloudwatch_logs/cloudwatch_logs.go index 9bac6138c..f04decd21 100644 --- a/plugins/outputs/cloudwatch_logs/cloudwatch_logs.go +++ b/plugins/outputs/cloudwatch_logs/cloudwatch_logs.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package cloudwatch_logs import ( "context" + _ "embed" "fmt" "sort" "strings" @@ -9,11 +11,16 @@ import ( "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs" "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types" + "github.com/influxdata/telegraf" internalaws "github.com/influxdata/telegraf/config/aws" "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type messageBatch struct { logEvents []types.InputLogEvent messageCount int @@ -73,6 +80,10 @@ const ( // Otherwise, the operation fails. ) +func (*CloudWatchLogs) SampleConfig() string { + return sampleConfig +} + // Init initialize plugin with checking configuration parameters func (c *CloudWatchLogs) Init() error { if c.LogGroup == "" { diff --git a/plugins/outputs/cloudwatch_logs/cloudwatch_logs_sample_config.go b/plugins/outputs/cloudwatch_logs/cloudwatch_logs_sample_config.go deleted file mode 100644 index fb60595d1..000000000 --- a/plugins/outputs/cloudwatch_logs/cloudwatch_logs_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cloudwatch_logs - -func (c *CloudWatchLogs) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/cratedb/README.md b/plugins/outputs/cratedb/README.md index 5f4648176..d446c9311 100644 --- a/plugins/outputs/cratedb/README.md +++ b/plugins/outputs/cratedb/README.md @@ -23,7 +23,7 @@ config option, see below. ## Configuration -```toml +```toml @sample.conf # Configuration for CrateDB to send metrics to. [[outputs.cratedb]] # A github.com/jackc/pgx/v4 connection string. diff --git a/plugins/outputs/cratedb/cratedb.go b/plugins/outputs/cratedb/cratedb.go index 283421e97..8877961ec 100644 --- a/plugins/outputs/cratedb/cratedb.go +++ b/plugins/outputs/cratedb/cratedb.go @@ -1,9 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package cratedb import ( "context" "crypto/sha512" "database/sql" + _ "embed" "encoding/binary" "fmt" "sort" @@ -18,6 +20,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const MaxInt64 = int64(^uint64(0) >> 1) type CrateDB struct { @@ -29,6 +35,10 @@ type CrateDB struct { DB *sql.DB } +func (*CrateDB) SampleConfig() string { + return sampleConfig +} + func (c *CrateDB) Connect() error { db, err := sql.Open("pgx", c.URL) if err != nil { diff --git a/plugins/outputs/cratedb/cratedb_sample_config.go b/plugins/outputs/cratedb/cratedb_sample_config.go deleted file mode 100644 index 7dea8cf49..000000000 --- a/plugins/outputs/cratedb/cratedb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package cratedb - -func (c *CrateDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/datadog/README.md b/plugins/outputs/datadog/README.md index 6b99e97fa..f17ee6f5e 100644 --- a/plugins/outputs/datadog/README.md +++ b/plugins/outputs/datadog/README.md @@ -5,7 +5,7 @@ This plugin writes to the [Datadog Metrics API][metrics] and requires an ## Configuration -```toml +```toml @sample.conf # Configuration for DataDog API to send metrics to. [[outputs.datadog]] ## Datadog API key diff --git a/plugins/outputs/datadog/datadog.go b/plugins/outputs/datadog/datadog.go index 5419c4da4..72520288a 100644 --- a/plugins/outputs/datadog/datadog.go +++ b/plugins/outputs/datadog/datadog.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package datadog import ( "bytes" + _ "embed" "encoding/json" "fmt" "math" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Datadog struct { Apikey string `toml:"apikey"` Timeout config.Duration `toml:"timeout"` @@ -45,6 +51,10 @@ type Point [2]float64 const datadogAPI = "https://app.datadoghq.com/api/v1/series" +func (*Datadog) SampleConfig() string { + return sampleConfig +} + func (d *Datadog) Connect() error { if d.Apikey == "" { return fmt.Errorf("apikey is a required field for datadog output") diff --git a/plugins/outputs/datadog/datadog_sample_config.go b/plugins/outputs/datadog/datadog_sample_config.go deleted file mode 100644 index 89e09ae73..000000000 --- a/plugins/outputs/datadog/datadog_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package datadog - -func (d *Datadog) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/discard/README.md b/plugins/outputs/discard/README.md index c86d389fa..84e6b63a8 100644 --- a/plugins/outputs/discard/README.md +++ b/plugins/outputs/discard/README.md @@ -5,7 +5,7 @@ meant to be used for testing purposes. ## Configuration -```toml +```toml @sample.conf # Send metrics to nowhere at all [[outputs.discard]] # no configuration diff --git a/plugins/outputs/discard/discard.go b/plugins/outputs/discard/discard.go index 617c616c1..a1ea6d62b 100644 --- a/plugins/outputs/discard/discard.go +++ b/plugins/outputs/discard/discard.go @@ -1,12 +1,23 @@ +//go:generate ../../../tools/readme_config_includer/generator package discard import ( + _ "embed" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Discard struct{} +func (*Discard) SampleConfig() string { + return sampleConfig +} + func (d *Discard) Connect() error { return nil } func (d *Discard) Close() error { return nil } func (d *Discard) Write(_ []telegraf.Metric) error { diff --git a/plugins/outputs/discard/discard_sample_config.go b/plugins/outputs/discard/discard_sample_config.go deleted file mode 100644 index 00da98589..000000000 --- a/plugins/outputs/discard/discard_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package discard - -func (d *Discard) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/dynatrace/README.md b/plugins/outputs/dynatrace/README.md index e1624f256..f2d8ac5c9 100644 --- a/plugins/outputs/dynatrace/README.md +++ b/plugins/outputs/dynatrace/README.md @@ -93,7 +93,7 @@ You can learn more about how to use the Dynatrace API ## Configuration -```toml +```toml @sample.conf # Send telegraf metrics to a Dynatrace environment [[outputs.dynatrace]] ## For usage with the Dynatrace OneAgent you can omit any configuration, diff --git a/plugins/outputs/dynatrace/dynatrace.go b/plugins/outputs/dynatrace/dynatrace.go index c0feda909..49ecb5d73 100644 --- a/plugins/outputs/dynatrace/dynatrace.go +++ b/plugins/outputs/dynatrace/dynatrace.go @@ -1,23 +1,29 @@ +//go:generate ../../../tools/readme_config_includer/generator package dynatrace import ( "bytes" + _ "embed" "fmt" "io" "net/http" "strings" "time" + dtMetric "github.com/dynatrace-oss/dynatrace-metric-utils-go/metric" + "github.com/dynatrace-oss/dynatrace-metric-utils-go/metric/apiconstants" + "github.com/dynatrace-oss/dynatrace-metric-utils-go/metric/dimensions" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/outputs" - - dtMetric "github.com/dynatrace-oss/dynatrace-metric-utils-go/metric" - "github.com/dynatrace-oss/dynatrace-metric-utils-go/metric/apiconstants" - "github.com/dynatrace-oss/dynatrace-metric-utils-go/metric/dimensions" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // Dynatrace Configuration for the Dynatrace output plugin type Dynatrace struct { URL string `toml:"url"` @@ -38,6 +44,10 @@ type Dynatrace struct { loggedMetrics map[string]bool // New empty set } +func (*Dynatrace) SampleConfig() string { + return sampleConfig +} + // Connect Connects the Dynatrace output plugin to the Telegraf stream func (d *Dynatrace) Connect() error { return nil diff --git a/plugins/outputs/dynatrace/dynatrace_sample_config.go b/plugins/outputs/dynatrace/dynatrace_sample_config.go deleted file mode 100644 index ba020ea1c..000000000 --- a/plugins/outputs/dynatrace/dynatrace_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package dynatrace - -func (d *Dynatrace) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/elasticsearch/README.md b/plugins/outputs/elasticsearch/README.md index 43ab8bcd5..d31e04b00 100644 --- a/plugins/outputs/elasticsearch/README.md +++ b/plugins/outputs/elasticsearch/README.md @@ -197,7 +197,7 @@ POST https://es.us-east-1.amazonaws.com/2021-01-01/opensearch/upgradeDomain ## Configuration -```toml +```toml @sample.conf # Configuration for Elasticsearch to send metrics to. [[outputs.elasticsearch]] ## The full HTTP endpoint URL for your Elasticsearch instance diff --git a/plugins/outputs/elasticsearch/elasticsearch.go b/plugins/outputs/elasticsearch/elasticsearch.go index 80a448a96..a75fb1bd0 100644 --- a/plugins/outputs/elasticsearch/elasticsearch.go +++ b/plugins/outputs/elasticsearch/elasticsearch.go @@ -1,8 +1,11 @@ +//go:generate ../../../tools/readme_config_includer/generator package elasticsearch import ( "bytes" "context" + "crypto/sha256" + _ "embed" "fmt" "math" "net/http" @@ -12,8 +15,6 @@ import ( "text/template" "time" - "crypto/sha256" - "github.com/olivere/elastic" "github.com/influxdata/telegraf" @@ -22,6 +23,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Elasticsearch struct { AuthBearerToken string `toml:"auth_bearer_token"` DefaultPipeline string `toml:"default_pipeline"` @@ -127,6 +132,10 @@ type templatePart struct { Version int } +func (*Elasticsearch) SampleConfig() string { + return sampleConfig +} + func (a *Elasticsearch) Connect() error { if a.URLs == nil || a.IndexName == "" { return fmt.Errorf("elasticsearch urls or index_name is not defined") diff --git a/plugins/outputs/elasticsearch/elasticsearch_sample_config.go b/plugins/outputs/elasticsearch/elasticsearch_sample_config.go deleted file mode 100644 index f0ea010f8..000000000 --- a/plugins/outputs/elasticsearch/elasticsearch_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package elasticsearch - -func (a *Elasticsearch) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/event_hubs/README.md b/plugins/outputs/event_hubs/README.md index 7f9915cf9..c7c3514c8 100644 --- a/plugins/outputs/event_hubs/README.md +++ b/plugins/outputs/event_hubs/README.md @@ -15,7 +15,7 @@ JSON is probably the easiest to integrate with downstream components. ## Configuration -```toml +```toml @sample.conf # Configuration for Event Hubs output plugin [[outputs.event_hubs]] ## The full connection string to the Event Hub (required) diff --git a/plugins/outputs/event_hubs/event_hubs.go b/plugins/outputs/event_hubs/event_hubs.go index 5a0c8d3d6..a8a514241 100644 --- a/plugins/outputs/event_hubs/event_hubs.go +++ b/plugins/outputs/event_hubs/event_hubs.go @@ -1,16 +1,23 @@ +//go:generate ../../../tools/readme_config_includer/generator package event_hubs import ( "context" + _ "embed" "time" eventhub "github.com/Azure/azure-event-hubs-go/v3" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + /* ** Wrapper interface for eventhub.Hub */ @@ -61,6 +68,10 @@ const ( defaultRequestTimeout = time.Second * 30 ) +func (*EventHubs) SampleConfig() string { + return sampleConfig +} + func (e *EventHubs) Init() error { err := e.Hub.GetHub(e.ConnectionString) diff --git a/plugins/outputs/event_hubs/event_hubs_sample_config.go b/plugins/outputs/event_hubs/event_hubs_sample_config.go deleted file mode 100644 index a9ab0c2bd..000000000 --- a/plugins/outputs/event_hubs/event_hubs_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package event_hubs - -func (e *EventHubs) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/event_hubs/sample.conf b/plugins/outputs/event_hubs/sample.conf index 0d8d38475..6290e1e83 100644 --- a/plugins/outputs/event_hubs/sample.conf +++ b/plugins/outputs/event_hubs/sample.conf @@ -3,8 +3,16 @@ ## The full connection string to the Event Hub (required) ## The shared access key must have "Send" permissions on the target Event Hub. connection_string = "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName" + ## Client timeout (defaults to 30s) # timeout = "30s" + + ## Partition key + ## Metric tag or field name to use for the event partition key. The value of + ## this tag or field is set as the key for events if it exists. If both, tag + ## and field, exist the tag is preferred. + # partition_key = "" + ## Data format to output. ## Each data format has its own unique set of configuration options, read ## more about them here: diff --git a/plugins/outputs/exec/README.md b/plugins/outputs/exec/README.md index 99875b38e..fb14afd17 100644 --- a/plugins/outputs/exec/README.md +++ b/plugins/outputs/exec/README.md @@ -14,7 +14,7 @@ For better performance, consider execd, which runs continuously. ## Configuration -```toml +```toml @sample.conf # Send metrics to command as input over stdin [[outputs.exec]] ## Command to ingest metrics via stdin. diff --git a/plugins/outputs/exec/exec.go b/plugins/outputs/exec/exec.go index c8346adc1..362ce391f 100644 --- a/plugins/outputs/exec/exec.go +++ b/plugins/outputs/exec/exec.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package exec import ( "bytes" + _ "embed" "fmt" "io" "os" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const maxStderrBytes = 512 // Exec defines the exec output plugin. @@ -29,6 +35,10 @@ type Exec struct { serializer serializers.Serializer } +func (*Exec) SampleConfig() string { + return sampleConfig +} + func (e *Exec) Init() error { e.runner = &CommandRunner{log: e.Log} diff --git a/plugins/outputs/exec/exec_sample_config.go b/plugins/outputs/exec/exec_sample_config.go deleted file mode 100644 index 9d0d8bbf7..000000000 --- a/plugins/outputs/exec/exec_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package exec - -func (e *Exec) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/execd/README.md b/plugins/outputs/execd/README.md index 59be1de03..314ee5e82 100644 --- a/plugins/outputs/execd/README.md +++ b/plugins/outputs/execd/README.md @@ -6,7 +6,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Run executable as long-running output plugin [[outputs.execd]] ## One program to run as daemon. diff --git a/plugins/outputs/execd/execd.go b/plugins/outputs/execd/execd.go index e880c3f1d..fccdc7b51 100644 --- a/plugins/outputs/execd/execd.go +++ b/plugins/outputs/execd/execd.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package execd import ( "bufio" + _ "embed" "fmt" "io" "strings" @@ -14,6 +16,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Execd struct { Command []string `toml:"command"` Environment []string `toml:"environment"` @@ -24,6 +30,10 @@ type Execd struct { serializer serializers.Serializer } +func (*Execd) SampleConfig() string { + return sampleConfig +} + func (e *Execd) SetSerializer(s serializers.Serializer) { e.serializer = s } diff --git a/plugins/outputs/execd/execd_sample_config.go b/plugins/outputs/execd/execd_sample_config.go deleted file mode 100644 index bc59d8ef3..000000000 --- a/plugins/outputs/execd/execd_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package execd - -func (e *Execd) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/file/README.md b/plugins/outputs/file/README.md index 13e22ae40..c0b6c6259 100644 --- a/plugins/outputs/file/README.md +++ b/plugins/outputs/file/README.md @@ -4,7 +4,7 @@ This plugin writes telegraf metrics to files ## Configuration -```toml +```toml @sample.conf # Send telegraf metrics to file(s) [[outputs.file]] ## Files to write to, "stdout" is a specially handled file. diff --git a/plugins/outputs/file/file.go b/plugins/outputs/file/file.go index 5f377ec47..ed2366886 100644 --- a/plugins/outputs/file/file.go +++ b/plugins/outputs/file/file.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package file import ( + _ "embed" "fmt" "io" "os" @@ -13,6 +15,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type File struct { Files []string `toml:"files"` RotationInterval config.Duration `toml:"rotation_interval"` @@ -26,6 +32,10 @@ type File struct { serializer serializers.Serializer } +func (*File) SampleConfig() string { + return sampleConfig +} + func (f *File) SetSerializer(serializer serializers.Serializer) { f.serializer = serializer } diff --git a/plugins/outputs/file/file_sample_config.go b/plugins/outputs/file/file_sample_config.go deleted file mode 100644 index aae05dce6..000000000 --- a/plugins/outputs/file/file_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package file - -func (f *File) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/graphite/README.md b/plugins/outputs/graphite/README.md index 92109adde..a72bc6398 100644 --- a/plugins/outputs/graphite/README.md +++ b/plugins/outputs/graphite/README.md @@ -11,7 +11,7 @@ see the [Graphite Data Format][2]. ## Configuration -```toml +```toml @sample.conf # Configuration for Graphite server to send metrics to [[outputs.graphite]] ## TCP endpoint for your graphite instance. diff --git a/plugins/outputs/graphite/graphite.go b/plugins/outputs/graphite/graphite.go index cd7f36033..11ecb5d27 100644 --- a/plugins/outputs/graphite/graphite.go +++ b/plugins/outputs/graphite/graphite.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package graphite import ( "crypto/tls" + _ "embed" "errors" "io" "math/rand" @@ -14,6 +16,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Graphite struct { GraphiteTagSupport bool `toml:"graphite_tag_support"` GraphiteTagSanitizeMode string `toml:"graphite_tag_sanitize_mode"` @@ -30,6 +36,10 @@ type Graphite struct { tlsint.ClientConfig } +func (*Graphite) SampleConfig() string { + return sampleConfig +} + func (g *Graphite) Connect() error { // Set default values if g.Timeout <= 0 { diff --git a/plugins/outputs/graphite/graphite_sample_config.go b/plugins/outputs/graphite/graphite_sample_config.go deleted file mode 100644 index 183dec344..000000000 --- a/plugins/outputs/graphite/graphite_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package graphite - -func (g *Graphite) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/graylog/README.md b/plugins/outputs/graylog/README.md index 95efa2a16..8ee98d7e8 100644 --- a/plugins/outputs/graylog/README.md +++ b/plugins/outputs/graylog/README.md @@ -23,7 +23,7 @@ the field name. ## Configuration -```toml +```toml @sample.conf # Send telegraf metrics to graylog [[outputs.graylog]] ## Endpoints for your graylog instances. diff --git a/plugins/outputs/graylog/graylog.go b/plugins/outputs/graylog/graylog.go index 0afef5358..6e4ba07e9 100644 --- a/plugins/outputs/graylog/graylog.go +++ b/plugins/outputs/graylog/graylog.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator package graylog import ( @@ -5,6 +6,7 @@ import ( "compress/zlib" "crypto/rand" "crypto/tls" + _ "embed" "encoding/binary" ejson "encoding/json" "fmt" @@ -21,6 +23,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultEndpoint = "127.0.0.1:12201" defaultConnection = "wan" @@ -317,6 +323,10 @@ type Graylog struct { closers []io.WriteCloser } +func (*Graylog) SampleConfig() string { + return sampleConfig +} + func (g *Graylog) Connect() error { var writers []io.Writer dialer := &net.Dialer{Timeout: time.Duration(g.Timeout)} diff --git a/plugins/outputs/graylog/graylog_sample_config.go b/plugins/outputs/graylog/graylog_sample_config.go deleted file mode 100644 index a8bfa00e3..000000000 --- a/plugins/outputs/graylog/graylog_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package graylog - -func (g *Graylog) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/groundwork/README.md b/plugins/outputs/groundwork/README.md index 7de62e94a..e11febc6b 100644 --- a/plugins/outputs/groundwork/README.md +++ b/plugins/outputs/groundwork/README.md @@ -7,7 +7,7 @@ GW8+ ## Configuration -```toml +```toml @sample.conf # Send telegraf metrics to GroundWork Monitor [[outputs.groundwork]] ## URL of your groundwork instance. diff --git a/plugins/outputs/groundwork/groundwork.go b/plugins/outputs/groundwork/groundwork.go index 2c398a511..4131c848f 100644 --- a/plugins/outputs/groundwork/groundwork.go +++ b/plugins/outputs/groundwork/groundwork.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package groundwork import ( "bytes" "context" + _ "embed" "encoding/json" "errors" "fmt" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type metricMeta struct { group string resource string @@ -35,6 +41,10 @@ type Groundwork struct { client clients.GWClient } +func (*Groundwork) SampleConfig() string { + return sampleConfig +} + func (g *Groundwork) Init() error { if g.Server == "" { return errors.New("no 'url' provided") diff --git a/plugins/outputs/groundwork/groundwork_sample_config.go b/plugins/outputs/groundwork/groundwork_sample_config.go deleted file mode 100644 index 25d0fa5d9..000000000 --- a/plugins/outputs/groundwork/groundwork_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package groundwork - -func (g *Groundwork) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/health/README.md b/plugins/outputs/health/README.md index fd842a75d..8bee3a8f4 100644 --- a/plugins/outputs/health/README.md +++ b/plugins/outputs/health/README.md @@ -9,7 +9,7 @@ must fail in order for the resource to enter the failed state. ## Configuration -```toml +```toml @sample.conf # Configurable HTTP health check resource based on metrics [[outputs.health]] ## Address and port to listen on. diff --git a/plugins/outputs/health/health.go b/plugins/outputs/health/health.go index 00731127c..90aba994d 100644 --- a/plugins/outputs/health/health.go +++ b/plugins/outputs/health/health.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package health import ( "context" "crypto/tls" + _ "embed" "errors" "net" "net/http" @@ -17,6 +19,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultServiceAddress = "tcp://:8080" defaultReadTimeout = 5 * time.Second @@ -52,6 +58,10 @@ type Health struct { healthy bool } +func (*Health) SampleConfig() string { + return sampleConfig +} + func (h *Health) Init() error { u, err := url.Parse(h.ServiceAddress) if err != nil { diff --git a/plugins/outputs/health/health_sample_config.go b/plugins/outputs/health/health_sample_config.go deleted file mode 100644 index 5254a21a5..000000000 --- a/plugins/outputs/health/health_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package health - -func (h *Health) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/http/README.md b/plugins/outputs/http/README.md index c1c002d5f..153ddedab 100644 --- a/plugins/outputs/http/README.md +++ b/plugins/outputs/http/README.md @@ -6,7 +6,7 @@ format by default. ## Configuration -```toml +```toml @sample.conf # A plugin that can transmit metrics over HTTP [[outputs.http]] ## URL is the address to send metrics to diff --git a/plugins/outputs/http/http.go b/plugins/outputs/http/http.go index b046c1dad..d1c97ea91 100644 --- a/plugins/outputs/http/http.go +++ b/plugins/outputs/http/http.go @@ -1,3 +1,4 @@ +//go:generate ../../../tools/readme_config_includer/generator package http import ( @@ -5,6 +6,7 @@ import ( "bytes" "context" "crypto/sha256" + _ "embed" "fmt" "io" "net/http" @@ -13,6 +15,7 @@ import ( awsV2 "github.com/aws/aws-sdk-go-v2/aws" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" + "github.com/influxdata/telegraf" internalaws "github.com/influxdata/telegraf/config/aws" "github.com/influxdata/telegraf/internal" @@ -23,6 +26,10 @@ import ( "google.golang.org/api/idtoken" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( maxErrMsgLen = 1024 defaultURL = "http://127.0.0.1:8080/telegraf" @@ -58,6 +65,10 @@ type HTTP struct { oauth2Token *oauth2.Token } +func (*HTTP) SampleConfig() string { + return sampleConfig +} + func (h *HTTP) SetSerializer(serializer serializers.Serializer) { h.serializer = serializer } diff --git a/plugins/outputs/http/http_sample_config.go b/plugins/outputs/http/http_sample_config.go deleted file mode 100644 index a2ad3e928..000000000 --- a/plugins/outputs/http/http_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package http - -func (h *HTTP) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/http/sample.conf b/plugins/outputs/http/sample.conf index 5c1a8fd1d..4192fea54 100644 --- a/plugins/outputs/http/sample.conf +++ b/plugins/outputs/http/sample.conf @@ -19,6 +19,9 @@ # token_url = "https://indentityprovider/oauth2/v1/token" # scopes = ["urn:opc:idm:__myscopes__"] + ## Goole API Auth + # google_application_credentials = "/etc/telegraf/example_secret.json" + ## Optional TLS Config # tls_ca = "/etc/telegraf/ca.pem" # tls_cert = "/etc/telegraf/cert.pem" diff --git a/plugins/outputs/influxdb/README.md b/plugins/outputs/influxdb/README.md index ee878a7d9..689348cb5 100644 --- a/plugins/outputs/influxdb/README.md +++ b/plugins/outputs/influxdb/README.md @@ -5,7 +5,7 @@ service. ## Configuration -```toml +```toml @sample.conf # Configuration for sending metrics to InfluxDB [[outputs.influxdb]] ## The full HTTP or UDP URL for your InfluxDB instance. diff --git a/plugins/outputs/influxdb/influxdb.go b/plugins/outputs/influxdb/influxdb.go index 1d9ba9cac..431e70737 100644 --- a/plugins/outputs/influxdb/influxdb.go +++ b/plugins/outputs/influxdb/influxdb.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator //nolint package influxdb import ( "context" + _ "embed" "errors" "fmt" "math/rand" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/influx" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( defaultURL = "http://localhost:8086" @@ -63,6 +69,10 @@ type InfluxDB struct { Log telegraf.Logger } +func (*InfluxDB) SampleConfig() string { + return sampleConfig +} + func (i *InfluxDB) Connect() error { ctx := context.Background() diff --git a/plugins/outputs/influxdb/influxdb_sample_config.go b/plugins/outputs/influxdb/influxdb_sample_config.go deleted file mode 100644 index 0c92a7a50..000000000 --- a/plugins/outputs/influxdb/influxdb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package influxdb - -func (i *InfluxDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/influxdb_v2/README.md b/plugins/outputs/influxdb_v2/README.md index 3b9ddf682..473fdc0e7 100644 --- a/plugins/outputs/influxdb_v2/README.md +++ b/plugins/outputs/influxdb_v2/README.md @@ -4,7 +4,7 @@ The InfluxDB output plugin writes metrics to the [InfluxDB v2.x] HTTP service. ## Configuration -```toml +```toml @sample.conf # Configuration for sending metrics to InfluxDB 2.0 [[outputs.influxdb_v2]] ## The URLs of the InfluxDB cluster nodes. diff --git a/plugins/outputs/influxdb_v2/influxdb_v2.go b/plugins/outputs/influxdb_v2/influxdb_v2.go index 7c7103cb6..f729dfe3a 100644 --- a/plugins/outputs/influxdb_v2/influxdb_v2.go +++ b/plugins/outputs/influxdb_v2/influxdb_v2.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package influxdb_v2 import ( "context" + _ "embed" "errors" "fmt" "math/rand" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/influx" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( defaultURL = "http://localhost:8086" @@ -48,6 +54,10 @@ type InfluxDB struct { clients []Client } +func (*InfluxDB) SampleConfig() string { + return sampleConfig +} + func (i *InfluxDB) Connect() error { if len(i.URLs) == 0 { i.URLs = append(i.URLs, defaultURL) diff --git a/plugins/outputs/influxdb_v2/influxdb_v2_sample_config.go b/plugins/outputs/influxdb_v2/influxdb_v2_sample_config.go deleted file mode 100644 index 2ce7b4f2c..000000000 --- a/plugins/outputs/influxdb_v2/influxdb_v2_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package influxdb_v2 - -func (i *InfluxDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/instrumental/README.md b/plugins/outputs/instrumental/README.md index 2baff31f5..84e730108 100644 --- a/plugins/outputs/instrumental/README.md +++ b/plugins/outputs/instrumental/README.md @@ -11,7 +11,7 @@ used if the metric comes in as a counter through `[[input.statsd]]`. ## Configuration -```toml +```toml @sample.conf # Configuration for sending metrics to an Instrumental project [[outputs.instrumental]] ## Project API Token (required) diff --git a/plugins/outputs/instrumental/instrumental.go b/plugins/outputs/instrumental/instrumental.go index 1fa7f8098..7cdd5fa00 100644 --- a/plugins/outputs/instrumental/instrumental.go +++ b/plugins/outputs/instrumental/instrumental.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package instrumental import ( "bytes" + _ "embed" "fmt" "io" "net" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/graphite" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( ValueIncludesBadChar = regexp.MustCompile("[^[:digit:].]") MetricNameReplacer = regexp.MustCompile("[^-[:alnum:]_.]+") @@ -43,6 +49,10 @@ const ( HandshakeFormat = HelloMessage + AuthFormat ) +func (*Instrumental) SampleConfig() string { + return sampleConfig +} + func (i *Instrumental) Connect() error { connection, err := net.DialTimeout("tcp", i.Host+":8000", time.Duration(i.Timeout)) diff --git a/plugins/outputs/instrumental/instrumental_sample_config.go b/plugins/outputs/instrumental/instrumental_sample_config.go deleted file mode 100644 index 504f42202..000000000 --- a/plugins/outputs/instrumental/instrumental_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package instrumental - -func (i *Instrumental) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/kafka/README.md b/plugins/outputs/kafka/README.md index 33c349ca7..26c260f27 100644 --- a/plugins/outputs/kafka/README.md +++ b/plugins/outputs/kafka/README.md @@ -5,7 +5,7 @@ Broker](http://kafka.apache.org/07/quickstart.html) acting a Kafka Producer. ## Configuration -```toml +```toml @sample.conf # Configuration for the Kafka server to send metrics to [[outputs.kafka]] ## URLs of kafka brokers diff --git a/plugins/outputs/kafka/kafka.go b/plugins/outputs/kafka/kafka.go index 269591f57..8122e67cd 100644 --- a/plugins/outputs/kafka/kafka.go +++ b/plugins/outputs/kafka/kafka.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package kafka import ( + _ "embed" "fmt" "log" "strings" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ValidTopicSuffixMethods = []string{ "", "measurement", @@ -89,6 +95,10 @@ func ValidateTopicSuffixMethod(method string) error { return fmt.Errorf("unknown topic suffix method provided: %s", method) } +func (*Kafka) SampleConfig() string { + return sampleConfig +} + func (k *Kafka) GetTopicName(metric telegraf.Metric) (telegraf.Metric, string) { topic := k.Topic if k.TopicTag != "" { diff --git a/plugins/outputs/kafka/kafka_sample_config.go b/plugins/outputs/kafka/kafka_sample_config.go deleted file mode 100644 index 291b05bcd..000000000 --- a/plugins/outputs/kafka/kafka_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kafka - -func (k *Kafka) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/kinesis/README.md b/plugins/outputs/kinesis/README.md index 07b9d0243..1a18d2e88 100644 --- a/plugins/outputs/kinesis/README.md +++ b/plugins/outputs/kinesis/README.md @@ -36,7 +36,7 @@ will be used. ## Configuration -```toml +```toml @sample.conf # Configuration for the AWS Kinesis output. [[outputs.kinesis]] ## Amazon REGION of kinesis endpoint. diff --git a/plugins/outputs/kinesis/kinesis.go b/plugins/outputs/kinesis/kinesis.go index e3a900e1e..efdb6ec6d 100644 --- a/plugins/outputs/kinesis/kinesis.go +++ b/plugins/outputs/kinesis/kinesis.go @@ -1,19 +1,26 @@ +//go:generate ../../../tools/readme_config_includer/generator package kinesis import ( "context" + _ "embed" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/kinesis" "github.com/aws/aws-sdk-go-v2/service/kinesis/types" "github.com/gofrs/uuid" + "github.com/influxdata/telegraf" internalaws "github.com/influxdata/telegraf/config/aws" "github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // Limit set by AWS (https://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecords.html) const maxRecordsPerRequest uint32 = 500 @@ -43,6 +50,10 @@ type kinesisClient interface { PutRecords(context.Context, *kinesis.PutRecordsInput, ...func(*kinesis.Options)) (*kinesis.PutRecordsOutput, error) } +func (*KinesisOutput) SampleConfig() string { + return sampleConfig +} + func (k *KinesisOutput) Connect() error { if k.Partition == nil { k.Log.Error("Deprecated partitionkey configuration in use, please consider using outputs.kinesis.partition") diff --git a/plugins/outputs/kinesis/kinesis_sample_config.go b/plugins/outputs/kinesis/kinesis_sample_config.go deleted file mode 100644 index cdefa070e..000000000 --- a/plugins/outputs/kinesis/kinesis_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package kinesis - -func (k *KinesisOutput) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/librato/README.md b/plugins/outputs/librato/README.md index acc9b6284..867054e6a 100644 --- a/plugins/outputs/librato/README.md +++ b/plugins/outputs/librato/README.md @@ -17,7 +17,7 @@ Currently, the plugin does not send any associated Point Tags. ## Configuration -```toml +```toml @sample.conf # Configuration for Librato API to send metrics to. [[outputs.librato]] ## Librato API Docs diff --git a/plugins/outputs/librato/librato.go b/plugins/outputs/librato/librato.go index 721ee264d..bf9393d2c 100644 --- a/plugins/outputs/librato/librato.go +++ b/plugins/outputs/librato/librato.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package librato import ( "bytes" + _ "embed" "encoding/json" "fmt" "io" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/graphite" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // Librato structure for configuration and client type Librato struct { APIUser string `toml:"api_user"` @@ -55,6 +61,10 @@ func NewLibrato(apiURL string) *Librato { } } +func (*Librato) SampleConfig() string { + return sampleConfig +} + // Connect is the default output plugin connection function who make sure it // can connect to the endpoint func (l *Librato) Connect() error { diff --git a/plugins/outputs/librato/librato_sample_config.go b/plugins/outputs/librato/librato_sample_config.go deleted file mode 100644 index fa09650c4..000000000 --- a/plugins/outputs/librato/librato_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package librato - -func (l *Librato) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/logzio/README.md b/plugins/outputs/logzio/README.md index fd1912e26..1d450c326 100644 --- a/plugins/outputs/logzio/README.md +++ b/plugins/outputs/logzio/README.md @@ -4,7 +4,7 @@ This plugin sends metrics to Logz.io over HTTPs. ## Configuration -```toml +```toml @sample.conf # A plugin that can send metrics over HTTPs to Logz.io [[outputs.logzio]] ## Set to true if Logz.io sender checks the disk space before adding metrics to the disk queue. diff --git a/plugins/outputs/logzio/logzio.go b/plugins/outputs/logzio/logzio.go index db4e39931..c62248cf7 100644 --- a/plugins/outputs/logzio/logzio.go +++ b/plugins/outputs/logzio/logzio.go @@ -1,11 +1,12 @@ +//go:generate ../../../tools/readme_config_includer/generator package logzio import ( "bytes" "compress/gzip" + _ "embed" "encoding/json" "fmt" - "net/http" "time" @@ -15,6 +16,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultLogzioURL = "https://listener.logz.io:8071" @@ -43,6 +48,10 @@ type Metric struct { Type string `json:"type"` } +func (*Logzio) SampleConfig() string { + return sampleConfig +} + // Connect to the Output func (l *Logzio) Connect() error { l.Log.Debug("Connecting to logz.io output...") diff --git a/plugins/outputs/logzio/logzio_sample_config.go b/plugins/outputs/logzio/logzio_sample_config.go deleted file mode 100644 index 42cadabbb..000000000 --- a/plugins/outputs/logzio/logzio_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package logzio - -func (l *Logzio) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/loki/README.md b/plugins/outputs/loki/README.md index f5f043924..d6bcab6ea 100644 --- a/plugins/outputs/loki/README.md +++ b/plugins/outputs/loki/README.md @@ -8,7 +8,7 @@ Logs within each stream are sorted by timestamp before being sent to Loki. ## Configuration -```toml +```toml @sample.conf # A plugin that can transmit logs to Loki [[outputs.loki]] ## The domain of Loki diff --git a/plugins/outputs/loki/loki.go b/plugins/outputs/loki/loki.go index 52a2c3ecd..ed437d768 100644 --- a/plugins/outputs/loki/loki.go +++ b/plugins/outputs/loki/loki.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package loki import ( "bytes" "context" + _ "embed" "encoding/json" "fmt" "io" @@ -21,6 +23,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultEndpoint = "/loki/api/v1/push" defaultClientTimeout = 5 * time.Second @@ -72,6 +78,10 @@ func (l *Loki) createClient(ctx context.Context) (*http.Client, error) { return client, nil } +func (*Loki) SampleConfig() string { + return sampleConfig +} + func (l *Loki) Connect() (err error) { if l.Domain == "" { return fmt.Errorf("domain is required") diff --git a/plugins/outputs/loki/loki_sample_config.go b/plugins/outputs/loki/loki_sample_config.go deleted file mode 100644 index f0ab4151c..000000000 --- a/plugins/outputs/loki/loki_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package loki - -func (l *Loki) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/mongodb/README.md b/plugins/outputs/mongodb/README.md index 902677dbe..3f6d019e8 100644 --- a/plugins/outputs/mongodb/README.md +++ b/plugins/outputs/mongodb/README.md @@ -6,7 +6,7 @@ Requires MongoDB 5.0+ for Time Series Collections ## Configuration -```toml +```toml @sample.conf # A plugin that can transmit logs to mongodb [[outputs.mongodb]] # connection string examples for mongodb diff --git a/plugins/outputs/mongodb/mongodb.go b/plugins/outputs/mongodb/mongodb.go index 153a9526d..17428c6a7 100644 --- a/plugins/outputs/mongodb/mongodb.go +++ b/plugins/outputs/mongodb/mongodb.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package mongodb import ( "context" + _ "embed" "fmt" "net/url" "strconv" @@ -19,6 +21,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + func (s *MongoDB) getCollections(ctx context.Context) error { s.collections = map[string]bson.M{} collections, err := s.client.Database(s.MetricDatabase).ListCollections(ctx, bson.M{}) @@ -61,6 +67,10 @@ type MongoDB struct { tls.ClientConfig } +func (*MongoDB) SampleConfig() string { + return sampleConfig +} + func (s *MongoDB) Init() error { if s.MetricDatabase == "" { s.MetricDatabase = "telegraf" diff --git a/plugins/outputs/mongodb/mongodb_sample_config.go b/plugins/outputs/mongodb/mongodb_sample_config.go deleted file mode 100644 index feea34f2a..000000000 --- a/plugins/outputs/mongodb/mongodb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mongodb - -func (s *MongoDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/mqtt/README.md b/plugins/outputs/mqtt/README.md index 04d6f2ad5..32142bd3e 100644 --- a/plugins/outputs/mqtt/README.md +++ b/plugins/outputs/mqtt/README.md @@ -14,7 +14,7 @@ As a reference `eclipse/paho.mqtt.golang` sets the `keep_alive` to 30. ## Configuration -```toml +```toml @sample.conf # Configuration for MQTT server to send metrics to [[outputs.mqtt]] ## MQTT Brokers diff --git a/plugins/outputs/mqtt/mqtt.go b/plugins/outputs/mqtt/mqtt.go index 35ede5e30..5dec184a3 100644 --- a/plugins/outputs/mqtt/mqtt.go +++ b/plugins/outputs/mqtt/mqtt.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package mqtt import ( + _ "embed" "fmt" "strings" "sync" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultKeepAlive = 0 ) @@ -43,6 +49,10 @@ type MQTT struct { sync.Mutex } +func (*MQTT) SampleConfig() string { + return sampleConfig +} + func (m *MQTT) Connect() error { var err error m.Lock() diff --git a/plugins/outputs/mqtt/mqtt_sample_config.go b/plugins/outputs/mqtt/mqtt_sample_config.go deleted file mode 100644 index 04fbfa6ae..000000000 --- a/plugins/outputs/mqtt/mqtt_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package mqtt - -func (m *MQTT) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/nats/README.md b/plugins/outputs/nats/README.md index af918442d..7a8787c26 100644 --- a/plugins/outputs/nats/README.md +++ b/plugins/outputs/nats/README.md @@ -4,7 +4,7 @@ This plugin writes to a (list of) specified NATS instance(s). ## Configuration -```toml +```toml @sample.conf # Send telegraf measurements to NATS [[outputs.nats]] ## URLs of NATS servers diff --git a/plugins/outputs/nats/nats.go b/plugins/outputs/nats/nats.go index 7b71ab2ae..95aae69ad 100644 --- a/plugins/outputs/nats/nats.go +++ b/plugins/outputs/nats/nats.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package nats import ( + _ "embed" "fmt" "strings" @@ -12,6 +14,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type NATS struct { Servers []string `toml:"servers"` Secure bool `toml:"secure"` @@ -29,6 +35,10 @@ type NATS struct { serializer serializers.Serializer } +func (*NATS) SampleConfig() string { + return sampleConfig +} + func (n *NATS) SetSerializer(serializer serializers.Serializer) { n.serializer = serializer } diff --git a/plugins/outputs/nats/nats_sample_config.go b/plugins/outputs/nats/nats_sample_config.go deleted file mode 100644 index 4b404d97b..000000000 --- a/plugins/outputs/nats/nats_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nats - -func (n *NATS) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/newrelic/README.md b/plugins/outputs/newrelic/README.md index 0e6d93822..fa3b1db00 100644 --- a/plugins/outputs/newrelic/README.md +++ b/plugins/outputs/newrelic/README.md @@ -8,7 +8,7 @@ Telegraf minimum version: Telegraf 1.15.0 ## Configuration -```toml +```toml @sample.conf # Send metrics to New Relic metrics endpoint [[outputs.newrelic]] ## The 'insights_key' parameter requires a NR license key. diff --git a/plugins/outputs/newrelic/newrelic.go b/plugins/outputs/newrelic/newrelic.go index 0b0125327..570cb2b83 100644 --- a/plugins/outputs/newrelic/newrelic.go +++ b/plugins/outputs/newrelic/newrelic.go @@ -1,8 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package newrelic -// newrelic.go import ( "context" + _ "embed" "fmt" "net/http" "net/url" @@ -16,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // NewRelic nr structure type NewRelic struct { InsightsKey string `toml:"insights_key"` @@ -31,6 +36,10 @@ type NewRelic struct { client http.Client } +func (*NewRelic) SampleConfig() string { + return sampleConfig +} + // Connect to the Output func (nr *NewRelic) Connect() error { if nr.InsightsKey == "" { diff --git a/plugins/outputs/newrelic/newrelic_sample_config.go b/plugins/outputs/newrelic/newrelic_sample_config.go deleted file mode 100644 index cbfb83833..000000000 --- a/plugins/outputs/newrelic/newrelic_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package newrelic - -func (nr *NewRelic) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/nsq/README.md b/plugins/outputs/nsq/README.md index 4f268944e..e2cc75c84 100644 --- a/plugins/outputs/nsq/README.md +++ b/plugins/outputs/nsq/README.md @@ -5,7 +5,7 @@ producer. It requires a `server` name and a `topic` name. ## Configuration -```toml +```toml @sample.conf # Send telegraf measurements to NSQD [[outputs.nsq]] ## Location of nsqd instance listening on TCP diff --git a/plugins/outputs/nsq/nsq.go b/plugins/outputs/nsq/nsq.go index 3b188f0e3..a86dec28f 100644 --- a/plugins/outputs/nsq/nsq.go +++ b/plugins/outputs/nsq/nsq.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package nsq import ( + _ "embed" "fmt" "github.com/nsqio/go-nsq" @@ -10,6 +12,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type NSQ struct { Server string Topic string @@ -19,6 +25,10 @@ type NSQ struct { serializer serializers.Serializer } +func (*NSQ) SampleConfig() string { + return sampleConfig +} + func (n *NSQ) SetSerializer(serializer serializers.Serializer) { n.serializer = serializer } diff --git a/plugins/outputs/nsq/nsq_sample_config.go b/plugins/outputs/nsq/nsq_sample_config.go deleted file mode 100644 index 75efaba5a..000000000 --- a/plugins/outputs/nsq/nsq_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package nsq - -func (n *NSQ) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/opentelemetry/README.md b/plugins/outputs/opentelemetry/README.md index 7f81d8452..3993ca245 100644 --- a/plugins/outputs/opentelemetry/README.md +++ b/plugins/outputs/opentelemetry/README.md @@ -5,7 +5,7 @@ and agents via gRPC. ## Configuration -```toml +```toml @sample.conf # Send OpenTelemetry metrics over gRPC [[outputs.opentelemetry]] ## Override the default (localhost:4317) OpenTelemetry gRPC service diff --git a/plugins/outputs/opentelemetry/opentelemetry.go b/plugins/outputs/opentelemetry/opentelemetry.go index 72eb0b4b3..37dd9a9f1 100644 --- a/plugins/outputs/opentelemetry/opentelemetry.go +++ b/plugins/outputs/opentelemetry/opentelemetry.go @@ -1,25 +1,30 @@ +//go:generate ../../../tools/readme_config_includer/generator package opentelemetry import ( "context" - "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" - "google.golang.org/grpc/credentials/insecure" + _ "embed" "time" "github.com/influxdata/influxdb-observability/common" "github.com/influxdata/influxdb-observability/influx2otel" + "go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" + _ "google.golang.org/grpc/encoding/gzip" + "google.golang.org/grpc/metadata" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/outputs" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - - // This causes the gRPC library to register gzip compression. - _ "google.golang.org/grpc/encoding/gzip" - "google.golang.org/grpc/metadata" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type OpenTelemetry struct { ServiceAddress string `toml:"service_address"` @@ -37,6 +42,10 @@ type OpenTelemetry struct { callOptions []grpc.CallOption } +func (*OpenTelemetry) SampleConfig() string { + return sampleConfig +} + func (o *OpenTelemetry) Connect() error { logger := &otelLogger{o.Log} diff --git a/plugins/outputs/opentelemetry/opentelemetry_sample_config.go b/plugins/outputs/opentelemetry/opentelemetry_sample_config.go deleted file mode 100644 index 82380c71d..000000000 --- a/plugins/outputs/opentelemetry/opentelemetry_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package opentelemetry - -func (o *OpenTelemetry) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/opentsdb/README.md b/plugins/outputs/opentsdb/README.md index 7c58b651b..e47683031 100644 --- a/plugins/outputs/opentsdb/README.md +++ b/plugins/outputs/opentsdb/README.md @@ -12,7 +12,7 @@ details. ## Configuration -```toml +```toml @sample.conf # Configuration for OpenTSDB server to send metrics to [[outputs.opentsdb]] ## prefix for metrics keys diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index efde7a6a1..e1949486c 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package opentsdb import ( + _ "embed" "fmt" "math" "net" @@ -14,6 +16,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( allowedChars = regexp.MustCompile(`[^a-zA-Z0-9-_./\p{L}]`) hyphenChars = strings.NewReplacer( @@ -53,6 +59,10 @@ func ToLineFormat(tags map[string]string) string { return strings.Join(tagsArray, " ") } +func (*OpenTSDB) SampleConfig() string { + return sampleConfig +} + func (o *OpenTSDB) Connect() error { if !strings.HasPrefix(o.Host, "http") && !strings.HasPrefix(o.Host, "tcp") { o.Host = "tcp://" + o.Host diff --git a/plugins/outputs/opentsdb/opentsdb_sample_config.go b/plugins/outputs/opentsdb/opentsdb_sample_config.go deleted file mode 100644 index 1f185ea10..000000000 --- a/plugins/outputs/opentsdb/opentsdb_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package opentsdb - -func (o *OpenTSDB) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/prometheus_client/README.md b/plugins/outputs/prometheus_client/README.md index 8ad9d471a..84a3afc82 100644 --- a/plugins/outputs/prometheus_client/README.md +++ b/plugins/outputs/prometheus_client/README.md @@ -5,7 +5,7 @@ metrics on `/metrics` (default) to be polled by a Prometheus server. ## Configuration -```toml +```toml @sample.conf # Configuration for the Prometheus client to spawn [[outputs.prometheus_client]] ## Address to listen on. diff --git a/plugins/outputs/prometheus_client/prometheus_client.go b/plugins/outputs/prometheus_client/prometheus_client.go index 257049001..564f3fd9b 100644 --- a/plugins/outputs/prometheus_client/prometheus_client.go +++ b/plugins/outputs/prometheus_client/prometheus_client.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package prometheus_client import ( "context" "crypto/tls" + _ "embed" "fmt" "net" "net/http" @@ -23,6 +25,10 @@ import ( v2 "github.com/influxdata/telegraf/plugins/outputs/prometheus_client/v2" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + var ( defaultListen = ":9273" defaultPath = "/metrics" @@ -56,6 +62,10 @@ type PrometheusClient struct { wg sync.WaitGroup } +func (*PrometheusClient) SampleConfig() string { + return sampleConfig +} + func (p *PrometheusClient) Init() error { defaultCollectors := map[string]bool{ "gocollector": true, diff --git a/plugins/outputs/prometheus_client/prometheus_client_sample_config.go b/plugins/outputs/prometheus_client/prometheus_client_sample_config.go deleted file mode 100644 index 6786d7b21..000000000 --- a/plugins/outputs/prometheus_client/prometheus_client_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package prometheus_client - -func (p *PrometheusClient) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/riemann/README.md b/plugins/outputs/riemann/README.md index ec9e2796e..f70b1e9de 100644 --- a/plugins/outputs/riemann/README.md +++ b/plugins/outputs/riemann/README.md @@ -4,7 +4,7 @@ This plugin writes to [Riemann](http://riemann.io/) via TCP or UDP. ## Configuration -```toml +```toml @sample.conf # Configuration for Riemann to send metrics to [[outputs.riemann]] ## The full TCP or UDP URL of the Riemann server diff --git a/plugins/outputs/riemann/riemann.go b/plugins/outputs/riemann/riemann.go index ed384aaaa..ad66d0bee 100644 --- a/plugins/outputs/riemann/riemann.go +++ b/plugins/outputs/riemann/riemann.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package riemann import ( + _ "embed" "fmt" "net/url" "os" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Riemann struct { URL string `toml:"url"` TTL float32 `toml:"ttl"` @@ -30,6 +36,10 @@ type Riemann struct { client *raidman.Client } +func (*Riemann) SampleConfig() string { + return sampleConfig +} + func (r *Riemann) Connect() error { parsedURL, err := url.Parse(r.URL) if err != nil { diff --git a/plugins/outputs/riemann/riemann_sample_config.go b/plugins/outputs/riemann/riemann_sample_config.go deleted file mode 100644 index 834fa0312..000000000 --- a/plugins/outputs/riemann/riemann_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package riemann - -func (r *Riemann) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/riemann_legacy/README.md b/plugins/outputs/riemann_legacy/README.md index 3e79a74ec..3e5835f87 100644 --- a/plugins/outputs/riemann_legacy/README.md +++ b/plugins/outputs/riemann_legacy/README.md @@ -7,7 +7,7 @@ instead. ## Configuration -```toml +```toml @sample.conf # Configuration for the Riemann server to send metrics to [[outputs.riemann_legacy]] ## URL of server diff --git a/plugins/outputs/riemann_legacy/riemann_legacy.go b/plugins/outputs/riemann_legacy/riemann_legacy.go index 13cf34dd8..714f8f271 100644 --- a/plugins/outputs/riemann_legacy/riemann_legacy.go +++ b/plugins/outputs/riemann_legacy/riemann_legacy.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package riemann_legacy import ( + _ "embed" "fmt" "os" "sort" @@ -12,6 +14,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const deprecationMsg = "Error: this Riemann output plugin will be deprecated in a future release, see https://github.com/influxdata/telegraf/issues/1878 for more details & discussion." type Riemann struct { @@ -23,6 +29,10 @@ type Riemann struct { client *raidman.Client } +func (*Riemann) SampleConfig() string { + return sampleConfig +} + func (r *Riemann) Connect() error { r.Log.Error(deprecationMsg) c, err := raidman.Dial(r.Transport, r.URL) diff --git a/plugins/outputs/riemann_legacy/riemann_legacy_sample_config.go b/plugins/outputs/riemann_legacy/riemann_legacy_sample_config.go deleted file mode 100644 index ea6ab9e93..000000000 --- a/plugins/outputs/riemann_legacy/riemann_legacy_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package riemann_legacy - -func (r *Riemann) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/sensu/README.md b/plugins/outputs/sensu/README.md index 7376b440e..103993a6e 100644 --- a/plugins/outputs/sensu/README.md +++ b/plugins/outputs/sensu/README.md @@ -5,7 +5,7 @@ HTTP events API. ## Configuration -```toml +```toml @sample.conf # Send aggregate metrics to Sensu Monitor [[outputs.sensu]] ## BACKEND API URL is the Sensu Backend API root URL to send metrics to diff --git a/plugins/outputs/sensu/sensu.go b/plugins/outputs/sensu/sensu.go index ab14aac84..cbfef03c6 100644 --- a/plugins/outputs/sensu/sensu.go +++ b/plugins/outputs/sensu/sensu.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package sensu import ( "bytes" + _ "embed" "encoding/json" "fmt" "io" @@ -21,6 +23,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultURL = "http://127.0.0.1:3031" defaultClientTimeout = 5 * time.Second @@ -117,6 +123,10 @@ func (s *Sensu) createClient() (*http.Client, error) { return client, nil } +func (*Sensu) SampleConfig() string { + return sampleConfig +} + func (s *Sensu) Connect() error { err := s.setEndpointURL() if err != nil { diff --git a/plugins/outputs/sensu/sensu_sample_config.go b/plugins/outputs/sensu/sensu_sample_config.go deleted file mode 100644 index bf91158d0..000000000 --- a/plugins/outputs/sensu/sensu_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sensu - -func (s *Sensu) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/signalfx/README.md b/plugins/outputs/signalfx/README.md index 9cbd69adf..7d9a79506 100644 --- a/plugins/outputs/signalfx/README.md +++ b/plugins/outputs/signalfx/README.md @@ -6,7 +6,7 @@ The SignalFx output plugin sends metrics to [SignalFx][docs]. ## Configuration -```toml +```toml @sample.conf # Send metrics and events to SignalFx [[outputs.signalfx]] ## SignalFx Org Access Token diff --git a/plugins/outputs/signalfx/signalfx.go b/plugins/outputs/signalfx/signalfx.go index b5ff8d8cd..abae1058f 100644 --- a/plugins/outputs/signalfx/signalfx.go +++ b/plugins/outputs/signalfx/signalfx.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package signalfx import ( "context" + _ "embed" "errors" "fmt" "strings" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + //init initializes the plugin context func init() { outputs.Add("signalfx", func() telegraf.Output { @@ -71,6 +77,10 @@ func NewSignalFx() *SignalFx { } } +func (*SignalFx) SampleConfig() string { + return sampleConfig +} + // Connect establishes a connection to SignalFx func (s *SignalFx) Connect() error { client := s.client.(*sfxclient.HTTPSink) diff --git a/plugins/outputs/signalfx/signalfx_sample_config.go b/plugins/outputs/signalfx/signalfx_sample_config.go deleted file mode 100644 index 34a09107e..000000000 --- a/plugins/outputs/signalfx/signalfx_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package signalfx - -func (s *SignalFx) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/socket_writer/README.md b/plugins/outputs/socket_writer/README.md index a0c908fcb..d51691e16 100644 --- a/plugins/outputs/socket_writer/README.md +++ b/plugins/outputs/socket_writer/README.md @@ -8,7 +8,7 @@ It can output data in any of the [supported output formats][formats]. ## Configuration -```toml +```toml @sample.conf # Generic socket writer capable of handling multiple socket types. [[outputs.socket_writer]] ## URL to connect to diff --git a/plugins/outputs/socket_writer/socket_writer.go b/plugins/outputs/socket_writer/socket_writer.go index 016b9f327..567ec74cd 100644 --- a/plugins/outputs/socket_writer/socket_writer.go +++ b/plugins/outputs/socket_writer/socket_writer.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package socket_writer import ( "crypto/tls" + _ "embed" "fmt" "net" "strings" @@ -15,6 +17,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type SocketWriter struct { ContentEncoding string `toml:"content_encoding"` Address string @@ -29,6 +35,10 @@ type SocketWriter struct { net.Conn } +func (*SocketWriter) SampleConfig() string { + return sampleConfig +} + func (sw *SocketWriter) SetSerializer(s serializers.Serializer) { sw.Serializer = s } diff --git a/plugins/outputs/socket_writer/socket_writer_sample_config.go b/plugins/outputs/socket_writer/socket_writer_sample_config.go deleted file mode 100644 index cfd503a0c..000000000 --- a/plugins/outputs/socket_writer/socket_writer_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package socket_writer - -func (sw *SocketWriter) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/sql/README.md b/plugins/outputs/sql/README.md index 40f8650b7..af7ccf73f 100644 --- a/plugins/outputs/sql/README.md +++ b/plugins/outputs/sql/README.md @@ -60,7 +60,7 @@ convert settings. ## Configuration -```toml +```toml @sample.conf # Save metrics to an SQL Database [[outputs.sql]] ## Database driver diff --git a/plugins/outputs/sql/sql.go b/plugins/outputs/sql/sql.go index fb2d07273..e0926d390 100644 --- a/plugins/outputs/sql/sql.go +++ b/plugins/outputs/sql/sql.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package sql import ( gosql "database/sql" + _ "embed" "fmt" "strings" @@ -16,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type ConvertStruct struct { Integer string Real string @@ -41,6 +47,10 @@ type SQL struct { tables map[string]bool } +func (*SQL) SampleConfig() string { + return sampleConfig +} + func (p *SQL) Connect() error { db, err := gosql.Open(p.Driver, p.DataSourceName) if err != nil { diff --git a/plugins/outputs/sql/sql_sample_config.go b/plugins/outputs/sql/sql_sample_config.go deleted file mode 100644 index 533a058fd..000000000 --- a/plugins/outputs/sql/sql_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sql - -func (p *SQL) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/stackdriver/README.md b/plugins/outputs/stackdriver/README.md index 100965921..e86d253c6 100644 --- a/plugins/outputs/stackdriver/README.md +++ b/plugins/outputs/stackdriver/README.md @@ -20,7 +20,7 @@ the required `project_id` label is always set to the `project` variable. ## Configuration -```toml +```toml @sample.conf # Configuration for Google Cloud Stackdriver to send metrics to [[outputs.stackdriver]] ## GCP Project diff --git a/plugins/outputs/stackdriver/stackdriver.go b/plugins/outputs/stackdriver/stackdriver.go index da5b9a31d..4223a0ebd 100644 --- a/plugins/outputs/stackdriver/stackdriver.go +++ b/plugins/outputs/stackdriver/stackdriver.go @@ -1,14 +1,16 @@ +//go:generate ../../../tools/readme_config_includer/generator package stackdriver import ( "context" + _ "embed" "fmt" "hash/fnv" "path" "sort" "strings" - monitoring "cloud.google.com/go/monitoring/apiv3/v2" // Imports the Stackdriver Monitoring client package. + monitoring "cloud.google.com/go/monitoring/apiv3/v2" "google.golang.org/api/option" metricpb "google.golang.org/genproto/googleapis/api/metric" monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres" @@ -20,6 +22,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // Stackdriver is the Google Stackdriver config info. type Stackdriver struct { Project string `toml:"project"` @@ -51,6 +57,10 @@ const ( errStringPointsTooFrequent = "one or more points were written more frequently than the maximum sampling period configured for the metric" ) +func (*Stackdriver) SampleConfig() string { + return sampleConfig +} + // Connect initiates the primary connection to the GCP project. func (s *Stackdriver) Connect() error { if s.Project == "" { diff --git a/plugins/outputs/stackdriver/stackdriver_sample_config.go b/plugins/outputs/stackdriver/stackdriver_sample_config.go deleted file mode 100644 index 5d3123e34..000000000 --- a/plugins/outputs/stackdriver/stackdriver_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package stackdriver - -func (s *Stackdriver) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/sumologic/README.md b/plugins/outputs/sumologic/README.md index 7ee149353..f5b9b491e 100644 --- a/plugins/outputs/sumologic/README.md +++ b/plugins/outputs/sumologic/README.md @@ -16,7 +16,7 @@ by Sumologic HTTP Source: ## Configuration -```toml +```toml @sample.conf # A plugin that can send metrics to Sumo Logic HTTP metric collector. [[outputs.sumologic]] ## Unique URL generated for your HTTP Metrics Source. diff --git a/plugins/outputs/sumologic/sumologic.go b/plugins/outputs/sumologic/sumologic.go index 1ac198787..2791f9052 100644 --- a/plugins/outputs/sumologic/sumologic.go +++ b/plugins/outputs/sumologic/sumologic.go @@ -1,8 +1,10 @@ +//go:generate ../../../tools/readme_config_includer/generator package sumologic import ( "bytes" "compress/gzip" + _ "embed" "net/http" "time" @@ -18,6 +20,10 @@ import ( "github.com/influxdata/telegraf/plugins/serializers/prometheus" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultClientTimeout = 5 * time.Second defaultMethod = http.MethodPost @@ -57,6 +63,10 @@ type SumoLogic struct { headers map[string]string } +func (*SumoLogic) SampleConfig() string { + return sampleConfig +} + func (s *SumoLogic) SetSerializer(serializer serializers.Serializer) { if s.headers == nil { s.headers = make(map[string]string) diff --git a/plugins/outputs/sumologic/sumologic_sample_config.go b/plugins/outputs/sumologic/sumologic_sample_config.go deleted file mode 100644 index 675e53b1f..000000000 --- a/plugins/outputs/sumologic/sumologic_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package sumologic - -func (s *SumoLogic) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/syslog/README.md b/plugins/outputs/syslog/README.md index 981f041ff..737e726a3 100644 --- a/plugins/outputs/syslog/README.md +++ b/plugins/outputs/syslog/README.md @@ -11,7 +11,7 @@ Syslog messages are formatted according to [RFC ## Configuration -```toml +```toml @sample.conf # Configuration for Syslog server to send metrics to [[outputs.syslog]] ## URL to connect to diff --git a/plugins/outputs/syslog/syslog.go b/plugins/outputs/syslog/syslog.go index ce2564b5e..7d78ad65e 100644 --- a/plugins/outputs/syslog/syslog.go +++ b/plugins/outputs/syslog/syslog.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package syslog import ( "crypto/tls" + _ "embed" "fmt" "net" "strconv" @@ -18,6 +20,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type Syslog struct { Address string KeepAlivePeriod *config.Duration @@ -35,6 +41,10 @@ type Syslog struct { mapper *SyslogMapper } +func (*Syslog) SampleConfig() string { + return sampleConfig +} + func (s *Syslog) Connect() error { s.initializeSyslogMapper() diff --git a/plugins/outputs/syslog/syslog_sample_config.go b/plugins/outputs/syslog/syslog_sample_config.go deleted file mode 100644 index 002c39f0e..000000000 --- a/plugins/outputs/syslog/syslog_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package syslog - -func (s *Syslog) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/timestream/README.md b/plugins/outputs/timestream/README.md index 05f781c3a..8b4da71ae 100644 --- a/plugins/outputs/timestream/README.md +++ b/plugins/outputs/timestream/README.md @@ -4,7 +4,7 @@ The Timestream output plugin writes metrics to the [Amazon Timestream] service. ## Configuration -```toml +```toml @sample.conf # Configuration for sending metrics to Amazon Timestream. [[outputs.timestream]] ## Amazon Region diff --git a/plugins/outputs/timestream/timestream.go b/plugins/outputs/timestream/timestream.go index 267177418..297d08ca0 100644 --- a/plugins/outputs/timestream/timestream.go +++ b/plugins/outputs/timestream/timestream.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package timestream import ( "context" + _ "embed" "errors" "fmt" "reflect" @@ -19,6 +21,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + type ( Timestream struct { MappingMode string `toml:"mapping_mode"` @@ -70,6 +76,10 @@ var WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteCl return timestreamwrite.NewFromConfig(cfg), nil } +func (*Timestream) SampleConfig() string { + return sampleConfig +} + func (t *Timestream) Connect() error { if t.DatabaseName == "" { return fmt.Errorf("DatabaseName key is required") diff --git a/plugins/outputs/timestream/timestream_sample_config.go b/plugins/outputs/timestream/timestream_sample_config.go deleted file mode 100644 index 597fcfbd2..000000000 --- a/plugins/outputs/timestream/timestream_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package timestream - -func (t *Timestream) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/warp10/README.md b/plugins/outputs/warp10/README.md index 78a1adb17..46eeb9d6f 100644 --- a/plugins/outputs/warp10/README.md +++ b/plugins/outputs/warp10/README.md @@ -4,7 +4,7 @@ The `warp10` output plugin writes metrics to [Warp 10][]. ## Configuration -```toml +```toml @sample.conf # Write metrics to Warp 10 [[outputs.warp10]] # Prefix to add to the measurement. diff --git a/plugins/outputs/warp10/warp10.go b/plugins/outputs/warp10/warp10.go index 06d6a5af6..d97d93b38 100644 --- a/plugins/outputs/warp10/warp10.go +++ b/plugins/outputs/warp10/warp10.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package warp10 import ( "bytes" + _ "embed" "fmt" "io" "math" @@ -18,6 +20,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultClientTimeout = 15 * time.Second ) @@ -64,6 +70,10 @@ func (w *Warp10) createClient() (*http.Client, error) { return client, nil } +func (*Warp10) SampleConfig() string { + return sampleConfig +} + // Connect to warp10 func (w *Warp10) Connect() error { client, err := w.createClient() diff --git a/plugins/outputs/warp10/warp10_sample_config.go b/plugins/outputs/warp10/warp10_sample_config.go deleted file mode 100644 index afd8bd966..000000000 --- a/plugins/outputs/warp10/warp10_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package warp10 - -func (w *Warp10) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/wavefront/README.md b/plugins/outputs/wavefront/README.md index 86cdea409..2d192d669 100644 --- a/plugins/outputs/wavefront/README.md +++ b/plugins/outputs/wavefront/README.md @@ -5,7 +5,7 @@ Wavefront data format over TCP. ## Configuration -```toml +```toml @sample.conf # Configuration for Wavefront server to send metrics to [[outputs.wavefront]] ## Url for Wavefront Direct Ingestion. For Wavefront Proxy Ingestion, see diff --git a/plugins/outputs/wavefront/wavefront.go b/plugins/outputs/wavefront/wavefront.go index 5a02bf9d7..dabfad78f 100644 --- a/plugins/outputs/wavefront/wavefront.go +++ b/plugins/outputs/wavefront/wavefront.go @@ -1,6 +1,8 @@ +//go:generate ../../../tools/readme_config_includer/generator package wavefront import ( + _ "embed" "fmt" "regexp" "strings" @@ -11,6 +13,10 @@ import ( "github.com/influxdata/telegraf/plugins/outputs" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const maxTagLength = 254 type Wavefront struct { @@ -66,6 +72,10 @@ type MetricPoint struct { Tags map[string]string } +func (*Wavefront) SampleConfig() string { + return sampleConfig +} + func (w *Wavefront) Connect() error { flushSeconds := 5 if w.ImmediateFlush { diff --git a/plugins/outputs/wavefront/wavefront_sample_config.go b/plugins/outputs/wavefront/wavefront_sample_config.go deleted file mode 100644 index e79fee6c6..000000000 --- a/plugins/outputs/wavefront/wavefront_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package wavefront - -func (w *Wavefront) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/websocket/README.md b/plugins/outputs/websocket/README.md index 4e0d7ba51..63e4aed2f 100644 --- a/plugins/outputs/websocket/README.md +++ b/plugins/outputs/websocket/README.md @@ -8,7 +8,7 @@ It can output data in any of the [supported output formats][formats]. ## Configuration -```toml +```toml @sample.conf # A plugin that can transmit metrics over WebSocket. [[outputs.websocket]] ## URL is the address to send metrics to. Make sure ws or wss scheme is used. diff --git a/plugins/outputs/websocket/websocket.go b/plugins/outputs/websocket/websocket.go index 3ff94739d..eaed85977 100644 --- a/plugins/outputs/websocket/websocket.go +++ b/plugins/outputs/websocket/websocket.go @@ -1,22 +1,28 @@ +//go:generate ../../../tools/readme_config_includer/generator package websocket import ( + _ "embed" "errors" "fmt" "net/http" "net/url" "time" + ws "github.com/gorilla/websocket" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/plugins/common/proxy" "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/plugins/outputs" "github.com/influxdata/telegraf/plugins/serializers" - - ws "github.com/gorilla/websocket" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + const ( defaultConnectTimeout = 30 * time.Second defaultWriteTimeout = 30 * time.Second @@ -40,6 +46,10 @@ type WebSocket struct { serializer serializers.Serializer } +func (*WebSocket) SampleConfig() string { + return sampleConfig +} + // SetSerializer implements serializers.SerializerOutput. func (w *WebSocket) SetSerializer(serializer serializers.Serializer) { w.serializer = serializer diff --git a/plugins/outputs/websocket/websocket_sample_config.go b/plugins/outputs/websocket/websocket_sample_config.go deleted file mode 100644 index af46cfa14..000000000 --- a/plugins/outputs/websocket/websocket_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package websocket - -func (w *WebSocket) SampleConfig() string { - return `{{ .SampleConfig }}` -} diff --git a/plugins/outputs/yandex_cloud_monitoring/README.md b/plugins/outputs/yandex_cloud_monitoring/README.md index 2e2cbd72e..76ab9ffde 100644 --- a/plugins/outputs/yandex_cloud_monitoring/README.md +++ b/plugins/outputs/yandex_cloud_monitoring/README.md @@ -5,7 +5,7 @@ Monitoring](https://cloud.yandex.com/services/monitoring). ## Configuration -```toml +```toml @sample.conf # Send aggregated metrics to Yandex.Cloud Monitoring [[outputs.yandex_cloud_monitoring]] ## Timeout for HTTP writes. diff --git a/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go b/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go index 08d353ad9..9ccd0870d 100644 --- a/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go +++ b/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring.go @@ -1,7 +1,9 @@ +//go:generate ../../../tools/readme_config_includer/generator package yandex_cloud_monitoring import ( "bytes" + _ "embed" "encoding/json" "fmt" "io" @@ -14,6 +16,10 @@ import ( "github.com/influxdata/telegraf/selfstat" ) +// DO NOT REMOVE THE NEXT TWO LINES! This is required to embedd the sampleConfig data. +//go:embed sample.conf +var sampleConfig string + // YandexCloudMonitoring allows publishing of metrics to the Yandex Cloud Monitoring custom metrics // service type YandexCloudMonitoring struct { @@ -63,6 +69,10 @@ const ( defaultMetadataFolderURL = "http://169.254.169.254/computeMetadata/v1/yandex/folder-id" ) +func (*YandexCloudMonitoring) SampleConfig() string { + return sampleConfig +} + // Connect initializes the plugin and validates connectivity func (a *YandexCloudMonitoring) Connect() error { if a.Timeout <= 0 { diff --git a/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring_sample_config.go b/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring_sample_config.go deleted file mode 100644 index a53afdd59..000000000 --- a/plugins/outputs/yandex_cloud_monitoring/yandex_cloud_monitoring_sample_config.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:generate go run ../../../tools/generate_plugindata/main.go -//go:generate go run ../../../tools/generate_plugindata/main.go --clean -// DON'T EDIT; This file is used as a template by tools/generate_plugindata -package yandex_cloud_monitoring - -func (a *YandexCloudMonitoring) SampleConfig() string { - return `{{ .SampleConfig }}` -}