| 1 |
package Resmon::Module::FRESHSVN; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use Resmon::ExtComm qw/cache_command/; |
|---|
| 4 |
use vars qw/@ISA/; |
|---|
| 5 |
@ISA = qw/Resmon::Module/; |
|---|
| 6 |
|
|---|
| 7 |
sub handler { |
|---|
| 8 |
my $arg = shift; |
|---|
| 9 |
my $os = $arg->fresh_status(); |
|---|
| 10 |
return $os if $os; |
|---|
| 11 |
my $dir = $arg->{'object'}; |
|---|
| 12 |
my $moutput = cache_command("/opt/omni/bin/svn info $dir", 60); |
|---|
| 13 |
my @mlines = split (/\n/,$moutput); |
|---|
| 14 |
my ($URL,$mr); |
|---|
| 15 |
for(@mlines) { |
|---|
| 16 |
if (/^URL:\s*(.*)$/) { $URL=$1; } |
|---|
| 17 |
elsif (/^Revision:\s*(\d+)/) { $mr = $1; } |
|---|
| 18 |
} |
|---|
| 19 |
return ($arg->set_status("BAD(wrong URL, in conf:".$arg->{'URL'}.", checked out: $URL)")) if ($URL ne $arg->{'URL'}); |
|---|
| 20 |
my $uoutput = cache_command("/opt/omni/bin/svn info --username svnsync --password Athi3izo --no-auth-cache --non-interactive $URL", 60); |
|---|
| 21 |
my @ulines = split (/\n/,$uoutput); |
|---|
| 22 |
my ($ur); |
|---|
| 23 |
for(@ulines) { |
|---|
| 24 |
if (/^Revision:\s*(\d+)/) { $ur = $1; } |
|---|
| 25 |
} |
|---|
| 26 |
if($ur == $mr){ return($arg->set_status("OK(rev:$ur)")); } |
|---|
| 27 |
else{ |
|---|
| 28 |
my ($uY,$uM,$uD,$uh,$um,$us); |
|---|
| 29 |
for(@ulines) { |
|---|
| 30 |
if (/^Last Changed Date:\s*(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{2}):(\d{2})/) { |
|---|
| 31 |
($uY,$uM,$uD,$uh,$um,$us) = ($1,$2,$3,$4,$5,$6); |
|---|
| 32 |
} |
|---|
| 33 |
} |
|---|
| 34 |
my $routput = cache_command("/opt/omni/bin/svn info --username svnsync --password Athi3izo --no-auth-cache --non-interactive $URL\@$mr", 60); |
|---|
| 35 |
my @rlines = split (/\n/,$routput); |
|---|
| 36 |
my ($mY,$mM,$mD,$mh,$mm,$ms); |
|---|
| 37 |
for(@rlines) { |
|---|
| 38 |
if (/^Last Changed Date:\s*(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{2}):(\d{2})/) { |
|---|
| 39 |
($mY,$mM,$mD,$mh,$mm,$ms) = ($1,$2,$3,$4,$5,$6); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
my ($mTime,$uTime,$lag,$maxlag); |
|---|
| 43 |
$mTime=$ms+60*($mm+60*($mh+24*($mD+31*($mM+12*$mY)))); |
|---|
| 44 |
$uTime=$us+60*($um+60*($uh+24*($uD+31*($uM+12*$uY)))); |
|---|
| 45 |
$lag=$uTime-$mTime; |
|---|
| 46 |
$maxlag=$arg->{'maxlag'}*60 || 330; |
|---|
| 47 |
if ($lag <= $maxlag){ |
|---|
| 48 |
return($arg->set_status("OK(delay = $lag < $maxlag)")); |
|---|
| 49 |
} |
|---|
| 50 |
elsif ($us+60*($um+60*($uh+24*$uD))<$maxlag) { |
|---|
| 51 |
my ($cD,$ch,$cm,$cs) = split ( / /, `date '+%d %H %M %S'`); |
|---|
| 52 |
my $cTime = $cs+60*($cm+60*($ch+24*$cD)); |
|---|
| 53 |
if ($cTime<$maxlag) { |
|---|
| 54 |
return($arg->set_status("WARNING(check unreliable, check later)")); |
|---|
| 55 |
} |
|---|
| 56 |
else { |
|---|
| 57 |
return($arg->set_status("BAD(my rev:$mr, repo rev:$ur, delay: $lag > $maxlag)")); |
|---|
| 58 |
} |
|---|
| 59 |
} |
|---|
| 60 |
else { |
|---|
| 61 |
return($arg->set_status("BAD(my rev:$mr, repo rev:$ur, delay: $lag > $maxlag)")); |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|