# 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 *
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,
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 *
import rt
# Correlates input with policy to form actions
import policy
-import soltesz
+import moncommands
+import database
import plc
import syncplcdb
# list will be monitored.
runningthreads = {}
# Seconds between checking threads
-WATCHSLEEP = 10
+WATCHSLEEP = 5
# Set up Logging
logger = logging.getLogger("monitor")
######### 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])
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')