cmd/scollector: Hide TSDB credentials in logs
Upon startup, scollector reports which OpenTSDB host it is connected to.
In case there is authentication required, the credentials were logged as
part of the URL. This patch replaces them with dummies.
@@ -253,7 +253,7 @@ func main() {
}
cdp, cquit := collectors.Run(c)
if u != nil {
- slog.Infoln("OpenTSDB host:", u)
+ slog.Infoln("OpenTSDB host:", hideUrlCredentials(u))
}
collect.UseNtlm = conf.UseNtlm
if err := collect.InitChan(u, "scollector", cdp); err != nil {
@@ -400,6 +400,17 @@ func parseHost(host string) (*url.URL, error) {
return u, nil
}
+func hideUrlCredentials(u *url.URL) *url.URL {
+ // Copy original url, replace credentials, e. g. for logging
+ if u.User != nil {
+ u2 := new(url.URL)
+ *u2 = *u
+ u2.User = url.UserPassword("xxx", "xxx")
+ return u2
+ }
+ return u
+}
+
func printPut(c chan *opentsdb.DataPoint) {
for dp := range c {
b, _ := json.Marshal(dp)
