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

[mongo] Clean password from state changed events #1789

Merged
merged 1 commit into from
Jul 27, 2015
Merged
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
22 changes: 10 additions & 12 deletions checks.d/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def __init__(self, name, init_config, agentConfig, instances=None):
def get_library_versions(self):
return {"pymongo": pymongo.version}

def check_last_state(self, state, server, agentConfig):
if self._last_state_by_server.get(server, -1) != state:
self._last_state_by_server[server] = state
return self.create_event(state, server, agentConfig)
def check_last_state(self, state, clean_server_name, agentConfig):
if self._last_state_by_server.get(clean_server_name, -1) != state:
self._last_state_by_server[clean_server_name] = state
return self.create_event(state, clean_server_name, agentConfig)

def create_event(self, state, server, agentConfig):
def create_event(self, state, clean_server_name, agentConfig):
"""Create an event with a message describing the replication
state of a mongo node"""

Expand Down Expand Up @@ -143,8 +143,8 @@ def get_state_description(state):

status = get_state_description(state)
hostname = get_hostname(agentConfig)
msg_title = "%s is %s" % (server, status)
msg = "MongoDB %s just reported as %s" % (server, status)
msg_title = "%s is %s" % (clean_server_name, status)
msg = "MongoDB %s just reported as %s" % (clean_server_name, status)

self.event({
'timestamp': int(time.time()),
Expand Down Expand Up @@ -181,12 +181,10 @@ def check(self, instance):
username = parsed.get('username')
password = parsed.get('password')
db_name = parsed.get('database')
clean_server_name = server.replace(password, "*" * 5) if password is not None else server

tags = instance.get('tags', [])
if password is not None:
tags.append('server:%s' % server.replace(password, "*" * 5))
else:
tags.append('server:%s' % server)
tags.append('server:%s' % clean_server_name)

# de-dupe tags to avoid a memory leak
tags = list(set(tags))
Expand Down Expand Up @@ -268,7 +266,7 @@ def check(self, instance):
data['health'] = current['health']

data['state'] = replSet['myState']
self.check_last_state(data['state'], server, self.agentConfig)
self.check_last_state(data['state'], clean_server_name, self.agentConfig)
status['replSet'] = data
except Exception, e:
if "OperationFailure" in repr(e) and "replSetGetStatus" in str(e):
Expand Down