From b88af200e8c3cbe5bf7d459286701e020aa839fd Mon Sep 17 00:00:00 2001 From: desaster Date: Fri, 11 Jun 2010 04:59:52 +0000 Subject: [PATCH] * Fix some dblog brokenness * Set the ttylog column for mysql to "MEDIUMBLOB" * Limit the ttylog size written to the database to 10 Megabytes git-svn-id: https://kippo.googlecode.com/svn/trunk@121 951d7100-d841-11de-b865-b3884708a8e2 --- doc/sql/mysql.sql | 2 +- kippo/core/dblog.py | 10 +++++++++- kippo/dblog/mysql.py | 7 +------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/doc/sql/mysql.sql b/doc/sql/mysql.sql index ea35054..c314619 100644 --- a/doc/sql/mysql.sql +++ b/doc/sql/mysql.sql @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS `session` ( `endtime` datetime default NULL, `sensor` varchar(50) NOT NULL, `ip` varchar(15) NOT NULL default '', - `ttylog` blob, + `ttylog` mediumblob, PRIMARY KEY (`id`), KEY `starttime` (`starttime`,`sensor`) ) ; diff --git a/kippo/core/dblog.py b/kippo/core/dblog.py index 62e24bc..28b364c 100644 --- a/kippo/core/dblog.py +++ b/kippo/core/dblog.py @@ -43,7 +43,7 @@ class DBLogger(object): return matches.groups()[0] def emit(self, ev): - if ev['system'] == '-': + if ev['system'] == '-' or not len(ev['message']): return match = self.re_unique.match(ev['system']) if not match: @@ -69,6 +69,14 @@ class DBLogger(object): for i in [x for x in self.sessions if self.sessions[x] == session]: del self.sessions[i] + def ttylog(self, session): + ttylog = None + if session in self.ttylogs: + f = file(self.ttylogs[session]) + ttylog = f.read(10485760) + f.close() + return ttylog + # We have to return an unique ID def createSession(self, ip): return 0 diff --git a/kippo/dblog/mysql.py b/kippo/dblog/mysql.py index b5dae13..f7c9a76 100644 --- a/kippo/dblog/mysql.py +++ b/kippo/dblog/mysql.py @@ -19,14 +19,9 @@ class DBLogger(dblog.DBLogger): return int(cursor.lastrowid) def handleConnectionLost(self, session, args): - ttylog = None - if session in self.ttylogs: - f = file(self.ttylogs[session]) - ttylog = f.read() - f.close() sql = 'UPDATE `session` SET `endtime` = FROM_UNIXTIME(%s)' + \ ', `ttylog` = %s WHERE `id` = %s' - params = (self.nowUnix(), ttylog, session) + params = (self.nowUnix(), self.ttylog(session), session) cursor = self.db.cursor() cursor.execute(sql, params)