Index: branches/eam_branches/ipp-20101205/tools/czarpoll.pl
===================================================================
--- branches/eam_branches/ipp-20101205/tools/czarpoll.pl	(revision 30102)
+++ branches/eam_branches/ipp-20101205/tools/czarpoll.pl	(revision 30446)
@@ -1,3 +1,9 @@
 #!/usr/bin/perl -w
+
+###########################################################################
+#
+# Main polling program for czartool. Grabs stuff from various sources every few minutes.
+#
+###########################################################################
 
 use warnings;
@@ -7,4 +13,5 @@
 
 # local classes
+use czartool::Config;
 use czartool::CzarDb;
 use czartool::Gpc1Db;
@@ -17,26 +24,49 @@
 
 my $period = 60;
-my $czarDbName = "czardb"; # TODO variables for other Db stuff, host etc
 my $save_temps = 0;
 
 GetOptions (
         "period|p=s" => \$period, # TODO more Db args
-        "dbname|d=s" => \$czarDbName,
         );
 
-my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", 0, $save_temps); # TODO last arg here is save_temps, should get as arg
-my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
+my $config = new czartool::Config();
+my $czarDb = $config->getCzarDbInstance(); 
+my $gpc1Db = $config->getGpc1Instance;
 my $nebulous = new czartool::Nebulous($czarDb);
 my $pantasks = new czartool::Pantasks();
-my $plotter = czartool::Plotter->new_file($gpc1Db, $czarDb, "/tmp", $save_temps); 
+my $plotter = czartool::Plotter->new_file($config, "/tmp", $save_temps); 
 my $burntool = new czartool::Burntool();
 
 
-$czarDb->setDateFormat("%Y%m%d-%H%i%s");
-
 my @stages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
 
 
 timePoll($period);
+
+###########################################################################
+#
+# Updates the dates from pantasks for all interested servers 
+#
+###########################################################################
+sub updateDates {
+
+    print "* Updating dates\n";
+    my @servers = ("stdscience", "registration");
+
+    my $server = undef;
+    $czarDb->emptyServerDates();
+    foreach $server (@servers) {
+
+        my @dates = @{$pantasks->getDates($server)};
+        if (@dates) { 
+
+            $czarDb->updateServerDates($server, \@dates);
+        }
+        else {
+
+            print "WARNING: No dates to update for '$server'\n";
+        }
+    }
+}
 
 ###########################################################################
@@ -55,10 +85,10 @@
         my @labels = @{$pantasks->getLabels($server)};
         if (@labels) { 
-        
+
             $czarDb->updateCurrentLabels($server, \@labels);
         }
         else {
-        
-             print "WARNING: No labels to update for '$server'\n";
+
+            print "WARNING: No labels to update for '$server'\n";
         }
     }
@@ -110,5 +140,5 @@
     my $today = undef;
     my $yesterday = undef;
-    my $newDayTime = "18:00";
+    my $newDayTime = $config->getMetricsStartTime();
     my $lastDayDailyTasks = "2010-01-01";
 
@@ -125,31 +155,24 @@
         # if after 18:00 today, then perform some daily tasks and start plots from 18:00 today
         else {
-            
+
             $begin = "$today $newDayTime";
 
             # check whether yesterday was cleaned. if not, cleanup tables and optimize
             if ($lastDayDailyTasks ne $yesterday) {
-   
+
                 print "* performing daily tasks (clean-up, metrics)";
 
                 # create metrics for last 24 hours
                 print "* Creating metrics for last 24 hours\n";
-                # TODO hardcoded path needs to be in config
-                my $dayMetrics = new czartool::DayMetrics($gpc1Db, 
-                        $czarDb, 
-                        "/data/ipp004.0/ipp/ippMetrics/", 
-                        1, 0, $today); 
+                my $dayMetrics = new czartool::DayMetrics($config, 1, 0, $today); 
                 $dayMetrics->writeHTML();
 
                 # now update metrics index page
-                my $metricsIndex = new czartool::MetricsIndex($gpc1Db, 
-                        $czarDb, 
-                        "/data/ipp004.0/ipp/ippMetrics/", 
-                        1, 0); 
+                my $metricsIndex = new czartool::MetricsIndex($config, 1, 0); 
                 $metricsIndex->writeHTML();
 
                 # now cleanup tables from yesterday and optimize
                 print "* New day - performing cleanup\n";
-                $czarDb->cleanupDateRange($yesterday, $yesterday, "30 MINUTE");
+                $czarDb->cleanupDateRange($yesterday, $yesterday, $config->getCzarCleanupInterval());
                 $czarDb->optimize();
                 $lastDayDailyTasks = $yesterday;
@@ -167,4 +190,7 @@
         $plotter->plotDiskUsageHistogram();
         updateServerStatus();
+
+        # check pantasks dates
+        updateDates();
 
         # check labels
