Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env perl6
- #use MONKEY-SEE-NO-EVAL;
- #use Grammar::Tracer;
- grammar FastlyLine {
- rule TOP {
- ^^ <date> <ip> <request> <status> <length> $$
- }
- token date { \S+ }
- token ip { \S+ }
- token status { \d+ }
- token length { \d+ | '"-"' }
- rule request { '"' <method> <uri> <version> '"' }
- token method { \w+ }
- token uri { \S+ }
- token version { <-[ " ]>+ }
- }
- class LogLine {
- has DateTime $.date;
- has $.ip;
- has $.method;
- has $.uri;
- has $.status;
- has $.length;
- has $.version;
- }
- class FastlyAction {
- method TOP($/) {
- make LogLine.new(
- date => $/<date>.made,
- ip => $/<ip>.Str,
- status => $/<status>.Int,
- method => $/<request><method>.Str,
- uri => $/<request><uri>.Str,
- version => $/<request><version>.Str,
- length => $/<length>.made,
- );
- }
- method date($/) { make DateTime.new($/.Str) }
- method length($/) { make $/.Str eq '"-"' ?? 0 !! $/.Int }
- }
- sub MAIN(Str:D :$q) {
- for $*IN.lines -> $l {
- my $x = FastlyLine.parse($l, actions => FastlyAction);
- if ($x) {
- $_ = $x.made;
- } else {
- say "ERROR in parsing: $l";
- next;
- }
- # EVAL($q);
- .say if .status == 503 && .uri ~~ /^^ '/tmol-dstl.js' /
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment