Index: branches/eam_branches/ipp-20120601/ippMonitor/INSTALL
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/INSTALL	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/INSTALL	(revision 34047)
@@ -15,4 +15,11 @@
 # note that we have a special version for ippmonitor without $PSCONFIG/$PSCONFDIR values:
 ipp@ippdb03 / ippdb03 example:
- psconfigure --dbhost ippdb01 --dbuser ipp --dbpass ipp --htdocs /var/www/localhost/htdocs --site ~/ippconfig/ippmonitor.config
+# psconfigure --dbhost ippdb01 --dbuser ipp --dbpass ipp --htdocs /var/www/localhost/htdocs --site ~/ippconfig/ippmonitor.config
 
+#ipp@ippdb03 / ippdb01 example:
+ psconfigure --dbhost ippdb03 --dbuser ipp --dbpass ipp --htdocs /var/www/localhost/htdocs --site ~/ippconfig/ippmonitor.config
+
+#
+# Regular installation on ippMonitor.ifa.hawaii.edu
+# Note: we use a 'science databases (replication) slave' and the ippMonitor read-only account to connect to that database
+psconfigure --dbhost scidbs1 --dbuser ippMonitor --dbpass ippMonitor --htdocs /var/www/localhost/htdocs --site ~/ippconfig/ippmonitor.config
Index: branches/eam_branches/ipp-20120601/ippMonitor/czartool/czartool/czarconfig.xml
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/czartool/czartool/czarconfig.xml	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/czartool/czartool/czarconfig.xml	(revision 34047)
@@ -21,5 +21,5 @@
   <gpc1database>
     <name>gpc1</name>
-    <host>ippdb01</host>
+    <host>scidbs1</host>
     <user>ippMonitor</user>
     <password>ippMonitor</password>
@@ -29,5 +29,5 @@
   <czardatabase>
     <name>czardb</name>
-    <host>ippdb01</host>
+    <host>scidbm</host>
     <user>ipp</user>
     <password>ipp</password>
@@ -46,2 +46,3 @@
 
 </czarconfig>
+
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/autocode.php
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/autocode.php	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/autocode.php	(revision 34047)
@@ -28,7 +28,9 @@
 // ** TABLE RESTRICTIONS **
 
+// Note: the restriction is now moved AFTER the count query
+// unless the RESTRICT_COUNT keyword is used
 if ($restricted == 0) {
-  if ("$UNRESTRICTED" != "none") {
-    $WHERE = "$WHERE $UNRESTRICTED";
+  if ("$RESTRICT_COUNT" != "none") {
+    $WHERE = "$WHERE $RESTRICT_COUNT";
   }
 }
@@ -56,4 +58,12 @@
   menu_end();
 }
+
+// Restrict the query if it is necessary
+if ($restricted == 0) {
+  if ( ("$UNRESTRICTED" != "none") && ("$RESTRICT_COUNT" == "none") ) {
+    $WHERE = "$WHERE $UNRESTRICTED";
+  }
+}
+
 // set up the row counter variables
 if ($ID['from']) {
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/camProcessedExp_Images.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/camProcessedExp_Images.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/camProcessedExp_Images.d	(revision 34047)
@@ -3,4 +3,6 @@
 FILE  camProcessedExp_Images.php
 MENU  ipp.science.dat
+
+UNRESTRICTED AND 0>1
 
 # the following WHERE clauses are added to all queries joined by AND
@@ -10,5 +12,4 @@
 WHERE camProcessedExp.cam_id  = camRun.cam_id
 WHERE camProcessedExp.fault = 0
-
 # define image names to be used below
 # IMAGE VAR basename filerule camera class_id
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/diffSummary_Images.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/diffSummary_Images.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/diffSummary_Images.d	(revision 34047)
@@ -3,4 +3,6 @@
 FILE  diffSummary_Images.php
 MENU  ipp.stack.dat
+
+UNRESTRICTED AND 0>1
 
 WHERE diffRun.diff_id             = diffSkyfile.diff_id
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/newImfile.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/newImfile.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/newImfile.d	(revision 34047)
@@ -4,4 +4,6 @@
 MENU  ipp.load.dat
 
+UNRESTRICTED WHERE 0>1
+
 #        field       size  format  name           show   link to         extras
 FIELD    exp_id,	5, %d,     exposure ID
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/pzDoneImfile.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/pzDoneImfile.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/pzDoneImfile.d	(revision 34047)
@@ -3,4 +3,6 @@
 FILE  pzDoneImfile.php
 MENU  ipp.load.dat
+
+UNRESTRICTED AND 0>1
 
 WHERE pzDownloadImfile.fault     = 0
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/pzPendingImfile.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/pzPendingImfile.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/pzPendingImfile.d	(revision 34047)
@@ -3,4 +3,6 @@
 FILE  pzPendingImfile.php
 MENU  ipp.load.dat
+
+UNRESTRICTED AND 0>1
 
 WHERE summitImfile.exp_name  = pzDownloadExp.exp_name 
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/rawBurntoolState.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/rawBurntoolState.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/rawBurntoolState.d	(revision 34047)
@@ -5,4 +5,5 @@
 
 # if no query restrictions are supplied, we want to limit the query or it is extremely long running:
+RESTRICT_COUNT WHERE 0>1
 UNRESTRICTED WHERE exp_id = 0
 
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/rawImfile.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/rawImfile.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/rawImfile.d	(revision 34047)
@@ -5,4 +5,6 @@
 
 # HEAD PHP insert_backref ("rawExp.php", "exp_id", $ID['link']);
+
+UNRESTRICTED WHERE 0>1
 
 OP   OP1  $ra * 57.295783
Index: branches/eam_branches/ipp-20120601/ippMonitor/def/summitImfile.d
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/def/summitImfile.d	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/def/summitImfile.d	(revision 34047)
@@ -3,4 +3,6 @@
 FILE  summitImfile.php
 MENU  ipp.load.dat
+
+UNRESTRICTED WHERE 0>1
 
 #        field     size  format  name             show   link to         extras
Index: branches/eam_branches/ipp-20120601/ippMonitor/raw/czartool_labels.php
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/raw/czartool_labels.php	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/raw/czartool_labels.php	(revision 34047)
@@ -171,5 +171,7 @@
 echo "<tr><td>Who's using the cluster?</td><td><a href=\"http://ippmonitor.ipp.ifa.hawaii.edu/ippMonitor/clusterMonitor/top.html\"><font color=\"blue\">here</font></a></td></tr>";
 echo "<tr><td>IPP metrics</td><td><a href=\"http://ipp0022.ifa.hawaii.edu/ps1sc/ippMetrics\"><font color=\"blue\">here</font></a></td></tr>";
-echo "<tr><td>Czar log pages</td><td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PS1_IPP_CzarLogs\"><font color=\"blue\">here</font></a></td></tr>";
+echo "<tr><td>Czar log pages</td><td><a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PS1_IPP_CzarLogs\"><font color=\"blue\">All</font></a>&nbsp;&nbsp;&nbsp;";
+echo "<a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/PS1_IPP_CzarLog_".(date("Ymd")-date("w")+"1")."\">This week</a>";
+echo "</td></tr>";
 echo "<tr><td>Exposure summary</td><td><a href=\"czartool_exposures.php?pass=$pass&proj=$proj\"><font color=\"blue\">here</font></a></td></tr>";
 
@@ -215,4 +217,5 @@
       showReplicationsStatus($REPL_HOST_PSTAMP, $REPL_USER_PSTAMP, $REPL_PASSWORD_PSTAMP, $REPL_DBNAME_PSTAMP);
       showReplicationsStatus($REPL_HOST_IPPADMIN, $REPL_USER_IPPADMIN, $REPL_PASSWORD_IPPADMIN, $REPL_DBNAME_IPPADMIN);
+      showReplicationsStatus($REPL_HOST_ISP, $REPL_USER_ISP, $REPL_PASSWORD_ISP, $REPL_DBNAME_ISP);
       echo "</table>";
 
Index: branches/eam_branches/ipp-20120601/ippMonitor/raw/site.php.in
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/raw/site.php.in	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/raw/site.php.in	(revision 34047)
@@ -25,10 +25,10 @@
 $REPL_USER_IPPADMIN = "ippMonitor";
 $REPL_PASSWORD_IPPADMIN = "ippMonitor";
-$REPL_DBNAME_IPPADMIN = "ipp001 (gpc1, isp, ippadmin, czardb)";
+$REPL_DBNAME_IPPADMIN = "ipp001 (gpc1, isp, ippadmin, czardb, ipptopsps, megacam, ssp, uip)" ;
 
 $REPL_HOST_NEBULOUS = "ippdb02.IfA.Hawaii.Edu";
 $REPL_USER_NEBULOUS = "ippMonitor";
 $REPL_PASSWORD_NEBULOUS = "ippMonitor";
-$REPL_DBNAME_NEBULOUS = "ippdb02 (Nebulous)";
+$REPL_DBNAME_NEBULOUS = "ippdb02 (nebulous)";
 
 $REPL_HOST_PSTAMP = "ippc19.IfA.Hawaii.Edu";
@@ -40,5 +40,12 @@
 $REPL_USER_GPC1 = "ippMonitor";
 $REPL_PASSWORD_GPC1 = "ippMonitor";
-$REPL_DBNAME_GPC1 = "ippdb03 (gpc1, isp, ippadmin, czardb)";
+$REPL_DBNAME_GPC1 = "ippdb03 (czardb, gpc1, ippadmin, ipptopsps, megacam, skycells, ssp, uip)";
+
+$REPL_HOST_ISP = "ippc17.IfA.Hawaii.Edu";
+$REPL_USER_ISP = "ippMonitor";
+$REPL_PASSWORD_ISP = "ippMonitor";
+$REPL_DBNAME_ISP = "ippc17 (isp)";
+
+
 
 ?>
Index: branches/eam_branches/ipp-20120601/ippMonitor/scripts/generate
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/scripts/generate	(revision 33977)
+++ branches/eam_branches/ipp-20120601/ippMonitor/scripts/generate	(revision 34047)
@@ -29,4 +29,5 @@
     &init_key ("MODE");
     &init_key ("UNRESTRICTED");
+    &init_key ("RESTRICT_COUNT");
     &init_key ("TABLE");
     &init_key ("TITLE");
@@ -46,10 +47,10 @@
         if ($key eq "TABLE") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
         if ($key eq "TYPE")  { ($value) = $value =~ m|^\s*(.+)\s*$|; }
-	if ($key eq "TOPLOT") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
-	if ($key eq "PLOTTER") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
-	if ($key eq "PLOTTITLE") { 
-	    ($value) = $value =~ m|^\s*(.+)\s*$|;
-	    $value =~ s/\s/_/g;
-	}
+        if ($key eq "TOPLOT") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
+        if ($key eq "PLOTTER") { ($value) = $value =~ m|^\s*(.+)\s*$|; }
+        if ($key eq "PLOTTITLE") {
+            ($value) = $value =~ m|^\s*(.+)\s*$|;
+            $value =~ s/\s/_/g;
+        }
 
         &set_keypair ($key, $value);
@@ -61,16 +62,16 @@
             if ($field =~ m|\S+\s+as\s+\S+|) {
                 ($fieldreal) = $field =~ m|\S+\s+as\s+(\S+)|;
-		#print STDERR "Case 1\n";
+                #print STDERR "Case 1\n";
             } elsif ($field =~ m|\S+\s+AS\s+\S+|) {
-		#print STDERR "field=$field\n";
-		$fieldreal = $field;
-		$fieldreal =~ s/\s+AS.*$//;
+                #print STDERR "field=$field\n";
+                $fieldreal = $field;
+                $fieldreal =~ s/\s+AS.*$//;
                 #($fieldreal) = $field =~ m|\S+\s+as\s+(\S+)|;
-		#print STDERR "Case 2\n";
+                #print STDERR "Case 2\n";
             } else {
                 $fieldreal = $field;
-		#print STDERR "Case 3\n";
+                #print STDERR "Case 3\n";
             }
-	    #print STDERR "field=[$field]\tfieldreal=[$fieldreal]\n";
+            #print STDERR "field=[$field]\tfieldreal=[$fieldreal]\n";
 
             if ($VERBOSE) { printf "%-20s %-20s %-20s %-20s %-20s %-20s\n", $field, $name, $format, $show, $link, $extras; }
@@ -141,4 +142,5 @@
     &check_key ("MODE", "basic");
     &check_key ("UNRESTRICTED", "none");
+    &check_key ("RESTRICT_COUNT", "none");
     &check_key ("TABLE", "");
     &check_key ("TITLE", "");
@@ -324,5 +326,4 @@
 # generate a WHERE test for each field (field != *)
 sub write_table_restrict {
-
     if ($WHERE) {
         print FILE "\$WHERE = \"WHERE $WHERE\";\n";
@@ -348,5 +349,5 @@
 }
 
-# Generate GROUP BY statement if any 
+# Generate GROUP BY statement if any
 sub write_group_by {
     print FILE "\$WHERE = check_ordering ('$GROUPS', \$WHERE);\n";
@@ -536,7 +537,7 @@
     @extfields = split (/,/, $extras);
     for ($i = 0; $i < @extfields; $i++) {
-	# print STDERR $extfields[$i],"\n";
+        # print STDERR $extfields[$i],"\n";
         ($label, $value, $outline) = &parse_label ($extfields[$i]);
-	# print STDERR "[",$label,"]","[",$value,"]","[",$outline,"\n";
+        # print STDERR "[",$label,"]","[",$value,"]","[",$outline,"\n";
         print FILE "  \$link = \$link . \"&$outline\";\n";
     }
@@ -553,5 +554,5 @@
     # print STDERR "#############################\n";
     # foreach my $key ( keys %linkarg ) {
-    # 	print STDERR "key: $key, value: $linkarg{$key}\n";
+    #   print STDERR "key: $key, value: $linkarg{$key}\n";
     # }
 
@@ -560,8 +561,8 @@
 
     if ($linkarg{$word}) {
-	# print STDERR "Case 1\n";
+        # print STDERR "Case 1\n";
         $linkarg{$word} = "$linkarg{$word},$value";
     } else {
-	# print STDERR "Case 2\n";
+        # print STDERR "Case 2\n";
         $linkarg{$word} = $value;
     }
@@ -585,11 +586,11 @@
     # print STDERR "### parse_label ###\n";
     # for ($i = 0; $i < @field; $i++) {
-    # 	print STDERR "field[$i]=$field[$i]\n";
+    #   print STDERR "field[$i]=$field[$i]\n";
     # }
     # for ($i = 0; $i < @fieldreal; $i++) {
-    # 	print STDERR "fieldreal[$i]=$fieldreal[$i]\n";
+    #   print STDERR "fieldreal[$i]=$fieldreal[$i]\n";
     # }
     # for ($i = 0; $i < @count; $i++) {
-    # 	print STDERR "count[$i]=$count[$i]\n";
+    #   print STDERR "count[$i]=$count[$i]\n";
     # }
 
@@ -598,5 +599,5 @@
     if ($string =~ m|\S+=\S+|) {
         ($label, $value) = $string =~ m|(\S+)=(\S+)|;
-	# print STDERR "value=$value\n";
+        # print STDERR "value=$value\n";
         if ($value =~ m|^\$|) {
           MATCH_LABEL:
@@ -669,7 +670,7 @@
     $name   = &parse_fieldname ($name);
     if (exists $ops{$name}) {
-	#if OPx was defined, replace it by its value
-	$name = $ops{$name};
-	$name =~ s/\s+//g;
+        #if OPx was defined, replace it by its value
+        $name = $ops{$name};
+        $name =~ s/\s+//g;
     }
     $camera = &parse_fieldname ($camera);
Index: branches/eam_branches/ipp-20120601/ippMonitor/supervision/check_if_mysql_slave_is_running_fine.py
===================================================================
--- branches/eam_branches/ipp-20120601/ippMonitor/supervision/check_if_mysql_slave_is_running_fine.py	(revision 34047)
+++ branches/eam_branches/ipp-20120601/ippMonitor/supervision/check_if_mysql_slave_is_running_fine.py	(revision 34047)
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+# This script is supposed to be run on a host which is running a mysql
+# replication slave. It should be started from the crontab every
+# hour(?).
+#
+# This script makes sure that the mysql replication slave is fine on
+# the localhost. If there is any problem, that is, if the replication
+# is broken because of an error or if the lag between the master and
+# the server is too important (see the MAX_LAG_SECONDS parameter),
+# then an e-mail is sent to the ps-ipp-ops mailing list (actually the
+# RECIPIENT parameter).
+#
+
+import MySQLdb
+import smtplib
+from email.mime.text import MIMEText
+import socket
+
+def send_email(recipient, subject, body):
+    message = MIMEText(body)
+    message['Subject'] = subject
+    _from = 'ipp@ifa.hawaii.edu'
+    message['From'] = _from
+    _to = [recipient]
+    message['To'] = recipient
+    SMTP_CONNECTION = smtplib.SMTP('hale.ifa.hawaii.edu')
+    SMTP_CONNECTION.sendmail(_from, _to, message.as_string())
+    SMTP_CONNECTION.quit()
+
+if __name__ == '__main__':
+    # Configuration parameters
+    MAX_LAG_SECONDS = 10000
+    RECIPIENT = 'ps-ipp-ops@ifa.hawaii.edu'
+
+    # Don't change anything after this
+    db = MySQLdb.connect('localhost', 'root')
+    cursor = db.cursor()
+    cursor.execute('SHOW SLAVE STATUS')
+    ( Slave_IO_State, Master_Host, Master_User, Master_Port,
+      Connect_Retry, Master_Log_File, Read_Master_Log_Pos, Relay_Log_File,
+      Relay_Log_Pos, Relay_Master_Log_File, Slave_IO_Running, Slave_SQL_Running,
+      Replicate_Do_DB, Replicate_Ignore_DB, Replicate_Do_Table, Replicate_Ignore_Table,
+      Replicate_Wild_Do_Table, Replicate_Wild_Ignore_Table, 
+      Last_Errno, Last_Error, Skip_Counter, Exec_Master_Log_Pos,
+      Relay_Log_Space, Until_Condition, Until_Log_File, Until_Log_Pos,
+      Master_SSL_Allowed, Master_SSL_CA_File, Master_SSL_CA_Path, Master_SSL_Cert,
+      Master_SSL_Cipher, Master_SSL_Key, Seconds_Behind_Master) = cursor.fetchall()[0]
+    nodename = socket.gethostbyaddr(socket.gethostname())[0].split('.')[0]
+    if Seconds_Behind_Master is None:
+        if Last_Error != '':
+            send_email(RECIPIENT, 
+                       'MySQL replication problem on %s' % (nodename),
+                       """Last_error value when executing SHOW SLAVE STATUS on that host is:
+%s
+""" % (Last_Error) )
+        else:
+            send_email(RECIPIENT, 
+                       'MySQL replication problem on %s' % (nodename),
+                       """Slave_IO_State value when executing SHOW SLAVE STATUS on that host is:
+%s
+""" % (Slave_IO_State) )
+            print 'Replication problem: %s (is master down?)' % Slave_IO_State
+    elif Seconds_Behind_Master > MAX_LAG_SECONDS:
+        nodename = socket.gethostbyaddr(socket.gethostname())[0].split('.')[0]
+        send_email(RECIPIENT, 
+                   'MySQL replication is late on %s' % (nodename),
+                   """The Seconds_Behind_Master value when executing the 'SHOW SLAVE STATUS' mysql statement on that host is:
+   %s
+
+For info, the threshold is %s seconds.
+
+Check if there is a blocking statement executing on the slave
+""" % (Seconds_Behind_Master, MAX_LAG_SECONDS) )
+    else:
+        pass
+    cursor.close()
+    db.close()
