Index: /trunk/tools/czarmetrics.pl
===================================================================
--- /trunk/tools/czarmetrics.pl	(revision 30249)
+++ /trunk/tools/czarmetrics.pl	(revision 30250)
@@ -8,9 +8,8 @@
 use CGI::Pretty qw[:standard];
 
+use czartool::Config;
 use czartool::DayMetrics;
 use czartool::MultiDayMetrics;
 use czartool::MetricsIndex;
-use czartool::CzarDb;
-use czartool::Gpc1Db;
 
 my $czarDbName = "czardb";
@@ -60,11 +59,9 @@
 if ($quit) {exit;}
 
-my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
-my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", $verbose, $save_temps);
-$czarDb->setDateFormat("%Y%m%d-%H%i%s");
+my $config = new czartool::Config();
 
 if ($index) {
 
-    my $metricsIndex = new czartool::MetricsIndex($gpc1Db, $czarDb, "/data/ipp004.0/ipp/ippMetrics/", 1, 0);
+    my $metricsIndex = new czartool::MetricsIndex($config, 1, 0);
     $metricsIndex->writeHTML();
     exit;
@@ -82,12 +79,14 @@
 if ($cumulative) {
 
-        my $multiDayMetrics = new czartool::MultiDayMetrics($gpc1Db, $czarDb, "/data/ipp004.0/ipp/ippMetrics/", 1, 0, $begin, $end);
+        my $multiDayMetrics = new czartool::MultiDayMetrics($config, 1, 0, $begin, $end);
         $multiDayMetrics->writeHTML();
 }
 else {
 
+    my $czarDb = $config->getCzarDbInstance();
+
     while (1) {
 
-        my $dayMetrics = new czartool::DayMetrics($gpc1Db, $czarDb, "/data/ipp004.0/ipp/ippMetrics/", 1, 0, $thisDay);
+        my $dayMetrics = new czartool::DayMetrics($config, 1, 0, $thisDay);
         $dayMetrics->writeHTML();
 
Index: /trunk/tools/czarplot.pl
===================================================================
--- /trunk/tools/czarplot.pl	(revision 30249)
+++ /trunk/tools/czarplot.pl	(revision 30250)
@@ -7,10 +7,8 @@
 use POSIX qw/strftime/;
 
-use czartool::CzarDb;
-use czartool::Gpc1Db;
+use czartool::Config;
 use czartool::Plotter;
 use czartool::StageMetrics;
 
-my $czarDbName = "czardb";
 my $label = undef;
 my $stage = undef;
@@ -36,5 +34,4 @@
 
 GetOptions (
-        "dbname=s" => \$czarDbName,
         "label|l=s" => \$label,
         "stage|s=s" => \$stage,
@@ -114,4 +111,6 @@
 if ($quit) { exit; }
 
+my $config = new czartool::Config();
+
 # default values
 if (!$rate && !$magicMask && !$nebulous && !$histogram && !$analysis && !$timeSeries) {$timeSeries = 1;}
@@ -121,7 +120,5 @@
 else {$savingToFile = 1;}
 
-my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
-my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp", $verbose, $save_temps);
-$czarDb->setDateFormat("%Y%m%d-%H%i%s");
+my $czarDb = $config->getCzarDbInstance();
 
 
@@ -129,16 +126,9 @@
 if ($savingToFile) {
 
-    $plotter = czartool::Plotter->new_file(
-            $gpc1Db,
-            $czarDb,
-            $path,
-            $save_temps);
+    $plotter = czartool::Plotter->new_file($config, $path, $save_temps);
 }
 else {
 
-    $plotter = czartool::Plotter->new_display(
-            $gpc1Db, 
-            $czarDb, 
-            $save_temps);
+    $plotter = czartool::Plotter->new_display($config, $save_temps);
 }
 
@@ -148,5 +138,5 @@
     if ($magicMask) {
 
-        $begin =  $day;
+        $begin = $day;
         $end = $day;
     }
@@ -167,4 +157,7 @@
     }
 }
+
+print "B $begin E $end";
+
 if ($rate) {
 
Index: /trunk/tools/czarpoll.pl
===================================================================
--- /trunk/tools/czarpoll.pl	(revision 30249)
+++ /trunk/tools/czarpoll.pl	(revision 30250)
@@ -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,21 +24,18 @@
 
 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");
@@ -110,5 +114,5 @@
     my $today = undef;
     my $yesterday = undef;
-    my $newDayTime = "18:00";
+    my $newDayTime = $config->getMetricsStartTime();
     my $lastDayDailyTasks = "2010-01-01";
 
@@ -136,15 +140,9 @@
                 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();
 
Index: /trunk/tools/czartool.pl
===================================================================
--- /trunk/tools/czartool.pl	(revision 30249)
+++ /trunk/tools/czartool.pl	(revision 30250)
@@ -6,4 +6,5 @@
 
 # local classes
+use czartool::Config;
 use czartool::CzarDb;
 use czartool::Gpc1Db;
@@ -22,8 +23,8 @@
 
 my @states = ("full", "new", "drop", "wait");
-my $czarDb = new czartool::CzarDb($czarDbName, "ippdb01", "ipp", "ipp");
-my $gpc1Db = new czartool::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser");
+my $config = new czartool::Config();
+my $czarDb = $config->getCzarDbInstance();
+my $gpc1Db = $config->getGpc1Instance();
 my $pantasks = new czartool::Pantasks();
-$czarDb->setDateFormat("%Y%m%d-%H%i%s");
 
 my @stdscienceLabels = undef;
Index: /trunk/tools/czartool/Config.pm
===================================================================
--- /trunk/tools/czartool/Config.pm	(revision 30250)
+++ /trunk/tools/czartool/Config.pm	(revision 30250)
@@ -0,0 +1,244 @@
+#!/usr/bin/perl -w
+
+use warnings;
+use strict;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use POSIX qw/strftime/;
+use CGI::Pretty qw[:standard];
+use XML::LibXML;
+
+use czartool::CzarDb;
+use czartool::Gpc1Db;
+
+package czartool::Config;
+
+###########################################################################
+#
+# Constructor
+#
+###########################################################################
+sub new {
+
+    my $class = shift;
+    my $self = {};
+
+    bless $self, $class;
+    $self->parseConfigFile();
+    return $self;
+}
+
+###########################################################################
+#
+# Parses the XML config file 
+#
+###########################################################################
+sub parseConfigFile {
+    my ($self) = @_;
+
+    my $parser = XML::LibXML->new;
+    my $doc = $parser->parse_file("czartool/czarconfig.xml");
+    my $xc = XML::LibXML::XPathContext->new($doc);
+    # $xc->registerNs('czarconfig', 'ippczar');
+
+    # gnuplot stuff
+    $self->{gnuplotfont} = $xc->findvalue('//gnuplot/font');
+    $self->{gnuplotfontsize} = $xc->findvalue('//gnuplot/size');
+
+    # metrics
+    $self->{metricssavelocation} = $xc->findvalue('//metrics/savelocation');
+    $self->{metricsstarttime} = $xc->findvalue('//metrics/starttime');
+
+    # gpc1 db
+    $self->{gpc1name} = $xc->findvalue('//gpc1database/name');
+    $self->{gpc1host} = $xc->findvalue('//gpc1database/host');
+    $self->{gpc1user} = $xc->findvalue('//gpc1database/user');
+    $self->{gpc1password} = $xc->findvalue('//gpc1database/password');
+
+    # czar db
+    $self->{czarname} = $xc->findvalue('//czardatabase/name');
+    $self->{czarhost} = $xc->findvalue('//czardatabase/host');
+    $self->{czaruser} = $xc->findvalue('//czardatabase/user');
+    $self->{czarpassword} = $xc->findvalue('//czardatabase/password');
+
+    # roboczar
+    $self->{roboczaremail} = $xc->findvalue('//roboczar/email');
+    $self->{roboczarserverinterval} = $xc->findvalue('//roboczar/serverinterval');
+
+
+}
+
+###########################################################################
+#
+# Returns an instance of the czardb database 
+#
+###########################################################################
+sub getCzarDbInstance {
+    my ($self) = @_;
+
+    my $czarDb = new czartool::CzarDb(
+            $self->{czarname}, 
+            $self->{czarhost}, 
+            $self->{czaruser},
+            $self->{czarpassword}
+            );
+    $czarDb->setDateFormat("%Y%m%d-%H%i%s");
+
+    return $czarDb;
+}
+
+###########################################################################
+#
+# Returns an instance of the gpc1 database 
+#
+###########################################################################
+sub getGpc1Instance {
+    my ($self) = @_;
+
+    return new czartool::Gpc1Db(
+            $self->{gpc1name}, 
+            $self->{gpc1host}, 
+            $self->{gpc1user},
+            $self->{gpc1password});
+}
+
+###########################################################################
+#
+# Returns the interval after which we consider a server to be down/stopped
+#
+###########################################################################
+sub getRoboczarServerInterval {
+    my ($self) = @_;
+    return $self->{roboczarserverinterval};
+}
+
+###########################################################################
+#
+# Returns the email to which roboczar should send its warnings
+#
+###########################################################################
+sub getRoboczarEmail {
+    my ($self) = @_;
+    return $self->{roboczaremail};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getGnuplotFont {
+    my ($self) = @_;
+    return $self->{gnuplotfont};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getGnuplotFontSize {
+    my ($self) = @_;
+    return $self->{gnuplotfontsize};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getMetricsSaveLocation {
+    my ($self) = @_;
+    return $self->{metricssavelocation};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getMetricsStartTime {
+    my ($self) = @_;
+    return $self->{metricsstarttime};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getGpc1Name {
+    my ($self) = @_;
+    return $self->{gpc1name};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getGpc1Host {
+    my ($self) = @_;
+    return $self->{gpc1host};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getGpc1User {
+    my ($self) = @_;
+    return $self->{gpc1user};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getGpc1Password {
+    my ($self) = @_;
+    return $self->{gpc1password};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getCzarName {
+    my ($self) = @_;
+    return $self->{czarname};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getCzarHost {
+    my ($self) = @_;
+    return $self->{czarhost};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getCzarUser {
+    my ($self) = @_;
+    return $self->{czaruser};
+}
+
+###########################################################################
+#
+# Returns  
+#
+###########################################################################
+sub getCzarPassword {
+    my ($self) = @_;
+    return $self->{czarpassword};
+}
+1;
Index: /trunk/tools/czartool/DayMetrics.pm
===================================================================
--- /trunk/tools/czartool/DayMetrics.pm	(revision 30249)
+++ /trunk/tools/czartool/DayMetrics.pm	(revision 30250)
@@ -28,17 +28,15 @@
     # Call the constructor of the parent class
     my $self = $class->SUPER::new(
-            $_[1],  # gpc1Db 
-            $_[2],  # czarDb
-            $_[3],  # baseDir
-            $_[4],  # verbose
-            $_[5]   # save_temps
+            $_[1],  # config object 
+            $_[2],  # verbose
+            $_[3]   # save_temps
             ); 
 
-    $self->{day} = $_[6];
+    $self->{day} = $_[4];
 
     my $yesterday =  $self->{czarDb}->subtractInterval($self->{day}, "1 DAY");
 
     # sort out times
-    $self->{begin} =  "$yesterday 18:00";
+    $self->{begin} =  "$yesterday " . $self->{config}->getMetricsStartTime();
     $self->{end} = $self->{czarDb}->addInterval($self->{begin}, "1 DAY");
     $self->{burntoolEnd} = $self->{czarDb}->addInterval($self->{begin}, "12 HOUR");
Index: /trunk/tools/czartool/Metrics.pm
===================================================================
--- /trunk/tools/czartool/Metrics.pm	(revision 30249)
+++ /trunk/tools/czartool/Metrics.pm	(revision 30250)
@@ -24,10 +24,12 @@
     my $class = shift;
     my $self = {
-        gpc1Db => shift,
-        czarDb => shift,
-        baseDir => shift,
+        config => shift,
         verbose => shift,
         save_temps => shift,
     };
+
+    $self->{gpc1Db} = $self->{config}->getGpc1Instance();
+    $self->{czarDb} = $self->{config}->getCzarDbInstance();
+    $self->{baseDir} = $self->{config}->getMetricsSaveLocation();
 
     # create path, dir
@@ -36,6 +38,5 @@
     # instantiate a plotter object
     $self->{plotter} = czartool::Plotter->new_file(
-            $self->{gpc1Db},
-            $self->{czarDb},
+            $self->{config},
             ".",
             $self->{save_temps});
Index: /trunk/tools/czartool/MetricsIndex.pm
===================================================================
--- /trunk/tools/czartool/MetricsIndex.pm	(revision 30249)
+++ /trunk/tools/czartool/MetricsIndex.pm	(revision 30250)
@@ -28,9 +28,7 @@
     # Call the constructor of the parent class
     my $self = $class->SUPER::new(
-            $_[1],  # gpc1Db 
-            $_[2],  # czarDb
-            $_[3],  # baseDir
-            $_[4],  # verbose
-            $_[5]   # save_temps
+            $_[1],  # config object 
+            $_[2],  # verbose
+            $_[3]   # save_temps
             );
 
Index: /trunk/tools/czartool/MultiDayMetrics.pm
===================================================================
--- /trunk/tools/czartool/MultiDayMetrics.pm	(revision 30249)
+++ /trunk/tools/czartool/MultiDayMetrics.pm	(revision 30250)
@@ -28,17 +28,15 @@
     # Call the constructor of the parent class
     my $self = $class->SUPER::new(
-            $_[1],  # gpc1Db 
-            $_[2],  # czarDb
-            $_[3],  # baseDir
-            $_[4],  # verbose
-            $_[5]   # save_temps
+            $_[1],  # config object 
+            $_[2],  # verbose
+            $_[3]   # save_temps
             );
 
-    $self->{startDay} = $_[6];
-    $self->{endDay} = $_[7];
+    $self->{startDay} = $_[4];
+    $self->{endDay} = $_[5];
 
     # sort out times
-    $self->{begin} =  "$self->{startDay} 06:00";
-    $self->{end} =  "$self->{endDay} 06:00";
+    $self->{begin} =  "$self->{startDay} " . $self->{config}->getMetricsStartTime();
+    $self->{end} =  "$self->{endDay} " . $self->{config}->getMetricsStartTime();
 
     # create path, dir and html file
Index: /trunk/tools/czartool/Plotter.pm
===================================================================
--- /trunk/tools/czartool/Plotter.pm	(revision 30249)
+++ /trunk/tools/czartool/Plotter.pm	(revision 30250)
@@ -7,4 +7,6 @@
 
 use File::Temp;
+
+use czartool::Config;
 
 my @allStages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist");
@@ -18,6 +20,5 @@
     my $class = shift;
     my $self = {
-        _gpc1Db => shift,
-        _czarDb => shift,
+        _config => shift,
         _dateFormat => shift,
         _outputFormat => shift,
@@ -27,4 +28,5 @@
 
     bless $self, $class;
+    $self->init();
     return $self;
 }
@@ -38,14 +40,13 @@
     my $class = shift;
     my $self = {
-        _gpc1Db => shift,
-        _czarDb => shift,
+        _config => shift,
         _outputPath => shift,
         _save_temps => shift,
                                                     };
-
     $self->{_dateFormat} = "%Y%m%d-%H%M%S";
-    $self->{_outputFormat} = "png font \"/usr/share/fonts/corefonts/arial.ttf\" 8"; # TODO path needs to be in config
-
-        bless $self, $class;
+    $self->{_outputFormat} = "png font \"".$self->{_config}->getGnuplotFont()."\" ".$self->{_config}->getGnuplotFontSize();
+
+    bless $self, $class;
+    $self->init();
     return $self;
 }
@@ -59,6 +60,5 @@
     my $class = shift;
     my $self = {
-        _gpc1Db => shift,
-        _czarDb => shift,
+        _config => shift,
         _save_temps => shift,
     };
@@ -69,8 +69,19 @@
 
     bless $self, $class;
+    $self->init();
     return $self;
 }
 
-
+###########################################################################
+#
+# Some initialisation code common to all constructors
+#
+###########################################################################
+sub init {
+    my ($self) = @_;
+
+    $self->{_gpc1Db} = $self->{_config}->getGpc1Instance();
+    $self->{_czarDb} = $self->{_config}->getCzarDbInstance();
+}
 
 ###########################################################################
Index: /trunk/tools/czartool/czarconfig.xml
===================================================================
--- /trunk/tools/czartool/czarconfig.xml	(revision 30249)
+++ /trunk/tools/czartool/czarconfig.xml	(revision 30250)
@@ -10,5 +10,5 @@
   <metrics>
     <savelocation>/data/ipp004.0/ipp/ippMetrics</savelocation>
-    <starttime>06:00</starttime>
+    <starttime>18:00</starttime>
   </metrics>
 
@@ -27,3 +27,7 @@
   </czardatabase>
 
+  <roboczar>
+    <email>ps-ipp-ops@ifa.hawaii.edu</email>
+    <serverinterval>20 MINUTE</serverinterval>
+  </roboczar>
 </czarconfig>
Index: /trunk/tools/roboczar.pl
===================================================================
--- /trunk/tools/roboczar.pl	(revision 30249)
+++ /trunk/tools/roboczar.pl	(revision 30250)
@@ -7,4 +7,5 @@
 
 # local classes
+use czartool::Config;
 use czartool::CzarDb;
 use czartool::Gpc1Db;
@@ -15,14 +16,8 @@
 use czartool::StageMetrics;
 
-my $czarDbName = "czardb"; # TODO variables for other Db stuff, host etc
 my $save_temps = 0;
 
-GetOptions (
-        "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
-
-$czarDb->setDateFormat("%Y%m%d-%H%i%s");
+my $config = new czartool::Config();
+my $czarDb = $config->getCzarDbInstance();
 
 my @stages = ("burntool", "chip", "cam", "fake", "warp", "stack", "diff", "magic", "magicDS", "dist"); # TODO get from Pantasks
@@ -41,14 +36,14 @@
     $message = "";
 
-    if (anyStoppedServers("20 MINUTE", \$serversMessage)) {
+    if (anyStoppedServers($config->getRoboczarServerInterval(), \$serversMessage)) {
 
         $message .= "\n\n" . $serversMessage;
         $anythingToReport = 1;
     }
-    if (anyStuckStages("2 HOUR", \$stuckMessage)) {
+#    if (anyStuckStages("2 HOUR", \$stuckMessage)) {
 
-        $message .= "\n\n" . $stuckMessage;
-        $anythingToReport = 1;
-    }
+ #       $message .= "\n\n" . $stuckMessage;
+  #      $anythingToReport = 1;
+   # }
 
     if ($anythingToReport && $message ne $lastMessage) {
@@ -56,6 +51,5 @@
 print "\n\n$message\n\n";
 
-        sendEmail(
-                "ps-ipp-ops\@ifa.hawaii.edu", 
+        sendEmail($config->getRoboczarEmail(),
                 "Roboczar warnings", 
                 "$message\n");
@@ -82,5 +76,5 @@
     my $anyStuckStages = 0;
 
-    # exception - we don't care if burntool is stalled before 6:30am
+    # exception - we don't care if burntool is stalled before 6:30am TODO we do now
     my $burntime = strftime('%Y-%m-%d 06:35', localtime);
     my $worryAboutBurntool = $czarDb->isBefore($burntime, $end);
