-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5419d8e
commit b793c84
Showing
1 changed file
with
10 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,8 @@ var ( | |
|
||
// GlobalFlags has command line flags to configure the exporter. | ||
type GlobalFlags struct { | ||
User string `name:"mongodb.user" help:"monitor user, need clusterMonitor role in admin db and read role in local db" env:"MONGODB_USER" placeholder:"monitor" default:"monitor"` | ||
Password string `name:"mongodb.password" help:"monitor user password" env:"MONGODB_PASSWORD" placeholder:"123456"` | ||
User string `name:"mongodb.user" help:"monitor user, need clusterMonitor role in admin db and read role in local db" env:"MONGODB_USER" placeholder:"monitorUser"` | ||
Password string `name:"mongodb.password" help:"monitor user password" env:"MONGODB_PASSWORD" placeholder:"monitorPassword"` | ||
CollStatsNamespaces string `name:"mongodb.collstats-colls" help:"List of comma separared databases.collections to get $collStats" placeholder:"db1,db2.col2"` | ||
IndexStatsCollections string `name:"mongodb.indexstats-colls" help:"List of comma separared databases.collections to get $indexStats" placeholder:"db1.col1,db2.col2"` | ||
URI string `name:"mongodb.uri" help:"MongoDB connection URI" env:"MONGODB_URI" placeholder:"mongodb://user:[email protected]:27017/admin?ssl=true"` | ||
|
@@ -105,16 +105,17 @@ func buildExporter(opts GlobalFlags) *exporter.Exporter { | |
|
||
log.Debugf("Compatible mode: %v", opts.CompatibleMode) | ||
|
||
if strings.HasPrefix(opts.URI, "mongodb") { | ||
// trim mongodb:// prefix to add user and pass | ||
// IF user@pass not contained in uri AND custom user and pass supplied in arguments | ||
// DO concat a new uri with user and pass arguments value | ||
if !strings.Contains(opts.URI, "@") && opts.User != "" && opts.Password != "" { | ||
// trim mongodb:// prefix to handle user and pass logic | ||
opts.URI = strings.TrimPrefix(opts.URI, "mongodb://") | ||
} | ||
|
||
if !strings.Contains(opts.URI, "@") { | ||
log.Debugf("add user and pass to the uri") | ||
if !strings.HasPrefix(opts.URI, "mongodb") { | ||
opts.URI = fmt.Sprintf("mongodb://%s:%s@%s", opts.User, opts.Password, opts.URI) | ||
} | ||
opts.URI = fmt.Sprintf("%s:%s@%s", opts.User, opts.Password, opts.URI) | ||
|
||
// add back mongodb:// | ||
opts.URI = "mongodb://" + opts.URI | ||
} | ||
|
||
log.Debugf("Connection URI: %s", opts.URI) | ||
|