- set API URL to www.planet-lab.org
[monitor.git] / monitor.py
index c375dd4..eacf14d 100644 (file)
@@ -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)
@@ -200,6 +203,7 @@ def main():
 
        # Wait for threads to init.  Probably should join, but work on that later.
        time.sleep(10)
+
        # Start Sending Emails
        startThread(pol, "policy")
 
@@ -208,7 +212,13 @@ def main():
                time.sleep(15)
 
 
+
+       # Store state of emails
        pol.emailedStore("WRITE")
+
+       # Email what we did.
+       pol.status()
+
        logger.info('Monitor Exitted')
        #if not debug:
        #       removepid("monitor")