-
Notifications
You must be signed in to change notification settings - Fork 0
/
logsql.py
28 lines (26 loc) · 1.05 KB
/
logsql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""This is just a dead simple example of a custom output module you could
use to load your log lines into a database. Try using this by passing '--nolazy --output=logsql' to loghetti
if you don't pass --nolazy, then there's a chance that not all attributes of 'line' will be defined. """
COLUMNS = ('id', 'ip', 'ident', 'user', 'month', 'day',
'year', 'hour', 'method', 'url', 'http_version',
'referrer', 'user_agent',
# 'foo', 'bar',
)
COLUMNS_REPR = repr(COLUMNS)
def munge(line):
try:
vals = (' ', line.ip, line.ident, line.http_user,
line.month, line.day, line.year, line.hour,
line.http_method, line.url, line.http_vers, line.referrer,
line.user_agent,
#line.urldata['foo'][0], line.urldata['bar'][0],
)
except KeyError:
pass
else:
print ' '.join(["INSERT INTO sometable",
COLUMNS_REPR,
"VALUES",
repr(vals),
';',
])