changes for 3.0
[monitor.git] / diagnose.py
index 70bdc38..ca4345e 100755 (executable)
@@ -5,7 +5,7 @@
 # Faiyaz Ahmed <faiyaza@cs.princeton.edu>
 # Stephen Soltesz <soltesz@cs.princeton.edu>
 #
-# $Id$
+# $Id: diagnose.py,v 1.1 2007/08/08 13:36:46 soltesz Exp $
 
 import sys
 from threading import *
@@ -15,11 +15,11 @@ import Queue
 from sets import Set
 
 # Global config options
-from config import config
-from optparse import OptionParser
-parser = OptionParser()
+import parser as parsermodule
+parser = parsermodule.getParser()
 
 parser.set_defaults(nodelist=None, 
+                                       refresh=False,
                                        cachert=False, 
                                        cachenodes=False, 
                                        blacklist=None, 
@@ -27,18 +27,18 @@ parser.set_defaults(nodelist=None,
 
 parser.add_option("", "--nodelist", dest="nodelist", metavar="filename",
                                        help="Read nodes to act on from specified file")
-parser.add_option("", "--cachert", action="store_true",
+parser.add_option("", "--refresh", action="store_true", dest="refresh",
+                                       help="Refresh the cached values")
+parser.add_option("", "--cachert", action="store_true", dest="cachert",
                                        help="Cache the RT database query")
-parser.add_option("", "--cachenodes", action="store_true",
+parser.add_option("", "--cachenodes", action="store_true", dest="cachenodes",
                                        help="Cache node lookup from PLC")
 parser.add_option("", "--ticketlist", dest="ticketlist",
                                        help="Whitelist all RT tickets in this file")
 parser.add_option("", "--blacklist", dest="blacklist",
                                        help="Blacklist all nodes in this file")
 
-config = config(parser)
-print "bcalling parse_args"
-config.parse_args()
+config = parsermodule.parse_args(parser)
 
 # daemonize and *pid
 #from util.process import * 
@@ -47,7 +47,8 @@ config.parse_args()
 import rt
 # Correlates input with policy to form actions
 import policy
-import soltesz
+import moncommands
+import database 
 import plc
 import syncplcdb
 
@@ -64,7 +65,7 @@ POLSLEEP=10
 # list will be monitored.
 runningthreads = {}
 # Seconds between checking threads
-WATCHSLEEP = 10
+WATCHSLEEP = 5
  
 # Set up Logging
 logger = logging.getLogger("monitor")
@@ -150,9 +151,10 @@ def main():
 
        #########  GET NODES    ########################################
        logger.info('Get Nodes from PLC')
-       print "getnode from plc"
-       l_plcnodes = soltesz.if_cached_else(config.cachenodes, "l_plcnodes",
-                               lambda : syncplcdb.create_plcdb() )
+       print "getnode from plc: %s %s %s" % (config.debug, config.cachenodes, config.refresh)
+       l_plcnodes = database.if_cached_else_refresh(config.cachenodes, 
+                                                               config.refresh, "l_plcnodes",
+                                                               lambda : syncplcdb.create_plcdb() )
 
        s_plcnodenames = Set([x['hostname'] for x in l_plcnodes])
 
@@ -176,14 +178,17 @@ def main():
 
        print "len of l_nodes: %d" % len(l_nodes)
        # Minus blacklisted ones..
-       l_blacklist = soltesz.if_cached_else(1, "l_blacklist", lambda : [])
-       l_ticket_blacklist = soltesz.if_cached_else(1,"l_ticket_blacklist",lambda : [])
+       l_blacklist = database.if_cached_else(1, "l_blacklist", lambda : [])
+       l_ticket_blacklist = database.if_cached_else(1,"l_ticket_blacklist",lambda : [])
        l_nodes  = filter(lambda x : not x['hostname'] in l_blacklist, l_nodes)
 
        logger.info('Get Tickets from RT')
        #######  RT tickets    #########################################
-       t = soltesz.MyTimer()
-       ad_dbTickets = soltesz.if_cached_else(config.cachert, "ad_dbTickets", rt.rt_tickets)
+       t = moncommands.MyTimer()
+       ad_dbTickets = database.if_cached_else_refresh(config.cachert, config.refresh, "ad_dbTickets", rt.rt_tickets)
+       if ad_dbTickets == "":
+               print "ad_dbTickets failed..."
+               sys.exit(1)
        print "Getting tickets from RT took: %f sec" % t.diff() ; del t
 
        logger.info('Start Merge/RT/Diagnose threads')