import string
import time
import socket
+import util.file
+import plc
+import sets
import signal
+import traceback
+from nodequery import pcu_select
#old_handler = signal.getsignal(signal.SIGCHLD)
#
#orig_sig_handler = signal.signal(signal.SIGCHLD, sig_handler)
-from config import config
-from optparse import OptionParser
-parser = OptionParser()
-parser.set_defaults(filename=None,
- increment=False,
- pcuid=None,
- dbname="findbadpcus",
- cachenodes=False,
- refresh=False,
- )
-parser.add_option("-f", "--nodelist", dest="filename", metavar="FILE",
- help="Provide the input file for the node list")
-parser.add_option("", "--pcuid", dest="pcuid", metavar="id",
- help="Provide the id for a single pcu")
-parser.add_option("", "--cachenodes", action="store_true",
- help="Cache node lookup from PLC")
-parser.add_option("", "--dbname", dest="dbname", metavar="FILE",
- help="Specify the name of the database to which the information is saved")
-parser.add_option("", "--refresh", action="store_true", dest="refresh",
- help="Refresh the cached values")
-parser.add_option("-i", "--increment", action="store_true", dest="increment",
- help="Increment round number to force refresh or retry")
-config = config(parser)
-config.parse_args()
# QUERY all nodes.
COMON_COTOPURL= "http://summer.cs.princeton.edu/status/tabulator.cgi?" + \
import reboot
from reboot import pcu_name
-import soltesz
+import database
+import moncommands
import plc
import comon
import threadpool
except:
try:
print "GetPCU from file %s" % pcuname
- l_pcus = soltesz.dbLoad("pculist")
+ l_pcus = database.dbLoad("pculist")
for i in l_pcus:
if i['pcu_id'] == pcuname:
l_pcu = i
except:
- import traceback
traceback.print_exc()
l_pcu = None
l_node = plc.getNodes(node_ids, ['hostname', 'last_contact', 'node_id', 'ports'])
except:
try:
- plc_nodes = soltesz.dbLoad("l_plcnodes")
+ plc_nodes = database.dbLoad("l_plcnodes")
for n in plc_nodes:
if n['node_id'] in node_ids:
l_node.append(n)
except:
- import traceback
traceback.print_exc()
l_node = None
d_site = d_site[0]
except:
try:
- plc_sites = soltesz.dbLoad("l_plcsites")
+ plc_sites = database.dbLoad("l_plcsites")
for site in plc_sites:
if site['site_id'] == site_id:
d_site = site
break
except:
- import traceback
traceback.print_exc()
values = None
continue_probe = False
except:
b_except = True
- import traceback
traceback.print_exc()
continue_probe = False
#### RUN NMAP ###############################
if continue_probe:
- nmap = soltesz.CMD()
- (oval,eval) = nmap.run_noexcept("nmap -oG - -P0 -p22,23,80,443,5869,16992 %s | grep Host:" % pcu_name(values))
+ nmap = moncommands.CMD()
+ (oval,eval) = nmap.run_noexcept("nmap -oG - -P0 -p22,23,80,443,5869,9100,16992 %s | grep Host:" % pcu_name(values))
# NOTE: an empty / error value for oval, will still work.
(values['portstatus'], continue_probe) = nmap_portstatus(oval)
else:
print values
errors = values
print "____________________________________"
- import traceback
errors['traceback'] = traceback.format_exc()
print errors['traceback']
count += 1
print "%d %s %s" % (count, nodename, externalState['nodes'][pcu_id]['values'])
- soltesz.dbDump(config.dbname, externalState)
+ database.dbDump(config.dbname, externalState)
if errors is not None:
pcu_id = "id_%s" % nodename
errorState[pcu_id] = errors
- soltesz.dbDump("findbadpcu_errors", errorState)
+ database.dbDump("findbadpcu_errors", errorState)
# this will be called when an exception occurs within a thread
def handle_exception(request, result):
global count
global_round = externalState['round']
- tp = threadpool.ThreadPool(20)
+ tp = threadpool.ThreadPool(10)
# CREATE all the work requests
for pcuname in l_pcus:
pass
# WAIT while all the work requests are processed.
+ begin = time.time()
while 1:
try:
time.sleep(1)
tp.poll()
+ # if more than two hours
+ if time.time() - begin > (60*60*1):
+ print "findbadpcus.py has run out of time!!!!!!"
+ database.dbDump(config.dbname, externalState)
+ os._exit(1)
except KeyboardInterrupt:
print "Interrupted!"
break
def main():
global externalState
- l_pcus = soltesz.if_cached_else_refresh(1, config.refresh, "pculist", lambda : plc.GetPCUs())
- externalState = soltesz.if_cached_else(1, config.dbname, lambda : externalState)
+ l_pcus = database.if_cached_else_refresh(1, config.refresh, "pculist", lambda : plc.GetPCUs())
+ externalState = database.if_cached_else(1, config.dbname, lambda : externalState)
cohash = {}
if config.increment:
# update global round number to force refreshes across all nodes
externalState['round'] += 1
- if config.filename == None and config.pcuid == None:
+ if config.site is not None:
+ api = plc.getAuthAPI()
+ site = api.GetSites(config.site)
+ l_nodes = api.GetNodes(site[0]['node_ids'], ['pcu_ids'])
+ pcus = []
+ for node in l_nodes:
+ pcus += node['pcu_ids']
+ # clear out dups.
+ l_pcus = [pcu for pcu in sets.Set(pcus)]
+ elif config.pcuselect is not None:
+ n, pcus = pcu_select(config.pcuselect)
+ # clear out dups.
+ l_pcus = [pcu for pcu in sets.Set(pcus)]
+
+ elif config.nodelist == None and config.pcuid == None:
print "Calling API GetPCUs() : refresh(%s)" % config.refresh
l_pcus = [pcu['pcu_id'] for pcu in l_pcus]
- elif config.filename is not None:
- l_pcus = config.getListFromFile(config.filename)
+ elif config.nodelist is not None:
+ l_pcus = util.file.getListFromFile(config.nodelist)
l_pcus = [int(pcu) for pcu in l_pcus]
elif config.pcuid is not None:
l_pcus = [ config.pcuid ]
return 0
-import logging
-logger = logging.getLogger("monitor")
-logger.setLevel(logging.DEBUG)
-fh = logging.FileHandler("monitor.log", mode = 'a')
-fh.setLevel(logging.DEBUG)
-formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
-fh.setFormatter(formatter)
-logger.addHandler(fh)
-
if __name__ == '__main__':
+ import logging
+ logger = logging.getLogger("monitor")
+ logger.setLevel(logging.DEBUG)
+ fh = logging.FileHandler("monitor.log", mode = 'a')
+ fh.setLevel(logging.DEBUG)
+ formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
+ fh.setFormatter(formatter)
+ logger.addHandler(fh)
+ import parser as parsermodule
+ parser = parsermodule.getParser()
+ parser.set_defaults(nodelist=None,
+ increment=False,
+ pcuid=None,
+ pcuselect=None,
+ site=None,
+ dbname="findbadpcus",
+ cachenodes=False,
+ refresh=False,
+ )
+ parser.add_option("-f", "--nodelist", dest="nodelist", metavar="FILE",
+ help="Provide the input file for the node list")
+ parser.add_option("", "--site", dest="site", metavar="FILE",
+ help="Get all pcus associated with the given site's nodes")
+ parser.add_option("", "--pcuselect", dest="pcuselect", metavar="FILE",
+ help="Query string to apply to the findbad pcus")
+ parser.add_option("", "--pcuid", dest="pcuid", metavar="id",
+ help="Provide the id for a single pcu")
+
+ parser.add_option("", "--cachenodes", action="store_true",
+ help="Cache node lookup from PLC")
+ parser.add_option("", "--dbname", dest="dbname", metavar="FILE",
+ help="Specify the name of the database to which the information is saved")
+ parser.add_option("", "--refresh", action="store_true", dest="refresh",
+ help="Refresh the cached values")
+ parser.add_option("-i", "--increment", action="store_true", dest="increment",
+ help="Increment round number to force refresh or retry")
+ parser = parsermodule.getParser(['defaults'], parser)
+ config = parsermodule.parse_args(parser)
try:
# NOTE: evidently, there is a bizarre interaction between iLO and ssh
# when LANG is set... Do not know why. Unsetting LANG, fixes the problem.
main()
time.sleep(1)
except Exception, err:
- import traceback
traceback.print_exc()
print "Exception: %s" % err
print "Saving data... exitting."
- soltesz.dbDump(config.dbname, externalState)
+ database.dbDump(config.dbname, externalState)
sys.exit(0)