Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SSL support #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import collectd
import ssl
from pymongo import MongoClient
from pymongo.read_preferences import ReadPreference
from distutils.version import LooseVersion as V
Expand All @@ -17,6 +18,7 @@ def __init__(self):
self.mongo_db = ["admin", ]
self.mongo_user = None
self.mongo_password = None
self.mongo_useSSL = False

self.lockTotalTime = None
self.lockTime = None
Expand All @@ -37,7 +39,10 @@ def submit(self, type, instance, value, db=None):
v.dispatch()

def get_db_and_collection_stats(self):
con = MongoClient(host=self.mongo_host, port=self.mongo_port, read_preference=ReadPreference.SECONDARY)
if self.mongo_useSSL:
con = MongoClient(host=self.mongo_host, port=self.mongo_port, read_preference=ReadPreference.SECONDARY, ssl=True, ssl_cert_reqs=ssl.CERT_NONE)
else:
con = MongoClient(host=self.mongo_host, port=self.mongo_port, read_preference=ReadPreference.SECONDARY)
db = con[self.mongo_db[0]]
if self.mongo_user and self.mongo_password:
db.authenticate(self.mongo_user, self.mongo_password)
Expand Down Expand Up @@ -138,6 +143,8 @@ def config(self, obj):
self.mongo_password = node.values[0]
elif node.key == 'Database':
self.mongo_db = node.values
elif node.key == 'UseSSL':
self.mongo_useSSL = node.values[0] == "True"
else:
collectd.warning("mongodb plugin: Unkown configuration key %s" % node.key)

Expand Down