split config.py and parser.py into two modules. updated all files to use the
[monitor.git] / monitor_policy.py
index a44e9a1..3dd244c 100644 (file)
@@ -1,7 +1,5 @@
-from config import config
-#print "policy"
-config = config()
-import soltesz
+import config
+import database
 import time
 import mailer
 from www.printbadnodes import cmpCategoryVal
@@ -42,18 +40,20 @@ PI=2
 USER=4
 ADMIN=8
 
+from unified_model import *
+
 class Merge:
        def __init__(self, l_merge):
                self.merge_list = l_merge
 
                # the hostname to loginbase mapping
-               self.plcdb_hn2lb = soltesz.dbLoad("plcdb_hn2lb")
+               self.plcdb_hn2lb = database.dbLoad("plcdb_hn2lb")
 
                # Previous actions taken on nodes.
-               self.act_all = soltesz.if_cached_else(1, "act_all", lambda : {})
-               self.findbad = soltesz.if_cached_else(1, "findbad", lambda : {})
+               self.act_all = database.if_cached_else(1, "act_all", lambda : {})
+               self.findbad = database.if_cached_else(1, "findbad", lambda : {})
 
-               self.cache_all = soltesz.if_cached_else(1, "act_all", lambda : {})
+               self.cache_all = database.if_cached_else(1, "act_all", lambda : {})
                self.sickdb = {}
                self.mergedb = {}
 
@@ -255,8 +255,8 @@ class RT:
 class Diagnose:
        def __init__(self, record_list):
                self.record_list = record_list
-               self.plcdb_hn2lb = soltesz.dbLoad("plcdb_hn2lb")
-               self.findbad = soltesz.if_cached_else(1, "findbad", lambda : {})
+               self.plcdb_hn2lb = database.dbLoad("plcdb_hn2lb")
+               self.findbad = database.if_cached_else(1, "findbad", lambda : {})
 
                self.diagnose_in = {}
                self.diagnose_out = {}
@@ -396,12 +396,13 @@ class Diagnose:
 
                # NOTE: these settings can be overridden by command line arguments,
                #       or the state of a record, i.e. if already in RT's Support Queue.
-               nodes_up = self.getUpAtSite(loginbase, d_diag_site)
+               pf = PersistFlags(loginbase, 1, db='site_persistflags')
+               nodes_up = pf.nodes_up
                if nodes_up < MINUP:
                        d_diag_site[loginbase]['config']['squeeze'] = True
 
                max_slices = self.getMaxSlices(loginbase)
-               num_nodes = self.getNumNodes(loginbase)
+               num_nodes = pf.nodes_total #self.getNumNodes(loginbase)
                # NOTE: when max_slices == 0, this is either a new site (the old way)
                #       or an old disabled site from previous monitor (before site['enabled'])
                if nodes_up < num_nodes and max_slices != 0:
@@ -824,12 +825,12 @@ class Diagnose:
 class Action:
        def __init__(self, diagnose_out):
                # the hostname to loginbase mapping
-               self.plcdb_hn2lb = soltesz.dbLoad("plcdb_hn2lb")
+               self.plcdb_hn2lb = database.dbLoad("plcdb_hn2lb")
 
                # Actions to take.
                self.diagnose_db = diagnose_out
                # Actions taken.
-               self.act_all   = soltesz.if_cached_else(1, "act_all", lambda : {})
+               self.act_all   = database.if_cached_else(1, "act_all", lambda : {})
 
                # A dict of actions to specific functions. PICKLE doesnt' like lambdas.
                self.actions = {}
@@ -866,7 +867,8 @@ class Action:
                        print err
                        if config.policysavedb:
                                print "Saving Databases... act_all"
-                               soltesz.dbDump("act_all", self.act_all)
+                               database.dbDump("act_all", self.act_all)
+                               database.dbDump("diagnose_out", self.diagnose_db)
                        sys.exit(1)
 
                #print_stats("sites_observed", stats)
@@ -878,10 +880,11 @@ class Action:
 
                if config.policysavedb:
                        print "Saving Databases... act_all"
-                       #soltesz.dbDump("policy.eventlog", self.eventlog)
+                       #database.dbDump("policy.eventlog", self.eventlog)
                        # TODO: remove 'diagnose_out', 
                        #       or at least the entries that were acted on.
-                       soltesz.dbDump("act_all", self.act_all)
+                       database.dbDump("act_all", self.act_all)
+                       database.dbDump("diagnose_out", self.diagnose_db)
 
        def accumSites(self):
                """
@@ -1058,6 +1061,7 @@ class Action:
                                if ticket_id == 0:
                                        # error.
                                        print "ticket_id == 0 for %s %s" % (loginbase, act_record['nodename'])
+                                       import os
                                        os._exit(1)
                                        pass
 
@@ -1084,11 +1088,11 @@ class Action:
                                i_nodes_actedon += 1
                
                if config.policysavedb:
-                       print "Saving Databases... act_all, diagnose_out"
-                       soltesz.dbDump("act_all", self.act_all)
+                       #print "Saving Databases... act_all, diagnose_out"
+                       #database.dbDump("act_all", self.act_all)
                        # remove site record from diagnose_out, it's in act_all as done.
                        del self.diagnose_db[loginbase]
-                       #soltesz.dbDump("diagnose_out", self.diagnose_db)
+                       #database.dbDump("diagnose_out", self.diagnose_db)
 
                print "sleeping for 1 sec"
                time.sleep(1)