Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
55
plugins/outputs/stomp/README.md
Normal file
55
plugins/outputs/stomp/README.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# ActiveMQ STOMP Output Plugin
|
||||
|
||||
This plugin writes metrics to an [Active MQ Broker][activemq] for [STOMP][stomp]
|
||||
but also supports [Amazon MQ][amazonmq] brokers. Metrics can be written in one
|
||||
of the supported [data formats][data_formats].
|
||||
|
||||
⭐ Telegraf v1.24.0
|
||||
🏷️ messaging
|
||||
💻 all
|
||||
|
||||
[activemq]: http://activemq.apache.org/
|
||||
[stomp]: https://stomp.github.io
|
||||
[amazonmq]:https://aws.amazon.com/amazon-mq
|
||||
[data_formats]: /docs/DATA_FORMATS_OUTPUT.md
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## Secret-store support
|
||||
|
||||
This plugin supports secrets from secret-stores for the `username` and
|
||||
`password` option.
|
||||
See the [secret-store documentation][SECRETSTORE] for more details on how
|
||||
to use them.
|
||||
|
||||
[SECRETSTORE]: ../../../docs/CONFIGURATION.md#secret-store-secrets
|
||||
|
||||
## Configuration
|
||||
|
||||
```toml @sample.conf
|
||||
# Configuration for active mq with stomp protocol to send metrics to
|
||||
[[outputs.stomp]]
|
||||
host = "localhost:61613"
|
||||
|
||||
## Queue name for producer messages
|
||||
queueName = "telegraf"
|
||||
|
||||
## Username and password if required by the Active MQ server.
|
||||
# username = ""
|
||||
# password = ""
|
||||
|
||||
## Optional TLS Config
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
# tls_cert = "/etc/telegraf/cert.pem"
|
||||
# tls_key = "/etc/telegraf/key.pem"
|
||||
|
||||
## Data format to output.
|
||||
data_format = "json"
|
||||
```
|
18
plugins/outputs/stomp/sample.conf
Normal file
18
plugins/outputs/stomp/sample.conf
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Configuration for active mq with stomp protocol to send metrics to
|
||||
[[outputs.stomp]]
|
||||
host = "localhost:61613"
|
||||
|
||||
## Queue name for producer messages
|
||||
queueName = "telegraf"
|
||||
|
||||
## Username and password if required by the Active MQ server.
|
||||
# username = ""
|
||||
# password = ""
|
||||
|
||||
## Optional TLS Config
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
# tls_cert = "/etc/telegraf/cert.pem"
|
||||
# tls_key = "/etc/telegraf/key.pem"
|
||||
|
||||
## Data format to output.
|
||||
data_format = "json"
|
119
plugins/outputs/stomp/stomp.go
Normal file
119
plugins/outputs/stomp/stomp.go
Normal file
|
@ -0,0 +1,119 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package stomp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/go-stomp/stomp"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/config"
|
||||
common_tls "github.com/influxdata/telegraf/plugins/common/tls"
|
||||
"github.com/influxdata/telegraf/plugins/outputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
type STOMP struct {
|
||||
Host string `toml:"host"`
|
||||
Username config.Secret `toml:"username"`
|
||||
Password config.Secret `toml:"password"`
|
||||
QueueName string `toml:"queueName"`
|
||||
Log telegraf.Logger `toml:"-"`
|
||||
|
||||
HeartBeatSend config.Duration `toml:"heartbeat_timeout_send"`
|
||||
HeartBeatRec config.Duration `toml:"heartbeat_timeout_receive"`
|
||||
|
||||
common_tls.ClientConfig
|
||||
|
||||
conn net.Conn
|
||||
stomp *stomp.Conn
|
||||
|
||||
serialize telegraf.Serializer
|
||||
}
|
||||
|
||||
func (q *STOMP) Connect() error {
|
||||
tlsConfig, err := q.ClientConfig.TLSConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tlsConfig != nil {
|
||||
q.conn, err = tls.Dial("tcp", q.Host, tlsConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
q.conn, err = net.Dial("tcp", q.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
authOption, err := q.getAuthOption()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
heartbeatOption := stomp.ConnOpt.HeartBeat(
|
||||
time.Duration(q.HeartBeatSend),
|
||||
time.Duration(q.HeartBeatRec),
|
||||
)
|
||||
q.stomp, err = stomp.Connect(q.conn, heartbeatOption, authOption)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q.Log.Debug("STOMP Connected...")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *STOMP) SetSerializer(serializer telegraf.Serializer) {
|
||||
q.serialize = serializer
|
||||
}
|
||||
|
||||
func (q *STOMP) Write(metrics []telegraf.Metric) error {
|
||||
for _, metric := range metrics {
|
||||
values, err := q.serialize.Serialize(metric)
|
||||
if err != nil {
|
||||
q.Log.Errorf("Serializing metric %v failed: %s", metric, err)
|
||||
continue
|
||||
}
|
||||
err = q.stomp.Send(q.QueueName, "text/plain", values, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("sending metric failed: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (*STOMP) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
func (q *STOMP) Close() error {
|
||||
return q.stomp.Disconnect()
|
||||
}
|
||||
|
||||
func (q *STOMP) getAuthOption() (func(*stomp.Conn) error, error) {
|
||||
username, err := q.Username.Get()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting username failed: %w", err)
|
||||
}
|
||||
defer username.Destroy()
|
||||
password, err := q.Password.Get()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting password failed: %w", err)
|
||||
}
|
||||
defer password.Destroy()
|
||||
return stomp.ConnOpt.Login(username.String(), password.String()), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
outputs.Add("stomp", func() telegraf.Output {
|
||||
return &STOMP{
|
||||
Host: "localhost:61613",
|
||||
QueueName: "telegraf",
|
||||
}
|
||||
})
|
||||
}
|
50
plugins/outputs/stomp/stomp_test.go
Normal file
50
plugins/outputs/stomp/stomp_test.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package stomp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/plugins/serializers/json"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestConnectAndWrite(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
}
|
||||
|
||||
servicePort := "61613"
|
||||
container := testutil.Container{
|
||||
Image: "rmohr/activemq",
|
||||
ExposedPorts: []string{servicePort},
|
||||
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
|
||||
}
|
||||
err := container.Start()
|
||||
require.NoError(t, err, "failed to start container")
|
||||
defer container.Terminate()
|
||||
var url = fmt.Sprintf("%s:%s", container.Address, container.Ports[servicePort])
|
||||
|
||||
s := &json.Serializer{
|
||||
TimestampUnits: config.Duration(10 * time.Second),
|
||||
TimestampFormat: "yyy-dd-mmThh:mm:ss",
|
||||
}
|
||||
require.NoError(t, s.Init())
|
||||
|
||||
st := &STOMP{
|
||||
Host: url,
|
||||
QueueName: "test_queue",
|
||||
HeartBeatSend: 0,
|
||||
HeartBeatRec: 0,
|
||||
Log: testutil.Logger{},
|
||||
serialize: s,
|
||||
}
|
||||
require.NoError(t, st.Connect())
|
||||
|
||||
require.NoError(t, st.Write(testutil.MockMetrics()))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue