root/lib/Resmon/Module/FRESHSVN.pm

Revision 4c788be307a22be6ece43323924f27eac69076a8, 2.1 kB (checked in by Mark Harrison <mark@omniti.com>, 6 years ago)

Fixed freshsvn module to not use a hardcoded path for the svn binary and try
to locate it using code similar to the dns update-helper.sh script.

git-svn-id: https://labs.omniti.com/resmon/trunk@83 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 use File::Find;
6
7 @ISA = qw/Resmon::Module/;
8
9 sub handler {
10   # Find location of subversion binary
11   my $svn = 'svn';
12   for my $path (qw(/usr/local/bin /opt/omni/bin)) {
13     if (-x "$path/svn") {
14       $svn = "$path/svn";
15       last;
16     }
17   }
18
19   my $arg = shift;
20   my $os = $arg->fresh_status();
21   return $os if $os;
22   my $dir = $arg->{'object'};
23   my $moutput = cache_command("$svn info $dir", 60);
24   my @mlines = split (/\n/,$moutput);
25   my ($URL,$mr);
26   for(@mlines) {
27     if (/^URL:\s*(.*)$/) { $URL=$1; }
28     elsif (/^Revision:\s*(\d+)/) { $mr = $1; }
29   }
30   return ($arg->set_status("BAD(wrong URL, in conf:".$arg->{'URL'}.", checked out: $URL)")) if ($URL ne $arg->{'URL'});
31   my $uoutput = cache_command("$svn info --username svnsync --password Athi3izo  --no-auth-cache --non-interactive $URL", 60);
32   my @ulines = split (/\n/,$uoutput);
33   my ($ur);
34   for(@ulines) {
35     if (/^Last Changed Rev:\s*(\d+)/) { $ur = $1; }
36   }
37   if($ur <= $mr){ return($arg->set_status("OK(rev:$ur)")); }
38   else{
39     my ($cY,$cM,$cD,$ch,$cm,$cs) = split (/ /, `date '+%Y %m %d %H %M %S'`);
40     my $cTime=$cs+60*($cm+60*($ch+24*($cD+31*($cM+12*$cY))));
41     my $dNow = "$cM/$cD/$cY $ch:$cm:$cs"; chomp $dNow;
42     my ($uY,$uM,$uD,$uh,$um,$us);
43     for(@ulines) {
44       if (/^Last Changed Date:\s*(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{2}):(\d{2})/) {
45         ($uY,$uM,$uD,$uh,$um,$us) = ($1,$2,$3,$4,$5,$6);
46       }
47     }
48     my $uTime = $us+60*($um+60*($uh+24*($uD+31*($uM+12*$uY))));
49     my $dCommitted = "$uM/$uD/$uY $uh:$um:$us";
50     my $lag=$cTime-$uTime;
51     my $maxlag=$arg->{'maxlag'}*60 || 330;
52     if ($lag <= $maxlag){
53       return($arg->set_status("OK(delay = $lag < $maxlag)"));
54     }
55     elsif ( ( ($us+60*($um+60*($uh+24*$uD))) < $maxlag )
56          && ( ($cs+60*($cm+60*($ch+24*$cD))) < 2 * $maxlag )
57           )
58     {
59       return($arg->set_status("WARNING(check unreliable, check later)"));
60     }
61     else {
62       return($arg->set_status("BAD(now $dNow, my rev:$mr, repo rev:$ur, committed: $dCommitted)"));
63     }
64   }
65 }
Note: See TracBrowser for help on using the browser.