|
Here is a quick and dirty python script I started writing some time ago.
It takes an asterisk log (/var/log/messages in my case) and save a different file for each call in asterisk log. It puts that files in 'logsdir' directory
It needs a lot of improvements, but it's a starting point
- It should save its status to a file to avoid parsing the whole file each time it's started
- It's actually based on asterisk pids, some files are not related to calls
- Files naming should be handled better (now the PID # is used)
#!/usr/bin/python
import re
import pickle
from sets import Set
switch = 1
logfile = '/var/log/messages'
logsdir = '/var/log/asterisk/calls/'
statusfile = '/etc/asteriskanalog.dat'
#Tune it with the average number of concurrent call of your sistem
maxfd = 10
f = open(logfile, 'r')
exp = re.compile("asterisk\[[0-9]+\]")
calls = Set([])
fdlist = {}
openfiles = []
for line in f:
m = exp.search(line)
if m:
callid = line[m.start()+9:m.end()-1]
calls.add(callid)
if callid not in openfiles:
if len(openfiles) >= maxfd:
fdlist[openfiles[0]].close()
openfiles.pop(0)
fdlist[callid] = open(logsdir+callid, 'a')
openfiles.append(callid)
fdlist[callid].write(line)
s = open(statusfile, 'w')
pickle.dump(calls, s)
s.close()
