def testCombinedExample(self):
     # test the combined example from apache.org
     combined_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] '\
     '"GET /apache_pb.gif HTTP/1.0" 200 2326 '\
     '"http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
     self.assertEqual(apache_log_parser_regex.dictify_logline(combined_log_entry), 
         {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})
Example #2
0
 def testCombinedExample(self):
     # test the combined example from apache.org
     combined_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] ' \
                          '"GET /apache_pb.gif HTTP/1.0" 200 2326 ' \
                          '"http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
     self.assertEqual(apache_log_parser_regex.dictify_logline(combined_log_entry),
                      {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})
 def testCommonExample(self):
     # test the common example from apache.org
     common_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] '\
                         '"GET /apache_pb.gif HTTP/1.0" 200 2326'
     self.assertEqual(apache_log_parser_regex.dictify_logline(common_log_entry),
                                 {'remote_host': '127.0.0.1',
                                     'status': '200', 'bytes_sent':
                                     '2326'})
Example #4
0
def get_log_dict(logline):
    l = dictify_logline(logline)
    try:
        l['bytes_sent'] = int(l['bytes_sent'])
    except ValueError:
        bytes_sent = 0
    l['logline'] = logline
    return l
Example #5
0
File: views.py Project: 7rack/py4sa
def get_log_dict(logline):
    l = dictify_logline(logline)
    try:
        l['bytes_sent'] = int(l['bytes_sent'])
    except ValueError:
        bytes_sent = 0
    l['logline'] = logline
    return l
Example #6
0
 def testMalformed(self):
     combined_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700]' \
                          ' "GET /apache_pb.gif/with white space.html HTTP/1.0" 200 2326'
     self.assertEqual(
         apache_log_parser_regex.dictify_logline(combined_log_entry), {
             'remote_host': '127.0.0.1',
             'status_code': '200',
             'bytes_sent': '2326'
         })
Example #7
0
 def load_loglines(self):
     self.loglines = []
     logfile = open(self.logfile, 'r')
     for i, line in enumerate(logfile):
         line_dict = dictify_logline(line)
         self.loglines.append((i + 1, line_dict['remote_host'], 
             line_dict['status'], int(line_dict['bytes_sent']), line.rstrip()))
     logfile.close()
     self.draw_loglines()
Example #8
0
 def testMalformedEntry(self):
     # test a malformed modification dereived from the example at apache.org
     #malformed_log_entry = '127.0.0.1 - frank [10/Oct/2000 13:55:36 -0700] '\
     #'"GET /apache_pb.gif HTTP/1.0" 200 2326 '\
     #'"http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
     malformed_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] '\
                           '"GET /some/url/with white space.html HTTP/1.0" 200 2326'
     self.assertEqual(apache_log_parser_regex.dictify_logline(malformed_log_entry),
                      {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})
Example #9
0
 def load_loglines(self):
     self.loglines = []
     logfile = open(self.logfile, 'r')
     for i, line in enumerate(logfile):
         line_dict = dictify_logline(line)
         self.loglines.append(
             (i + 1, line_dict['remote_host'], line_dict['status'],
              int(line_dict['bytes_sent']), line.rstrip()))
     logfile.close()
     self.draw_loglines()
Example #10
0
 def testCommonExample(self):
     # test the common example from apache.org
     common_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] '\
     '"GET /apache_pb.gif HTTP/1.0" 200 2326'
     self.assertEqual(
         apache_log_parser_regex.dictify_logline(common_log_entry), {
             'remote_host': '127.0.0.1',
             'status': '200',
             'bytes_sent': '2326'
         })
Example #11
0
    def testMalformedEntry(self):
        # test a malformed modification dereived from the example at apache.org
        #malformed_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] '\
        #        '"GET /apache_pb.gif HTTP/1.0" 200 2326 '\
        #        '"http://www.example.com/start.html" \
        #        "Mozilla/4.08 [en] (Win98; I; Nav)"'

        malformed_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] '\
                '"GET /some/url/with white space.html HTTP/1.0" 200 2326 '
        self.assertEqual(apache_log_parser_regex.dictify_logline(malformed_log_entry), {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})
            def load_logfile(self, widget, data=None):
                """load logfile data into tree view"""
                
                filename = widget.get_filename()
                print "FILE-->", filename self.file_chooser.hide()
                self.loglines_store.clear()
                logfile = open(filename, 'r')
                for i, line in enumerate(logfile): line_dict = dictify_logline(line)

                self.loglines_store.append([i + 1, line_dict['remote_host'], line_dict['status'], int(line_dict['bytes_sent']), line])
                logfile.close()
Example #13
0
 def load_logfile(self, widget, data=None):
     """load logfile data into tree view"""
     filename = widget.get_filename()
     print "FILE-->", filename
     self.file_chooser.hide()
     self.loglines_store.clear()
     logfile = open(filename, 'r')
     for i, line in enumerate(logfile):
         line_dict = dictify_logline(line)
         self.loglines_store.append([i + 1, line_dict['remote_host'],
             line_dict['status'], int(line_dict['bytes_sent']), line])
     logfile.close()
Example #14
0
#!/usr/bin/python2
# -*- coding:utf-8 -*-

import shelve
import apache_log_parser_regex

logfile = open('access.log', 'r')
shelve_file = shelve.open('access.s')

for line in logfile:
    d_line = apache_log_parser_regex.dictify_logline(line)
    shelve_file[d_line['remote_host']] = \
            shelve_file.setdefault(d_line['remote_host'], 0) \
            + int(d_line['bytes_sent'])

logfile.close()
shelve_file.close()
 def testMalformed(self):
     # test for malformed example
     common_log_entry = '127.0.0.1         -     frank [10/Oct/2000:13:55:36 -0700] '\
             '"GET /some/url/with white space.html HTTP/1.0" 200 2326'
     self.assertEqual(apache_log_parser_regex.dictify_logline(common_log_entry),
             {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})
Example #16
0
 def testMalformedExample(self):
     malformed_log_entry = '127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] ' \
                           '"GET /some/url/with white space.html HTTP/1.0" 200 2326'
     self.assertEqual(apache_log_parser_regex.dictify_logline(malformed_log_entry),
                      {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})
#!/usr/bin/python

import shelve
import apache_log_parser_regex

logfile = open('access.log', 'r')
shelve_file = shelve.open('access.s')

for line in logfile:
    d_line = apache_log_parser_regex.dictify_logline(line)
    shelve_file[d_line['remote_host']] = \
        shelve_file.setdefault(d_line['remote_host'], 0) + \
        int(d_line['bytes_sent'])

logfile.close()
shelve_file.close()
 def testExtraWhitespace(self):
     # test for extra white space between fields
     common_log_entry = '127.0.0.1         -     frank [10/Oct/2000:13:55:36 -0700] '\
             '"GET /apache_pb.gif HTTP/1.0" 200 2326'
     self.assertEqual(apache_log_parser_regex.dictify_logline(common_log_entry),
             {'remote_host': '127.0.0.1', 'status': '200', 'bytes_sent': '2326'})