root/lib/Resmon/Module/FRESHSVN.pm

Revision f808515669a647d9cf2ff36891b3c05b309c1751, 1.8 kB (checked in by Sergey Ivanov <seriv@omniti.com>, 6 years ago)

check if svn checkout is fresh

git-svn-id: https://labs.omniti.com/resmon/trunk@50 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
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 @molines = split (/\n/,$moutput);
14   my ($URL,$mr,$mY,$mM,$mD,$mh,$mm,$ms);
15   for(@molines) {
16     if (/^URL:\s*(.*)$/) { $URL=$1; }
17     elsif (/^Last Changed Rev:\s*(\d+)/) { $mr = $1; }
18     elsif (/^Last Changed Date:\s*(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{2}):(\d{2})/) {
19       ($mY,$mM,$mD,$mh,$mm,$ms) = ($1,$2,$3,$4,$5,$6);
20     }
21   }
22   return ($arg->set_status("BAD(wrong URL, in conf:".$arg->{'URL'}.", checked out: $URL)")) if ($URL ne $arg->{'URL'});
23   my $uoutput = cache_command("/opt/omni/bin/svn info --username svnsync --password Athi3izo  --no-auth-cache --non-interactive $arg->{'URL'} 2>&1 ", 60);
24   my @ulines = split (/\n/,$uoutput);
25   my ($ur,$uY,$uM,$uD,$uh,$um,$us);
26   for(@ulines) {
27     if (/^Last Changed Rev:\s*(\d+)/) { $ur = $1; }
28     elsif (/^Last Changed Date:\s*(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{2}):(\d{2})/) {
29       ($uY,$uM,$uD,$uh,$um,$us) = ($1,$2,$3,$4,$5,$6);
30     }
31   }
32   if($ur == $mr){ return($arg->set_status("OK(rev:$ur)")); }
33   else{
34     my ($mTime,$uTime,$lag,$maxlag);
35     $mTime=$ms+60*($mm+60*($mh+24*($mD+31*($mM+12*$mY))));
36     $uTime=$us+60*($um+60*($uh+24*($uD+31*($uM+12*$uY))));
37     $lag=$uTime-$mTime;
38     $maxlag=$arg->{'maxlag'}*60 || 330;
39     if ($lag <= $maxlag){
40       return($arg->set_status("OK(delay = $lag < $maxlag)"));
41     }
42     elsif ($us+60*($um+60*($uh+24*($uD)))<$maxlag) {
43       return($arg->set_status("WARNING(check unreliable, check later)"));
44     }
45     else {
46       return($arg->set_status("BAD(my rev:$mr, repo rev:$ur)"));
47     }
48   }
49 }
Note: See TracBrowser for help on using the browser.