2 |
|
|
3 |
use strict; |
use strict; |
4 |
use DBI; |
use DBI; |
5 |
|
use Cache::FileCache; |
6 |
|
|
7 |
my $debug = 0; |
my $debug = 0; |
8 |
|
|
9 |
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; |
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; |
10 |
|
my $cache = new Cache::FileCache(); |
11 |
|
|
12 |
my %omni; |
my %omni; |
13 |
|
|
14 |
sub db { |
sub db { |
15 |
my $rv = $dbh->do("update gantt |
return if (scalar keys %omni != 6); |
16 |
|
|
17 |
|
my $sql = "update gantt |
18 |
set finish=now() where |
set finish=now() where |
19 |
sessionid='$omni{SessionID}' and |
sessionid='$omni{SessionID}' and |
20 |
type='$omni{Session_type}' and |
type='$omni{Session_type}' and |
21 |
status='$omni{Session_status}' and |
status='$omni{Session_status}' and |
22 |
user_group_host='".$omni{'User.Group@Host'}."' and |
user_group_host='".$omni{'User.Group@Host'}."' and |
23 |
specification='$omni{Backup_Specification}'"); |
specification='$omni{Backup_Specification}'"; |
24 |
|
|
25 |
|
my $rv = $dbh->do($sql); |
26 |
|
|
27 |
|
print "sql:\n$sql\nrv: $rv\n" if ($debug); |
28 |
|
|
29 |
|
my ($device,$host); |
30 |
|
|
31 |
$dbh->do ("insert into gantt (sessionid,type,status, |
if ($rv eq "0E0" || !$rv) { |
32 |
user_group_host,specification) values |
my $c = $cache->get( $omni{SessionID} ); |
33 |
('$omni{SessionID}','$omni{Session_type}', |
|
34 |
'$omni{Session_status}', |
if (defined $c) { |
35 |
'".$omni{'User.Group@Host'}."', |
($device,$host) = split(/\t/,$c,2); |
36 |
'$omni{Backup_Specification}')") if ($rv eq "0E0"); |
print STDERR "cache hit for $omni{SessionID} - $host:$device\n" if ($debug); |
37 |
|
} else { |
38 |
|
print STDERR "cache miss for $omni{SessionID}" if ($debug); |
39 |
|
open(O, "/usr/omni/bin/omnistat -session $omni{SessionID} |") || die "omnistat: $!"; |
40 |
|
while(<O>) { |
41 |
|
chomp; |
42 |
|
next if (/^$/ || /^Device/ || /^=+$/); |
43 |
|
($device,$host,undef) = split(/\s+/,$_,3); |
44 |
|
$cache->set( $omni{SessionID}, "$device\t$host", "24 hours" ); |
45 |
|
print STDERR " = $host:$device\n" if ($debug); |
46 |
|
last; |
47 |
|
} |
48 |
|
close(O); |
49 |
|
} |
50 |
|
|
51 |
|
$sql = "insert into gantt (sessionid,type,status, |
52 |
|
user_group_host,specification,device,host) values |
53 |
|
('$omni{SessionID}','$omni{Session_type}', |
54 |
|
'$omni{Session_status}', |
55 |
|
'".$omni{'User.Group@Host'}."', |
56 |
|
'$omni{Backup_Specification}', |
57 |
|
'$device','$host')"; |
58 |
|
|
59 |
|
$dbh->do($sql) || warn "$sql : ".$dbh->errstr(); |
60 |
|
|
61 |
|
} |
62 |
} |
} |
63 |
|
|
64 |
open(O, "/usr/omni/bin/omnistat -detail |") || die "omnistat: $!"; |
open(O, "/usr/omni/bin/omnistat -detail |") || die "omnistat: $!"; |
65 |
while(<O>) { |
if (!eof(O)) { |
66 |
chomp; |
# somehow, from time to time omnistats dies before we get here |
67 |
if (/^$/) { |
# this is a workaround to keep cron e-mails from reporting it. |
68 |
db() if (scalar keys %omni == 4); |
while(<O>) { |
69 |
%omni = (); |
chomp; |
70 |
print "------------\n" if ($debug); |
if (/^$/) { |
71 |
next; |
db(); |
72 |
|
%omni = (); |
73 |
|
print "------------\n" if ($debug); |
74 |
|
next; |
75 |
|
} |
76 |
|
s/^[\t\s]+//; |
77 |
|
my ($l,$r) = split (/\s*:\s*/,$_,2); |
78 |
|
if ($r) { |
79 |
|
$l =~ s/\s+/_/g; |
80 |
|
$r =~ s/\s+$//g; |
81 |
|
print "$l -> $r\n" if ($debug); |
82 |
|
$omni{$l} = $r; |
83 |
|
} |
84 |
} |
} |
85 |
s/^[\t\s]+//; |
db(); |
86 |
my ($l,$r) = split (/\s*:\s*/,$_,2); |
close(O); |
|
$l =~ s/\s+/_/g; |
|
|
$r =~ s/\s+$//g; |
|
|
print "$l -> $r\n" if ($debug); |
|
|
$omni{$l} = $r; |
|
|
|
|
87 |
} |
} |
|
db(); |
|
|
close(O); |
|