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

Refactor for library use #1

Merged
merged 2 commits into from
Oct 13, 2011
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# Override the generic daemon class to run our checks
class agent(Daemon):

def run(self):
def run(self, agentConfig=None, run_forever=True):
agentLogger = logging.getLogger('agent')

agentLogger.debug('Collecting basic system stats')
Expand All @@ -46,7 +46,10 @@ def run(self):

agentLogger.debug('Creating checks instance')

agentConfig, rawConfig = get_config()
if agentConfig is None:
agentConfig, rawConfig = get_config()
else:
rawConfig = {}
emitter = http_emitter

# Checks instance
Expand All @@ -56,7 +59,8 @@ def run(self):
agentLogger.debug('Scheduling checks every ' + str(agentConfig['checkFreq']) + ' seconds')
s = sched.scheduler(time.time, time.sleep)
c.doChecks(s, True, systemStats) # start immediately (case 28315)
s.run()
if run_forever:
s.run()

def setupLogging(agentConfig):
"""Used by ddagent.py as well"""
Expand Down
23 changes: 13 additions & 10 deletions checks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@

from resources.processes import Processes as ResProcesses

def getUuid():
# Generate a unique name that will stay constant between
# invocations, such as platform.node() + uuid.getnode()
# Use uuid5, which does not depend on the clock and is
# recommended over uuid3.
# This is important to be able to identify a server even if
# its drives have been wiped clean.
# Note that this is not foolproof but we can reconcile servers
# on the back-end if need be, based on mac addresses.
return uuid.uuid5(uuid.NAMESPACE_DNS, platform.node() + str(uuid.getnode())).hex

def recordsize(func):
"Record the size of the response"
def wrapper(*args, **kwargs):
Expand Down Expand Up @@ -102,7 +113,7 @@ def __init__(self, agentConfig, rawConfig, emitter):

self._event_checks = [Hudson(), Nagios(socket.gethostname())]
self._resources_checks = [ResProcesses(self.checksLogger,self.agentConfig)]

#
# Checks - FIXME migrating to the new Check interface is a WIP
#
Expand Down Expand Up @@ -334,15 +345,7 @@ def _doChecks(self, firstRun, systemStats=False):
except socket.error:
self.checksLogger.exception('Unable to get hostname')

# Generate a unique name that will stay constant between
# invocations, such as platform.node() + uuid.getnode()
# Use uuid5, which does not depend on the clock and is
# recommended over uuid3.
# This is important to be able to identify a server even if
# its drives have been wiped clean.
# Note that this is not foolproof but we can reconcile servers
# on the back-end if need be, based on mac addresses.
checksData['uuid'] = uuid.uuid5(uuid.NAMESPACE_DNS, platform.node() + str(uuid.getnode())).hex
checksData['uuid'] = getUuid()
self.checksLogger.debug('doChecks: added uuid %s' % checksData['uuid'])

# Process the event checks.
Expand Down