1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,68 @@
package inputs_sflow
import (
"fmt"
"github.com/influxdata/toml"
"github.com/influxdata/toml/ast"
"github.com/influxdata/telegraf/migrations"
"github.com/influxdata/telegraf/migrations/common"
)
const msg = `
Replacement 'inputs.netflow' will output a different metric format.
Please adapt your queries!
`
// Define "old" data structure
type sflow struct {
ServiceAddress string `toml:"service_address"`
ReadBufferSize string `toml:"read_buffer_size"`
common.InputOptions
}
// Migration function
func migrate(tbl *ast.Table) ([]byte, string, error) {
// Decode the old data structure
var old sflow
if err := toml.UnmarshalTable(tbl, &old); err != nil {
return nil, "", err
}
// Fill common options
plugin := make(map[string]interface{})
old.InputOptions.Migrate()
general, err := toml.Marshal(old.InputOptions)
if err != nil {
return nil, "", fmt.Errorf("marshalling general options failed: %w", err)
}
if err := toml.Unmarshal(general, &plugin); err != nil {
return nil, "", fmt.Errorf("re-unmarshalling general options failed: %w", err)
}
// Use a map for the new plugin and fill in the data
plugin["service_address"] = old.ServiceAddress
if old.ReadBufferSize != "" {
plugin["read_buffer_size"] = old.ReadBufferSize
}
// Create the corresponding metric configurations
cfg := migrations.CreateTOMLStruct("inputs", "netflow")
cfg.Add("inputs", "netflow", plugin)
// Marshal the new configuration
buf, err := toml.Marshal(cfg)
if err != nil {
return nil, "", err
}
buf = append(buf, []byte("\n")...)
// Create the new content to output
return buf, msg, nil
}
// Register the migration function for the plugin type
func init() {
migrations.AddPluginMigration("inputs.sflow", migrate)
}

View file

@ -0,0 +1,62 @@
package inputs_sflow_test
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/influxdata/telegraf/config"
_ "github.com/influxdata/telegraf/migrations/inputs_sflow" // register migration
_ "github.com/influxdata/telegraf/plugins/inputs/netflow" // register plugin
_ "github.com/influxdata/telegraf/plugins/inputs/sflow" // register plugin
)
func TestCases(t *testing.T) {
// Get all directories in testdata
folders, err := os.ReadDir("testcases")
require.NoError(t, err)
for _, f := range folders {
// Only handle folders
if !f.IsDir() {
continue
}
t.Run(f.Name(), func(t *testing.T) {
testcasePath := filepath.Join("testcases", f.Name())
inputFile := filepath.Join(testcasePath, "telegraf.conf")
expectedFile := filepath.Join(testcasePath, "expected.conf")
// Read the expected output
expected := config.NewConfig()
require.NoError(t, expected.LoadConfig(expectedFile))
require.NotEmpty(t, expected.Inputs)
// Read the input data
input, remote, err := config.LoadConfigFile(inputFile)
require.NoError(t, err)
require.False(t, remote)
require.NotEmpty(t, input)
// Migrate
output, n, err := config.ApplyMigrations(input)
require.NoError(t, err)
require.NotEmpty(t, output)
require.GreaterOrEqual(t, n, uint64(1))
actual := config.NewConfig()
require.NoError(t, actual.LoadConfigData(output, config.EmptySourcePath))
// Test the output
require.Len(t, actual.Inputs, len(expected.Inputs))
actualIDs := make([]string, 0, len(expected.Inputs))
expectedIDs := make([]string, 0, len(expected.Inputs))
for i := range actual.Inputs {
actualIDs = append(actualIDs, actual.Inputs[i].ID())
expectedIDs = append(expectedIDs, expected.Inputs[i].ID())
}
require.ElementsMatchf(t, expectedIDs, actualIDs, "generated config: %s", string(output))
})
}
}

View file

@ -0,0 +1,7 @@
[[inputs.netflow]]
service_address = "udp://:6343"
read_buffer_size = "32KiB"
fieldinclude = ["a"]
name_override = "foo"
[inputs.netflow.tags]
foo = "bar"

View file

@ -0,0 +1,8 @@
[[inputs.sflow]]
service_address = "udp://:6343"
read_buffer_size = "32KiB"
name_override = "foo"
fieldpass = ["a"]
[inputs.sflow.tags]
foo = "bar"

View file

@ -0,0 +1,2 @@
[[inputs.netflow]]
service_address = "udp://:6343"

View file

@ -0,0 +1,11 @@
# SFlow V5 Protocol Listener
[[inputs.sflow]]
## Address to listen for sFlow packets.
## example: service_address = "udp://:6343"
## service_address = "udp4://:6343"
## service_address = "udp6://:6343"
service_address = "udp://:6343"
## Set the size of the operating system's receive buffer.
## example: read_buffer_size = "64KiB"
# read_buffer_size = ""

View file

@ -0,0 +1,3 @@
[[inputs.netflow]]
service_address = "udp://:6343"
read_buffer_size = "32KiB"

View file

@ -0,0 +1,11 @@
# SFlow V5 Protocol Listener
[[inputs.sflow]]
## Address to listen for sFlow packets.
## example: service_address = "udp://:6343"
## service_address = "udp4://:6343"
## service_address = "udp6://:6343"
service_address = "udp://:6343"
## Set the size of the operating system's receive buffer.
## example: read_buffer_size = "64KiB"
read_buffer_size = "32KiB"