forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mongodb output plugin (influxdata#9923)
- Loading branch information
1 parent
343e846
commit 7d6672c
Showing
17 changed files
with
872 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# MongoDB Output Plugin | ||
|
||
This plugin sends metrics to MongoDB and automatically creates the collections as time series collections when they don't already exist. | ||
**Please note:** Requires MongoDB 5.0+ for Time Series Collections | ||
|
||
### Configuration: | ||
|
||
```toml | ||
# A plugin that can transmit logs to mongodb | ||
[[outputs.mongodb]] | ||
# connection string examples for mongodb | ||
dsn = "mongodb://localhost:27017" | ||
# dsn = "mongodb://mongod1:27017,mongod2:27017,mongod3:27017/admin&replicaSet=myReplSet&w=1" | ||
|
||
# overrides serverSelectionTimeoutMS in dsn if set | ||
# timeout = "30s" | ||
|
||
# default authentication, optional | ||
# authentication = "NONE" | ||
|
||
# for SCRAM-SHA-256 authentication | ||
# authentication = "SCRAM" | ||
# username = "root" | ||
# password = "***" | ||
|
||
# for x509 certificate authentication | ||
# authentication = "X509" | ||
# tls_ca = "ca.pem" | ||
# tls_key = "client.pem" | ||
# # tls_key_pwd = "changeme" # required for encrypted tls_key | ||
# insecure_skip_verify = false | ||
|
||
# database to store measurements and time series collections | ||
# database = "telegraf" | ||
|
||
# granularity can be seconds, minutes, or hours. | ||
# configuring this value will be based on your input collection frequency. | ||
# see https://docs.mongodb.com/manual/core/timeseries-collections/#create-a-time-series-collection | ||
# granularity = "seconds" | ||
|
||
# optionally set a TTL to automatically expire documents from the measurement collections. | ||
# ttl = "360h" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM docker.io/library/mongo:latest | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y openssh-client | ||
|
||
WORKDIR /var/log | ||
RUN mkdir -p mongodb_noauth/ mongodb_scram/ mongodb_x509/ mongodb_x509_expire/ | ||
|
||
WORKDIR /opt | ||
COPY ./testutil/pki/tls-certs.sh . | ||
RUN mkdir -p data/noauth data/scram data/x509 data/x509_expire | ||
RUN /opt/tls-certs.sh | ||
|
||
COPY ./plugins/outputs/mongodb/dev/mongodb.sh . | ||
RUN chmod +x mongodb.sh | ||
|
||
EXPOSE 27017 | ||
EXPOSE 27018 | ||
EXPOSE 27019 | ||
EXPOSE 27020 | ||
|
||
CMD ./mongodb.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
# no auth | ||
mongod --dbpath data/noauth --fork --logpath /var/log/mongodb_noauth/mongod.log --bind_ip 0.0.0.0 --port 27017 | ||
|
||
# scram auth | ||
mongod --dbpath data/scram --fork --logpath /var/log/mongodb_scram/mongod.log --bind_ip 0.0.0.0 --port 27018 | ||
mongo localhost:27018/admin --eval "db.createUser({user:\"root\", pwd:\"changeme\", roles:[{role:\"root\",db:\"admin\"}]})" | ||
mongo localhost:27018/admin --eval "db.shutdownServer()" | ||
mongod --dbpath data/scram --fork --logpath /var/log/mongodb_scram/mongod.log --auth --setParameter authenticationMechanisms=SCRAM-SHA-256 --bind_ip 0.0.0.0 --port 27018 | ||
|
||
# get client certificate subject for creating x509 authenticating user | ||
dn=$(openssl x509 -in ./private/client.pem -noout -subject -nameopt RFC2253 | sed 's/subject=//g') | ||
|
||
# x509 auth | ||
mongod --dbpath data/x509 --fork --logpath /var/log/mongodb_x509/mongod.log --bind_ip 0.0.0.0 --port 27019 | ||
mongo localhost:27019/admin --eval "db.getSiblingDB(\"\$external\").runCommand({createUser:\"$dn\",roles:[{role:\"root\",db:\"admin\"}]})" | ||
mongo localhost:27019/admin --eval "db.shutdownServer()" | ||
mongod --dbpath data/x509 --fork --logpath /var/log/mongodb_x509/mongod.log --auth --setParameter authenticationMechanisms=MONGODB-X509 --tlsMode preferTLS --tlsCAFile certs/cacert.pem --tlsCertificateKeyFile private/server.pem --bind_ip 0.0.0.0 --port 27019 | ||
|
||
# x509 auth short expirey | ||
# mongodb will not start with an expired certificate. service must be started before certificate expires. tests should be run after certificate expiry | ||
mongod --dbpath data/x509_expire --fork --logpath /var/log/mongodb_x509_expire/mongod.log --bind_ip 0.0.0.0 --port 27020 | ||
mongo localhost:27020/admin --eval "db.getSiblingDB(\"\$external\").runCommand({createUser:\"$dn\",roles:[{role:\"root\",db:\"admin\"}]})" | ||
mongo localhost:27020/admin --eval "db.shutdownServer()" | ||
mongod --dbpath data/x509_expire --fork --logpath /var/log/mongodb_x509_expire/mongod.log --auth --setParameter authenticationMechanisms=MONGODB-X509 --tlsMode preferTLS --tlsCAFile certs/cacert.pem --tlsCertificateKeyFile private/serverexp.pem --bind_ip 0.0.0.0 --port 27020 | ||
|
||
# note about key size and mongodb | ||
# x509 must be 2048 bytes or stronger in order for mongodb to start. otherwise you will receive similar error below | ||
# {"keyFile":"/opt/private/server.pem","error":"error:140AB18F:SSL routines:SSL_CTX_use_certificate:ee key too small"} | ||
|
||
# copy key files to /opt/export. docker volume should point /opt/export to outputs/mongodb/dev in order to run non short x509 tests | ||
cp /opt/certs/cacert.pem /opt/private/client.pem /opt/private/clientenc.pem /opt/export | ||
|
||
while true; do sleep 1; done # leave container running. |
Oops, something went wrong.