--- omni2db.pl 2002/09/11 20:54:24 1.3 +++ omni2db.pl 2002/09/14 12:15:20 1.6 @@ -2,32 +2,63 @@ use strict; use DBI; +use Cache::FileCache; my $debug = 0; my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; +my $cache = new Cache::FileCache(); my %omni; sub db { return if (scalar keys %omni != 6); - my $rv = $dbh->do("update gantt + my $sql = "update gantt set finish=now() where sessionid='$omni{SessionID}' and type='$omni{Session_type}' and status='$omni{Session_status}' and - user_group_host='".$omni{'User.Group@Host'}||''."' and - specification='$omni{Backup_Specification}'"); + user_group_host='".$omni{'User.Group@Host'}."' and + specification='$omni{Backup_Specification}'"; - print "rv: $rv\n" if ($debug); + my $rv = $dbh->do($sql); - $dbh->do ("insert into gantt (sessionid,type,status, - user_group_host,specification) values - ('$omni{SessionID}','$omni{Session_type}', - '$omni{Session_status}', - '".$omni{'User.Group@Host'}."', - '$omni{Backup_Specification}')") if ($rv eq "0E0" || !$rv); + print "sql:\n$sql\nrv: $rv\n" if ($debug); + + my ($device,$host); + + if ($rv eq "0E0" || !$rv) { + my $c = $cache->get( $omni{SessionID} ); + + if (defined $c) { + ($device,$host) = split(/\t/,$c,2); + print STDERR "cache hit for $omni{SessionID} - $host:$device\n" if ($debug); + } else { + print STDERR "cache miss for $omni{SessionID}" if ($debug); + open(O, "/usr/omni/bin/omnistat -session $omni{SessionID} |") || die "omnistat: $!"; + while() { + chomp; + next if (/^$/ || /^Device/ || /^=+$/); + ($device,$host,undef) = split(/\s+/,$_,3); + $cache->set( $omni{SessionID}, "$device\t$host", "24 hours" ); + print STDERR " = $host:$device\n" if ($debug); + last; + } + close(O); + } + + $sql = "insert into gantt (sessionid,type,status, + user_group_host,specification,device,host) values + ('$omni{SessionID}','$omni{Session_type}', + '$omni{Session_status}', + '".$omni{'User.Group@Host'}."', + '$omni{Backup_Specification}', + '$device','$host')"; + + $dbh->do($sql) || warn "$sql : ".$dbh->errstr(); + + } } open(O, "/usr/omni/bin/omnistat -detail |") || die "omnistat: $!";