* 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
This commit is contained in:
desaster
2010-06-11 04:59:52 +00:00
parent 97908aad25
commit b88af200e8
3 changed files with 11 additions and 8 deletions

View File

@@ -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`)
) ;

View File

@@ -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

View File

@@ -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)