/[omni_gantt]/omni2db.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /omni2db.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations)
Sun Oct 5 10:12:44 2003 UTC (20 years, 5 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +21 -17 lines
File MIME type: text/plain
check for closed filehandle (omnistat crash I surpose)

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4     use DBI;
5 dpavlin 1.5 use Cache::FileCache;
6 dpavlin 1.1
7     my $debug = 0;
8    
9     my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr;
10 dpavlin 1.5 my $cache = new Cache::FileCache();
11 dpavlin 1.1
12     my %omni;
13    
14     sub db {
15 dpavlin 1.3 return if (scalar keys %omni != 6);
16    
17 dpavlin 1.4 my $sql = "update gantt
18 dpavlin 1.1 set finish=now() where
19     sessionid='$omni{SessionID}' and
20     type='$omni{Session_type}' and
21     status='$omni{Session_status}' and
22 dpavlin 1.4 user_group_host='".$omni{'User.Group@Host'}."' and
23     specification='$omni{Backup_Specification}'";
24 dpavlin 1.1
25 dpavlin 1.4 my $rv = $dbh->do($sql);
26    
27     print "sql:\n$sql\nrv: $rv\n" if ($debug);
28 dpavlin 1.2
29 dpavlin 1.5 my ($device,$host);
30    
31     if ($rv eq "0E0" || !$rv) {
32     my $c = $cache->get( $omni{SessionID} );
33    
34     if (defined $c) {
35     ($device,$host) = split(/\t/,$c,2);
36     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 dpavlin 1.6
51     $sql = "insert into gantt (sessionid,type,status,
52 dpavlin 1.5 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 dpavlin 1.6 '$device','$host')";
58    
59     $dbh->do($sql) || warn "$sql : ".$dbh->errstr();
60    
61 dpavlin 1.5 }
62 dpavlin 1.1 }
63    
64     open(O, "/usr/omni/bin/omnistat -detail |") || die "omnistat: $!";
65 dpavlin 1.7 if (!eof(O)) {
66     # somehow, from time to time omnistats dies before we get here
67     # this is a workaround to keep cron e-mails from reporting it.
68     while(<O>) {
69     chomp;
70     if (/^$/) {
71     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 dpavlin 1.3 }
85 dpavlin 1.7 db();
86     close(O);
87 dpavlin 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.26