Exemplo n.º 1
0
 public function testFormat()
 {
     $parser = new LogParser("%h %l %u %t \"%r\" %>s %O");
     $entry = $parser->parse('177.3.137.13 - - [11/Sep/2013:22:46:30 +0000] "GET / HTTP/1.1" 200 9726');
     $this->assertEquals('177.3.137.13', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('11/Sep/2013:22:46:30 +0000', $entry->time);
     $this->assertEquals('GET / HTTP/1.1', $entry->request);
     $this->assertEquals('200', $entry->status);
     $this->assertEquals('9726', $entry->sentBytes);
     $entry = $parser->parse('177.3.137.13 - - [11/Sep/2013:22:46:36 +0000] "GET /media/css/fe0e1ba295680ef4c59ccc987fca2371.css HTTP/1.1" 200 36861');
     $this->assertEquals('177.3.137.13', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('11/Sep/2013:22:46:36 +0000', $entry->time);
     $this->assertEquals('GET /media/css/fe0e1ba295680ef4c59ccc987fca2371.css HTTP/1.1', $entry->request);
     $this->assertEquals('200', $entry->status);
     $this->assertEquals('36861', $entry->sentBytes);
     $entry = $parser->parse('66.249.66.207 - - [11/Sep/2013:22:46:47 +0000] "GET /robots.txt HTTP/1.1" 503 1041');
     $this->assertEquals('66.249.66.207', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('11/Sep/2013:22:46:47 +0000', $entry->time);
     $this->assertEquals('GET /robots.txt HTTP/1.1', $entry->request);
     $this->assertEquals('503', $entry->status);
     $this->assertEquals('1041', $entry->sentBytes);
 }
Exemplo n.º 2
0
 public function testFormat()
 {
     $parser = new LogParser("%{User-agent}i");
     $entry = $parser->parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36');
     $this->assertEquals('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36', $entry->HeaderUseragent);
     $entry = $parser->parse('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');
     $this->assertEquals('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', $entry->HeaderUseragent);
 }
Exemplo n.º 3
0
 public function testFormat()
 {
     $parser = new LogParser("%{Referer}i -> %U");
     $entry = $parser->parse('- -> /index.php');
     $this->assertEquals('/index.php', $entry->URL);
     $this->assertEquals('-', $entry->HeaderReferer);
     $entry = $parser->parse('http://ecommerce.dev/ -> /media/css/fe0e1ba295680ef4c59ccc987fca2371.css');
     $this->assertEquals('/media/css/fe0e1ba295680ef4c59ccc987fca2371.css', $entry->URL);
     $this->assertEquals('http://ecommerce.dev/', $entry->HeaderReferer);
     $entry = $parser->parse('- -> /robots.txt');
     $this->assertEquals('/robots.txt', $entry->URL);
     $this->assertEquals('-', $entry->HeaderReferer);
 }
Exemplo n.º 4
0
 public function testCombinedFormat()
 {
     $parser = new LogParser("%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"");
     $entry = $parser->parse('66.249.74.132 - - [10/Sep/2013:15:50:06 +0000] "GET /electronics/cameras/accessories/universal-camera-charger HTTP/1.1" 200 12347 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"');
     $this->assertEquals('66.249.74.132', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('10/Sep/2013:15:50:06 +0000', $entry->time);
     $this->assertEquals('GET /electronics/cameras/accessories/universal-camera-charger HTTP/1.1', $entry->request);
     $this->assertEquals('200', $entry->status);
     $this->assertEquals('12347', $entry->sentBytes);
     $this->assertEquals('-', $entry->HeaderReferer);
     $this->assertEquals('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', $entry->HeaderUserAgent);
 }
Exemplo n.º 5
0
 public function testReferersAndAgents()
 {
     $parser = new LogParser("%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"");
     $entry = $parser->parse('www.example.com:80 ::1 - - [27/Oct/2013:06:27:33 +0000] "OPTIONS * HTTP/1.0" 200 126 "-" "Apache/2.2.22 (Ubuntu) (internal dummy connection)"');
     $this->assertEquals('www.example.com', $entry->serverName);
     $this->assertEquals('80', $entry->port);
     $this->assertEquals('::1', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('27/Oct/2013:06:27:33 +0000', $entry->time);
     $this->assertEquals('OPTIONS * HTTP/1.0', $entry->request);
     $this->assertEquals('200', $entry->status);
     $this->assertEquals('126', $entry->sentBytes);
     $this->assertEquals('-', $entry->HeaderReferer);
     $this->assertEquals('Apache/2.2.22 (Ubuntu) (internal dummy connection)', $entry->HeaderUserAgent);
 }
Exemplo n.º 6
0
 /**
  * VarnishParser constructor. Initializes the parser and adds some custom format parsers
  */
 public function __construct()
 {
     parent::__construct();
     $this->addPattern('%m', '(?P<requestMethod>OPTIONS|GET|HEAD|POST|PUT|PURGE|DELETE|TRACE|CONNECT)');
     $this->addPattern('%r', '(?P<request>(.+?))');
     $this->addPattern('%>u', '(?P<userAgent>.+?)');
     $this->addPattern('%R', '(?P<referrer>.+?)');
     $this->addPattern('%P', '(?P<requestProtocol>HTTP/1.(?:0|1))');
     $this->setFormat('%a %l %b %t "%m %r %P" %>s %O "%R" "%>u"');
 }
Exemplo n.º 7
0
 public function testFormat()
 {
     $parser = new LogParser("%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"");
     $entry = $parser->parse('ecommerce.dev:80 177.3.137.13 - - [11/Sep/2013:22:46:30 +0000] "GET / HTTP/1.1" 200 9726 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"');
     $this->assertEquals('ecommerce.dev', $entry->serverName);
     $this->assertEquals('80', $entry->port);
     $this->assertEquals('177.3.137.13', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('11/Sep/2013:22:46:30 +0000', $entry->time);
     $this->assertEquals('GET / HTTP/1.1', $entry->request);
     $this->assertEquals('200', $entry->status);
     $this->assertEquals('9726', $entry->sentBytes);
     $this->assertEquals('-', $entry->HeaderReferer);
     $this->assertEquals('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36', $entry->HeaderUserAgent);
     $entry = $parser->parse('ecommerce.dev:80 177.3.137.13 - - [11/Sep/2013:22:46:36 +0000] "GET /media/css/fe0e1ba295680ef4c59ccc987fca2371.css HTTP/1.1" 200 36861 "http://ecommerce.dev/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36"');
     $this->assertEquals('ecommerce.dev', $entry->serverName);
     $this->assertEquals('80', $entry->port);
     $this->assertEquals('177.3.137.13', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('11/Sep/2013:22:46:36 +0000', $entry->time);
     $this->assertEquals('GET /media/css/fe0e1ba295680ef4c59ccc987fca2371.css HTTP/1.1', $entry->request);
     $this->assertEquals('200', $entry->status);
     $this->assertEquals('36861', $entry->sentBytes);
     $this->assertEquals('http://ecommerce.dev/', $entry->HeaderReferer);
     $this->assertEquals('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36', $entry->HeaderUserAgent);
     $entry = $parser->parse('ecommerce.dev:80 66.249.66.207 - - [11/Sep/2013:22:46:47 +0000] "GET /robots.txt HTTP/1.1" 503 1041 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"');
     $this->assertEquals('ecommerce.dev', $entry->serverName);
     $this->assertEquals('80', $entry->port);
     $this->assertEquals('66.249.66.207', $entry->host);
     $this->assertEquals('-', $entry->logname);
     $this->assertEquals('-', $entry->user);
     $this->assertEquals('11/Sep/2013:22:46:47 +0000', $entry->time);
     $this->assertEquals('GET /robots.txt HTTP/1.1', $entry->request);
     $this->assertEquals('503', $entry->status);
     $this->assertEquals('1041', $entry->sentBytes);
     $this->assertEquals('-', $entry->HeaderReferer);
     $this->assertEquals('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', $entry->HeaderUserAgent);
 }
Exemplo n.º 8
0
 /**
  * @param LogParser $parser
  */
 private function setParser($parser)
 {
     // TODO set format as dependency
     $parser->setFormat('%h %l %u %t "%r" %>s %b');
     $this->parser = $parser;
 }