Skip to content

Commit

Permalink
Add support for ssl connections in Mongo check
Browse files Browse the repository at this point in the history
Fix #848
  • Loading branch information
Remi Hakim committed Mar 6, 2014
1 parent d71cf96 commit 762d9d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion checks.d/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def check(self, instance):
return

server = instance['server']
use_ssl = instance.get('ssl', None)
ssl_keyfile = instance.get('ssl_keyfile', None)
ssl_certfile = instance.get('ssl_certfile', None)
ssl_cert_reqs = instance.get('ssl_cert_reqs', None)
ssl_ca_certs = instance.get('ssl_ca_certs', None)

tags = instance.get('tags', [])
tags.append('server:%s' % server)
# de-dupe tags to avoid a memory leak
Expand Down Expand Up @@ -178,7 +184,9 @@ def check(self, instance):
self.log.debug("Mongo: cannot extract username and password from config %s" % server)
do_auth = False

conn = Connection(server, network_timeout=DEFAULT_TIMEOUT)
conn = Connection(server, network_timeout=DEFAULT_TIMEOUT,
ssl=use_ssl, ssl_keyfile=ssl_keyfile, ssl_certfile=ssl_certfile,
ssl_cert_reqs=ssl_cert_reqs, ssl_ca_certs=ssl_ca_certs)
db = conn[db_name]
if do_auth:
if not db.authenticate(username, password):
Expand Down
11 changes: 10 additions & 1 deletion conf.d/mongo.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ instances:
# - server: mongodb://localhost:27017
# tags:
# - optional_tag1
# - optional_tag2
# - optional_tag2
#
# Optional SSL parameters, see https://github.com/mongodb/mongo-python-driver/blob/2.6.3/pymongo/mongo_client.py#L193-L212
# for more details
#
# ssl: False # Optional (default to False)
# ssl_keyfile: # Path to the private keyfile used to identify the local
# ssl_certfile: # Path to the certificate file used to identify the local connection against mongod.
# ssl_cert_reqs: # Specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided.
# ssl_ca_certs: # Path to the ca_certs file

0 comments on commit 762d9d5

Please sign in to comment.