- I don't know how these ended up in cvs.
[monitor.git] / monitor.py
index c375dd4..feac309 100644 (file)
@@ -4,7 +4,7 @@
 # 
 # Faiyaz Ahmed <faiyaza@cs.princeton.edu>
 #
-# $Id: $
+# $Id: monitor.py,v 1.4 2006/11/14 19:20:13 faiyaza Exp $
 
 import sys
 import os
@@ -14,6 +14,8 @@ from threading import *
 import time
 import logging
 import Queue
+# Global config options
+import config
 # daemonize and *pid
 from util.process import * 
 
@@ -26,8 +28,6 @@ import policy
 # Email
 import mailer
 import emailTxt
-# Defaults
-debug = False 
 
 # Log to what 
 LOG="./monitor.log"
@@ -38,6 +38,8 @@ DAT="./monitor.dat"
 # Email defaults
 MTA="localhost"
 FROM="support@planet-lab.org"
+TECHEMAIL="tech-%s@sites.planet-lab.org"
+PIEMAIL="pi-%s@sites.planet-lab.org"
 
 # API
 XMLRPC_SERVER = 'https://www.planet-lab.org/PLCAPI/'
@@ -108,7 +110,7 @@ class ThreadWatcher(Thread):
                for thread in runningthreads.keys():
                        # If thread found dead, remove from queue
                        if not runningthreads[thread].isAlive():
-                               logger.error("Thread Died: %s" %(thread))
+                               logger.error("***********Thread died: %s**********" %(thread))
                                del runningthreads[thread]
 
 
@@ -125,7 +127,7 @@ Start threads, do some housekeeping, then daemonize.
 """
 def main():
        # Defaults
-       global debug, status, logger
+       global status, logger
 
        try:
                longopts = ["debug", "status", "help"]
@@ -137,7 +139,8 @@ def main():
 
        for (opt, optval) in opts:
                if opt == "-d" or opt == "--debug":
-                       debug = True
+                       config.debug = True
+                       print "Running in DEBUG mode:  NO EMAILS SENT AND NO SLICES SQUEEZED."
                elif opt == "--status":
                        #print summary(names)
                        sys.exit(0)
@@ -155,7 +158,7 @@ def main():
        # The meat of it.
 
        # Nodes to check. Queue of all sick nodes.
-        toCheck = Queue.Queue()
+       toCheck = Queue.Queue()
        # Nodes that are sick w/o tickets
        sickNoTicket = Queue.Queue()
        # Comon DB of all nodes
@@ -163,7 +166,7 @@ def main():
        # Nodes that are down.  Use this to maintain DB;  cleanup.
         #alldown = Queue.Queue()
        # RT DB
-        tickets = {}
+       tickets = {}
        # Nodes we've emailed.
        # host - > (type of email, time)
        emailed = {}
@@ -199,16 +202,22 @@ def main():
        startThread(cm1,"comon")
 
        # Wait for threads to init.  Probably should join, but work on that later.
-       time.sleep(10)
+       time.sleep(15)
+
+#      while toCheck.empty() == false:
+#              time.sleep(10)
+#              
        # Start Sending Emails
+       time.sleep(30)
        startThread(pol, "policy")
+       time.sleep(10)
 
-       # Wait to finish
-       while (sickNoTicket.empty() == False) or (toCheck.empty() == False):
-               time.sleep(15)
+       # Store state of emails
+#      pol.emailedStore("WRITE")
 
+       # Email what we did.
+#      pol.status()
 
-       pol.emailedStore("WRITE")
        logger.info('Monitor Exitted')
        #if not debug:
        #       removepid("monitor")