Skip to content

Commit

Permalink
Update monitor and parsers for new client
Browse files Browse the repository at this point in the history
They were still using the old LogEntry method of
adding records to Cassandra.
  • Loading branch information
thobbs committed Jun 11, 2011
1 parent e4637a2 commit a38f3bf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
13 changes: 8 additions & 5 deletions logsandra/monitor/monitor.py
Expand Up @@ -10,28 +10,31 @@
# Local imports
from logsandra.monitor.watchers import Watcher
from logsandra.monitor.parsers.clf import ClfParser
from logsandra.model import CassandraClient, LogEntry
from logsandra.model.client import CassandraClient


class Monitor(object):

def __init__(self, settings, tail=False):
self.logger = logging.getLogger('logsandra.monitord')
self.settings = settings
self.client = CassandraClient(self.settings['ident'], self.settings['cassandra_address'], self.settings['cassandra_port'], self.settings['cassandra_timeout'])
self.client = CassandraClient(settings['ident'], settings['cassandra_address'],
settings['cassandra_port'], settings['cassandra_timeout'])

self.tail = tail
self.seek_position = {}

self.parsers = {}
log_entry = LogEntry(self.client)
parsers_path = os.path.join(os.path.dirname(imp.find_module('logsandra/monitor/')[1]), 'parsers/')
parsers_files = [filename[:-3] for filename in os.listdir(parsers_path) if filename.endswith('.py') and not filename.startswith('__')]
parsers_files = []
for filename in os.listdir(parsers_path):
if filename.endswith('.py') and not filename.startswith('__'):
parsers_files.append(filename[:-3])
parsers_temp = __import__('logsandra.monitor.parsers', globals(), locals(), parsers_files, -1)
for filename in parsers_files:
module = getattr(parsers_temp, filename)
classname = '%sParser' % (filename.capitalize())
self.parsers[filename] = getattr(module, classname)(log_entry)
self.parsers[filename] = getattr(module, classname)(self.client)

def run(self):
self.logger.debug('Starting watcher')
Expand Down
4 changes: 2 additions & 2 deletions logsandra/monitor/parsers/__init__.py
@@ -1,4 +1,4 @@
class BaseParser(object):

def __init__(self, log_entries):
self.log_entries = log_entries
def __init__(self, client):
self.client = client
2 changes: 1 addition & 1 deletion logsandra/monitor/parsers/clf.py
Expand Up @@ -73,4 +73,4 @@ def parse(self, line, source, data):

date = dateutil.parser.parse(result['time'], fuzzy=True)

return self.log_entries.add(date=date, entry=line, source=source, keywords=keywords)
return self.client.add_log(date=date, entry=line, source=source, keywords=keywords)
3 changes: 1 addition & 2 deletions logsandra/monitor/parsers/syslog.py
Expand Up @@ -8,7 +8,6 @@ class SyslogParser(BaseParser):
def parse(self, line, source, data):
elements = line.split(' ')


date = ' '.join(elements[0:3])
date = dateutil.parser.parse(date, fuzzy=True)

Expand Down Expand Up @@ -36,4 +35,4 @@ def parse(self, line, source, data):
for c in content:
keywords.append(c)

return self.log_entries.add(date=date, entry=line, source=source, keywords=keywords)
return self.client.add_log(date=date, entry=line, source=source, keywords=keywords)
2 changes: 1 addition & 1 deletion logsandra/monitor/watchers/standard.py
Expand Up @@ -60,7 +60,7 @@ def _find_files_generator(self):
filename = os.path.abspath(os.path.expanduser(entity['path']))
yield filename, entity
else:
raise Error('Invalid path, cannot monitor it')
raise Exception('Invalid path, cannot monitor it')

def _rescan(self):
tempfiles = {}
Expand Down

0 comments on commit a38f3bf

Please sign in to comment.