Skip to content
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This CHANGELOG follows the format located [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)

## [Unreleased]
### Breaking Changes
- `--connect` now defaults to `:direct` so that Server status/Replicaset stats are current host's rather than all metrics in the replica set (@naemon)

### Added
- exposed `--connect` which controls how it connects. Valid values are `:direct`, `:replica_set` (mongo client default), and `:sharded`. (@naemon) (@majormoses)

## [2.1.0] - 2018-12-27
### Added
Expand Down
7 changes: 7 additions & 0 deletions bin/metrics-mongodb-replication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ class MongoDB < Sensu::Plugin::Metric::CLI::Graphite
long: '--debug',
default: false

option :connect,
description: 'The connection method to use',
long: `--connect`,
in: %i(direct replica_set sharded),
proc: proc(&:to_sym),
default: :direct

def get_mongo_doc(command)
rs = @db.command(command)
unless rs.successful?
Expand Down
7 changes: 7 additions & 0 deletions bin/metrics-mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class MongoDB < Sensu::Plugin::Metric::CLI::Graphite
long: '--require-master',
default: false

option :connect,
description: 'The connection method to use',
long: `--connect`,
in: %i(direct replica_set sharded),
proc: proc(&:to_sym),
default: :direct

option :exclude_db_sizes,
description: 'Exclude database sizes',
long: '--exclude-db-sizes',
Expand Down
2 changes: 2 additions & 0 deletions lib/sensu-plugins-mongodb/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,15 @@ def get_mongo_client(db_name)
ssl_key = @config[:ssl_key]
ssl_ca_cert = @config[:ssl_ca_cert]
ssl_verify = @config[:ssl_verify]
connect = @config[:connect]

if Gem.loaded_specs['mongo'].version < Gem::Version.new('2.0.0')
MongoClient.new(host, port)
else
address_str = "#{host}:#{port}"
client_opts = {}
client_opts[:database] = db_name
client_opts[:connect] = connect
unless db_user.nil?
client_opts[:user] = db_user
client_opts[:password] = db_password
Expand Down