influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.63k stars 5.58k forks source link

mongodb escaping special characters in password #13948

Closed m3rlinux closed 1 year ago

m3rlinux commented 1 year ago

Relevant telegraf.conf

###########
# MongoDB #
###########

[[inputs.mongodb]]
  servers = ["mongodb://mongouser:abc@DE^YtrnA@127.0.0.1:27017"]
  gather_cluster_status = true
  gather_perdb_stats = true
  gather_col_stats = true
  gather_top_stat = true

Logs from Telegraf

2023-09-19T10:15:50Z I! Loading config: /etc/telegraf/telegraf.d/mongo.conf
2023-09-19T10:15:50Z I! Starting Telegraf 1.28.1 brought to you by InfluxData the makers of InfluxDB
2023-09-19T10:15:50Z I! Available plugins: 240 inputs, 9 aggregators, 29 processors, 24 parsers, 59 outputs, 5 secret-stores
2023-09-19T10:15:50Z I! Loaded inputs: mongodb
2023-09-19T10:15:50Z I! Loaded aggregators: 
2023-09-19T10:15:50Z I! Loaded processors: 
2023-09-19T10:15:50Z I! Loaded secretstores: 
2023-09-19T10:15:50Z W! Outputs are not used in testing mode!
2023-09-19T10:15:50Z I! Tags enabled: host=myhost
2023-09-19T10:15:50Z D! [agent] Initializing plugins
2023-09-19T10:15:50Z D! [agent] Starting service inputs
2023-09-19T10:15:50Z E! [agent] Starting input inputs.mongodb: unable to parse connection URL: parse "mongodb://mongouser:abc@DE^YtrnA@127.0.0.1:27017": net/url: invalid userinfo
2023-09-19T10:15:51Z D! [agent] Stopping service inputs
2023-09-19T10:15:51Z D! [agent] Input channel closed
2023-09-19T10:15:51Z D! [agent] Stopped Successfully


### System info

Telegraf 1.28.1, Ubuntu 22.04.2 LTS 

### Steps to reproduce

1. write conf file
2. run command: telegraf --debug --test --config /etc/telegraf/telegraf.d/mongo.conf

### Expected behavior

No errors

### Actual behavior

Error in log and no metrics gathering
powersj commented 1 year ago

Hi,

As you are providing a URI, I would suggest you try URL encoding the password, specificaly, the @ becomes %40 and possibly the ^ becomes %5E.

m3rlinux commented 1 year ago

It works like a charm! Thanks @powersj