daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jun 12th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env perl6
  2.  
  3. #use MONKEY-SEE-NO-EVAL;
  4. #use Grammar::Tracer;
  5.  
  6. grammar FastlyLine {
  7.     rule TOP {
  8.         ^^ <date> <ip> <request> <status> <length> $$
  9.     }
  10.  
  11.     token date    { \S+ }
  12.     token ip      { \S+ }
  13.     token status  { \d+ }
  14.     token length  { \d+ | '"-"' }
  15.  
  16.     rule  request { '"' <method> <uri> <version> '"' }
  17.     token method  { \w+ }
  18.     token uri     { \S+ }
  19.     token version { <-[ " ]>+ }
  20. }
  21. class LogLine {
  22.    has DateTime $.date;
  23.    has $.ip;
  24.    has $.method;
  25.    has $.uri;
  26.    has $.status;
  27.    has $.length;
  28.    has $.version;
  29. }
  30. class FastlyAction {
  31.    method TOP($/)    {
  32.        make LogLine.new(
  33.            date    => $/<date>.made,
  34.            ip      => $/<ip>.Str,
  35.            status  => $/<status>.Int,
  36.            method  => $/<request><method>.Str,
  37.            uri     => $/<request><uri>.Str,
  38.            version => $/<request><version>.Str,
  39.            length  => $/<length>.made,
  40.        );
  41.    }
  42.    method date($/)   { make DateTime.new($/.Str) }
  43.    method length($/) { make $/.Str eq '"-"' ?? 0 !! $/.Int }
  44. }
  45.  
  46. sub MAIN(Str:D :$q) {
  47.    for $*IN.lines -> $l {
  48.        my $x = FastlyLine.parse($l, actions => FastlyAction);
  49.        if ($x) {
  50.            $_ = $x.made;
  51.        } else {
  52.            say "ERROR in parsing: $l";
  53.            next;
  54.        }
  55. #       EVAL($q);
  56.        .say if .status == 503 && .uri ~~ /^^ '/tmol-dstl.js' /
  57.    }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top