Ejemplo n.º 1
0
 def test_issue9(self):
     parser = apache_log_parser.Parser(
         "%h %v %V %l %u %t %r %>s %b %{Referer}i %{User-agent}i")
     log = "10.1.1.1 T1 blah.foo.com - - [08/Mar/2015:18:06:58 -0400] GET /content_images/3/American-University-in-Cairo-AUC.jpeg.jpg HTTP/1.1 404 344 http://www.google.ie AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36"
     data = parser.parse(log)
     self.assertEqual(
         data, {
             'status':
             '404',
             'request_header_referer':
             'http://www.google.ie',
             'remote_user':
             '******',
             'server_name':
             'T1',
             'request_http_ver':
             '1.1',
             'request_header_user_agent':
             'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36',
             'request_first_line':
             'GET /content_images/3/American-University-in-Cairo-AUC.jpeg.jpg HTTP/1.1',
             'remote_logname':
             '-',
             'request_method':
             'GET',
             'response_bytes_clf':
             '344',
             'server_name2':
             'blah.foo.com',
             'request_url':
             '/content_images/3/American-University-in-Cairo-AUC.jpeg.jpg',
             'remote_host':
             '10.1.1.1',
             'time_received':
             '[08/Mar/2015:18:06:58 -0400]',
             'time_received_datetimeobj':
             datetime.datetime(2015, 3, 8, 18, 6, 58),
             'time_received_isoformat':
             '2015-03-08T18:06:58',
             'time_received_tz_datetimeobj':
             datetime.datetime(
                 2015,
                 3,
                 8,
                 18,
                 6,
                 58,
                 tzinfo=apache_log_parser.FixedOffset('-0400')),
             'time_received_tz_isoformat':
             '2015-03-08T18:06:58-04:00',
             'time_received_utc_datetimeobj':
             datetime.datetime(
                 2015,
                 3,
                 8,
                 22,
                 6,
                 58,
                 tzinfo=apache_log_parser.FixedOffset('0000')),
             'time_received_utc_isoformat':
             '2015-03-08T22:06:58+00:00',
         })
Ejemplo n.º 2
0
    def test_pr8(self):
        parser = apache_log_parser.make_parser(
            '%h %{remote}p %v %{local}p %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %P %D %{number}n %{SSL_PROTOCOL}x %{SSL_CIPHER}x %k %{UNIQUE_ID}e '
        )
        data = parser(
            '127.0.0.1 50153 mysite.co.uk 443 [28/Nov/2014:10:03:40 +0000] "GET /mypage/this/that?stuff=all HTTP/1.1" 200 5129 "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36" 18572 363701 0 TLSv1.01 MY-CYPHER 0 VHhIfKwQGCMAAEiMUIAAAAF '
        )
        self.assertEqual(
            data, {
                'status':
                '200',
                'extension_ssl_protocol':
                'TLSv1.01',
                'request_header_user_agent__browser__family':
                'Chrome',
                'time_us':
                '363701',
                'num_keepalives':
                '0',
                'request_first_line':
                'GET /mypage/this/that?stuff=all HTTP/1.1',
                'pid':
                '18572',
                'response_bytes_clf':
                '5129',
                'request_header_user_agent__os__family':
                u'Windows',
                'request_url':
                '/mypage/this/that?stuff=all',
                'request_http_ver':
                '1.1',
                'request_header_referer':
                '-',
                'server_name':
                'mysite.co.uk',
                'request_header_user_agent__is_mobile':
                False,
                'request_header_user_agent__browser__version_string':
                '37.0.2062',
                'request_header_user_agent':
                'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
                'note_number':
                '0',
                'request_header_user_agent__os__version_string':
                '7',
                'server_port_local':
                '443',
                'request_method':
                'GET',
                'server_port_remote':
                '50153',
                'env_unique_id':
                'VHhIfKwQGCMAAEiMUIAAAAF',
                'time_received_datetimeobj':
                datetime.datetime(2014, 11, 28, 10, 3, 40),
                'time_received_isoformat':
                '2014-11-28T10:03:40',
                'remote_host':
                '127.0.0.1',
                'time_received':
                '[28/Nov/2014:10:03:40 +0000]',
                'time_received_tz_datetimeobj':
                datetime.datetime(
                    2014,
                    11,
                    28,
                    10,
                    3,
                    40,
                    tzinfo=apache_log_parser.FixedOffset("0000")),
                'time_received_tz_isoformat':
                '2014-11-28T10:03:40+00:00',
                'remote_host':
                '127.0.0.1',
                'time_received_utc_datetimeobj':
                datetime.datetime(
                    2014,
                    11,
                    28,
                    10,
                    3,
                    40,
                    tzinfo=apache_log_parser.FixedOffset("0000")),
                'time_received_utc_isoformat':
                '2014-11-28T10:03:40+00:00',
                'remote_host':
                '127.0.0.1',
                'extension_ssl_cipher':
                'MY-CYPHER',
            })

        parser = apache_log_parser.make_parser(
            '%A %V %p %P %a \"%r\" \"%{main_call}n\" %{some_time}t %b %>s %D %{UNIQUE_ID}e '
        )
        data = parser(
            '127.0.0.1 othersite 80 25572 192.168.1.100 "GET /Class/method/ HTTP/1.1" "-" 20141128155031 2266 200 10991 VHiZx6wQGCMAAEiBE8kAAAAA:VHiZx6wQGiMAAGPkBnMAAAAH:VHiZx6wQGiMAAGPkBnMAAAAH '
        )
        self.assertEqual(
            data, {
                'status': '200',
                'note_main_call': '-',
                'time_some_time': '20141128155031',
                'time_us': '10991',
                'request_http_ver': '1.1',
                'local_ip': '127.0.0.1',
                'pid': '25572',
                'request_first_line': 'GET /Class/method/ HTTP/1.1',
                'request_method': 'GET',
                'server_port': '80',
                'response_bytes_clf': '2266',
                'server_name2': 'othersite',
                'request_url': '/Class/method/',
                'env_unique_id':
                'VHiZx6wQGCMAAEiBE8kAAAAA:VHiZx6wQGiMAAGPkBnMAAAAH:VHiZx6wQGiMAAGPkBnMAAAAH',
                'remote_ip': '192.168.1.100'
            })
Ejemplo n.º 3
0
    def test_timezone_issue(self):
        parser = apache_log_parser.Parser("%t")
        log = "[08/Mar/2015:18:06:58 -0435]"
        data = parser.parse(log)
        self.assertEqual(data, {
            'time_received': '[08/Mar/2015:18:06:58 -0435]',
            'time_received_datetimeobj': datetime.datetime(2015, 3, 8, 18, 6, 58),
            'time_received_isoformat': '2015-03-08T18:06:58',
            'time_received_tz_datetimeobj': datetime.datetime(2015, 3, 8, 18, 6, 58, tzinfo=apache_log_parser.FixedOffset('-0435')),

            'time_received_tz_isoformat': '2015-03-08T18:06:58-04:35',
            'time_received_utc_datetimeobj': datetime.datetime(2015, 3, 8, 22, 41, 58, tzinfo=apache_log_parser.FixedOffset('0000')),
            'time_received_utc_isoformat': '2015-03-08T22:41:58+00:00',
        })