--- omni2db.pl 2002/09/12 07:59:57 1.4 +++ omni2db.pl 2002/09/13 12:38:25 1.5 @@ -2,10 +2,12 @@ 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; @@ -24,12 +26,36 @@ print "sql:\n$sql\nrv: $rv\n" if ($debug); - $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); + 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); + } + + $dbh->do ("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')") + } } open(O, "/usr/omni/bin/omnistat -detail |") || die "omnistat: $!";