Asterisk full log parser
I want to make a log parser for for an Asterisk PBX, but don't know where to start.
I figured it out what i need from the log. the lines that i need look like this:
[Apr 12 11:11:56] VERBOSE[3359] logger.c: -- Called 111
the number in VERBOSE[....] are the same for 1 call.
The first thing that i have 开发者_Python百科to do is get the lines that contain that VERBOSE number so i can identify that call. the second thing is to read the text, there are some standard texts so it won't be hard to recognize.
The thing is that i would like to read it real time (the file is written real time), and display it in a webpage. PHP or Ajax.
The thing that i want to do is, show up rows in a webpage as users call. and the new call to be added under the current/answered call.
Any tips, examples would be great.
Thanks, Sebastian
I would do it in 2 programs that can work as simple CGI programs.
First program parses log and show date and call identifier. Such identifier will be link to 2nd program. In Python you can use regexp:
# 1st group - date, 2nd - callid RX_VERBOSE = re.compile(r'(.*) VERBOSE\[(\d+)\] ') def make_link(call_id): return(' <a href="show_call.cgi?call_id=%d>%d</a>' % (call_id, call_id)) def show_calls(logfn): call_ids = [] f = open(logfn) for line in f: rx = RX_VERBOSE.search(line) if rx: call_id = int(rx.group(2)) if not call_id in call_ids: print('%s %s' % (rx.group(1), make_link(call_id))) call_ids.append(call_id) f.close()
This program will show the lines that has call identifier:
def show_call_datails(logfn, call_id): search_str = ' VERBOSE[%s] ' % call_id f = open(logfn) for line in f: if search_str in line: print(line.rstrip()) f.close()
精彩评论