Added check so we dont keep resending the same email
[monitor.git] / policy.py
index 11e8a68..f6629fb 100644 (file)
--- a/policy.py
+++ b/policy.py
@@ -3,7 +3,7 @@
 #
 # Faiyaz Ahmed <faiyaza@cs.princeton.edu>
 #
-# $Id: $
+# $Id: policy.py,v 1.7 2007/01/11 21:39:07 faiyaza Exp $
 #
 # Policy Engine.
 
@@ -27,7 +27,7 @@ logger = logging.getLogger("monitor")
 POLSLEEP = 7200
 
 # Where to email the summary
-SUMTO = "pupadm@lists.planet-lab.org"
+SUMTO = "faiyaza@cs.princeton.edu"
 TECHEMAIL="tech-%s@sites.planet-lab.org"
 PIEMAIL="pi-%s@sites.planet-lab.org"
 SLICEMAIL="%s@slices.planet-lab.org"
@@ -35,7 +35,7 @@ PLCEMAIL="support@planet-lab.org"
 
 #Thresholds (DAYS)
 SPERDAY = 86400
-PITHRESH = 1 * SPERDAY
+PITHRESH = 2 * SPERDAY
 SLICETHRESH = 5 * SPERDAY
 # Days before attempting rins again
 RINSTHRESH = 5 * SPERDAY
@@ -108,6 +108,9 @@ class Policy(Thread):
                node = self.sickNoTicket.get(block = True)
                # Get the login base    
                loginbase = plc.siteId(node)
+               
+               # Princeton Backdoor
+               if loginbase == "princeton": return
 
                # Send appropriate message for node if in appropriate bucket.
                # If we know where to send a message
@@ -141,26 +144,48 @@ class Policy(Thread):
 
                                logger.info("POLICY:  acted %s on %s days ago" % (node, 
                                delta // SPERDAY))
+                       
+                               # If no luck with tech, email PI
+                               if (delta >= 1):
+                                       target.append(PIEMAIL % loginbase)
 
                                # If more than PI thresh, but less than slicethresh
                                if (delta >= PITHRESH) and (delta < SLICETHRESH): 
-                                       target.append(PIEMAIL % loginbase)
                                        #remove slice creation if enough nodes arent up
                                        if not self.enoughUp(loginbase):
+                                               slices = plc.slices(loginbase)
+                                               if len(slices) >= 1:
+                                                       for slice in slices:
+                                                               target.append(SLICEMAIL % slice)
                                                logger.info("POLICY:  Removing slice creation from %s" % loginbase)
+                                               tmp = emailTxt.mailtxt.removedSliceCreation
+                                               sbj = tmp[0] 
+                                               msg = tmp[1] % {'loginbase': loginbase}
                                                plc.removeSliceCreation(node)
+                                               mailer.email(sbj, msg, target)  
                                                self.squeezed[loginbase] = (time.time(), "creation")
+                                               self.emailed[node] = ("creation", time.time())  
+                                               return
+
                                # If more than PI thresh and slicethresh
                                if (delta >= PITHRESH) and (delta > SLICETHRESH):
+                                       target.append(PIEMAIL % loginbase)
                                        # Email slices at site.
                                        slices = plc.slices(loginbase)
                                        if len(slices) >= 1:
                                                for slice in slices:
                                                        target.append(SLICEMAIL % slice)
-                                               if not self.enoughUp(loginbase):
-                                                       plc.suspendSlices(node)
-                                                       self.squeezed[loginbase] = (time.time(),
-                                                                "freeze")
+                                       # If not enough up, freeze slices and email everyone.
+                                       if not self.enoughUp(loginbase):
+                                               logger.info("POLICY:  Suspending %s slices." % loginbase)
+                                               tmp = emailTxt.mailtxt.suspendSlices
+                                               sbj = tmp[0] 
+                                               msg = tmp[1] % {'loginbase': loginbase}
+                                               plc.suspendSlices(node)
+                                               self.squeezed[loginbase] = (time.time(), "freeze")
+                                               mailer.email(sbj, msg, target)  
+                                               self.emailed[node] = ("freeze", time.time())    
+                                               return
 
                        # Find the bucket the node is in and send appropriate email
                        # to approriate list of people.