changes for 3.0
[monitor.git] / unified_model.py
index e237bc9..df4024e 100755 (executable)
@@ -36,7 +36,11 @@ def cmpValMap(v1, v2, map):
                raise Exception("No index %s or %s in map" % (v1, v2))
 
 def cmpCategoryVal(v1, v2):
-       map = array_to_priority_map([ None, 'ALPHA', 'PROD', 'OLDBOOTCD', 'UNKNOWN', 'FORCED', 'ERROR', ])
+       # Terrible hack to manage migration to no more 'ALPHA' states.
+       if v1 == 'ALPHA': v1 = "PROD"
+       if v2 == 'ALPHA': v2 = "PROD"
+       #map = array_to_priority_map([ None, 'PROD', 'ALPHA', 'OLDBOOTCD', 'UNKNOWN', 'FORCED', 'ERROR', ])
+       map = array_to_priority_map([ None, 'ALPHA', 'PROD', 'OLDPROD', 'OLDBOOTCD', 'UNKNOWN', 'FORCED', 'ERROR', ])
        return cmpValMap(v1,v2,map)
 
 
@@ -230,7 +234,7 @@ class PersistMessage(Message):
                        #print "creating new object"
                        obj = super(PersistMessage, typ).__new__(typ, [id, subject, message, via_rt], **kwargs)
                        obj.id = id
-                       obj.actiontracker = Recent(3*60*60*24)
+                       obj.actiontracker = Recent(1*60*60*24)
                        obj.ticket_id = None
 
                if 'ticket_id' in kwargs and kwargs['ticket_id'] is not None:
@@ -259,6 +263,7 @@ class PersistMessage(Message):
                        self.save()
                else:
                        # NOTE: only send a new message every week, regardless.
+                       # NOTE: can cause thank-you messages to be lost, for instance when node comes back online within window.
                        print "Not sending to host b/c not within window of %s days" % (self.actiontracker.withintime // (60*60*24))
 
 class MonitorMessage(object):
@@ -350,7 +355,7 @@ class PersistSitePenalty(SitePenalty):
 
                #print pm
                if id in pm:
-                       print "Using existing object"
+                       print "PersistSitePenalty Using existing object"
                        obj = pm[id]
                else:
                        print "creating new object"
@@ -423,7 +428,11 @@ class Record(object):
        def severity(self):
                category = self.data['category']
                prev_category = self.data['prev_category']
-               #print "SEVERITY: ", category, prev_category
+               print "SEVERITY: ", category, prev_category
+               try:
+                       print "SEVERITY state: ", self.data['state'], self.data['prev_state']
+               except:
+                       print "SEVERITY state: unknown unknown"
                val = cmpCategoryVal(category, prev_category)
                return val 
 
@@ -509,6 +518,7 @@ class Record(object):
                else:
                        print "takeAction: increasing penalty for %s"%self.hostname
                        pp.increase()
+               print "takeAction: applying penalty to %s as index %s"% (self.hostname, index)
                pp.index = index
                pp.apply(self.hostname)
                pp.save()
@@ -539,6 +549,8 @@ class Record(object):
                                                                 self.data['message'][1] % self.data['args'],
                                                                 True, db='monitor_persistmessages',
                                                                 ticket_id=ticket_id)
+                       if self.data['stage'] == "improvement":
+                               message.reset()
                        return message
                else:
                        return None
@@ -556,14 +568,17 @@ class Record(object):
                if ADMIN & roles:
                        contacts += [config.email]
                if TECH & roles:
-                       contacts += [TECHEMAIL % self.loginbase]
+                       #contacts += [TECHEMAIL % self.loginbase]
+                       contacts += plc.getTechEmails(self.loginbase)
                if PI & roles:
-                       contacts += [PIEMAIL % self.loginbase]
+                       #contacts += [PIEMAIL % self.loginbase]
+                       contacts += plc.getPIEmails(self.loginbase)
                if USER & roles:
+                       contacts += plc.getSliceUserEmails(self.loginbase)
                        slices = plc.slices(self.loginbase)
                        if len(slices) >= 1:
-                               for slice in slices:
-                                       contacts += [SLICEMAIL % slice]
+                               #for slice in slices:
+                               #       contacts += [SLICEMAIL % slice]
                                print "SLIC: %20s : %d slices" % (self.loginbase, len(slices))
                        else:
                                print "SLIC: %20s : 0 slices" % self.loginbase