-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathreplay_accesslog.pl
More file actions
executable file
·81 lines (60 loc) · 2.12 KB
/
replay_accesslog.pl
File metadata and controls
executable file
·81 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env perl
# expects access log in ~/logs
# walks it, looks for non 40x GETs with no auth, then curls them from localhost
# the idea is that a successful production request yesterday should not fail today
# REALLY GROSS AND INITITAL CHECKIN. sorry, yo.
# grab all relevant urls and stick them into a hash
my %urlset = {};
my @log = `cat ~/logs/access.log`;
my ($host, $url) = '';
my $exitstatus = 0;
# gross hack for initial key after fucking up the hash
my $i = -1;
foreach my $line (@log) {
@record=split(" ", $line);
#skip 40x, non-GETs, and shit that requires auth
next if ( $record[6] =~ /NONE\/40/ || $record[8] ne "GET" || $record[$#record] !~ /AUTH_NONE/ );
#regex out the host and uri, stick them into the urlset hash
$record[9] =~ /http:\/\/(.+?)\/(.+)$/;
$host = $1;
$uri = $2;
next unless ( $host && $uri );
#grab only http status
$record[6] =~ /(\d+)$/;
$status = $1;
$i++;
$urlset{$i} = {
host => $host,
uri => $uri,
status_now => undef,
status_sample => $status,
};
}
# lets not forkbomb
use Parallel::ForkManager;
my $pm = new Parallel::ForkManager(50);
# lets prep a table if we have any failures
use Text::Table;
my $tb = Text::Table->new(
"url", "status\nproduction yesterday", "status\nstaging today"
);
for ( my $x = 0; $x < keys ( %urlset ); $x++ ) {
$pm->start and next;
$url = "$urlset{$x}{'host'}/$urlset{$x}{'uri'}";
# curl that shit, record only the http return code
$urlset{$x}{'status_now'}=`curl -m 1 -s -H "Host:$urlset{$x}{'host'}" -w "%{http_code}" \'localhost:8820/$urlset{$x}{'uri'}\' -o /dev/null`;
if ( ( $urlset{$x}{'status_now'} != $urlset{$x}{'status_sample'} ) &&
( $urlset{$x}{'status_now'} !~ /^(40|0|3)/ && $urlset{$x}{'status_sample'} =~ /^2/ ) ){
# push this guy to our table. ensure we exit non-0
print "$url went from $urlset{$x}{'status_sample'} to $urlset{$x}{'status_now'}\n";
$tb -> load (
[ $url, $urlset{$x}{'status_sample'}, $urlset{$x}{'status_now'} ],
);
$exitstatus = 1;
}
$pm->finish;
}
if ($exitstatus != 0) {
print $tb;
}
exit $exitstatus;