X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=findbad.py;h=b76df4c76e7725db88171991d848f2ebd0de4daa;hb=125c27b9121122663bada7e36eb2a00c95362d18;hp=9b348bb415df028cd6c85a5fe6c0b55760027f96;hpb=4df3989d4aee44cb6e36169ac69ba097436f7b15;p=monitor.git diff --git a/findbad.py b/findbad.py index 9b348bb..b76df4c 100755 --- a/findbad.py +++ b/findbad.py @@ -8,17 +8,17 @@ from datetime import datetime,timedelta import threadpool import threading -from monitor import util -from monitor.util import command +from monitor.util import file +from pcucontrol.util import command from monitor import config -from monitor.database.info.model import FindbadNodeRecordSync, FindbadNodeRecord, session +from monitor.database.info.model import FindbadNodeRecord, session from monitor.sources import comon from monitor.wrapper import plc, plccache from monitor.scanapi import * -from nodequery import verify,query_to_dict,node_select +from monitor.query import verify,query_to_dict,node_select import traceback from monitor.common import nmap_port_status @@ -53,9 +53,10 @@ def checkAndRecordState(l_nodes, cohash): # CREATE all the work requests for nodename in l_nodes: - fbnodesync = FindbadNodeRecordSync.findby_or_create(hostname=nodename, if_new_set={'round':0}) - node_round = fbnodesync.round - fbnodesync.flush() + #fbnodesync = FindbadNodeRecordSync.findby_or_create(hostname=nodename, if_new_set={'round':0}) + #node_round = fbnodesync.round + node_round = global_round - 1 + #fbnodesync.flush() if node_round < global_round or config.force: # recreate node stats when refreshed @@ -86,16 +87,16 @@ def checkAndRecordState(l_nodes, cohash): print "All results collected." break - print FindbadNodeRecordSync.query.count() + #print FindbadNodeRecordSync.query.count() print FindbadNodeRecord.query.count() session.flush() def main(): global global_round - fbsync = FindbadNodeRecordSync.findby_or_create(hostname="global", - if_new_set={'round' : global_round}) - global_round = fbsync.round + #fbsync = FindbadNodeRecordSync.findby_or_create(hostname="global", + # if_new_set={'round' : global_round}) + #global_round = fbsync.round if config.increment: # update global round number to force refreshes across all nodes @@ -111,31 +112,31 @@ def main(): #cohash = cotop.coget(cotop_url) l_nodes = plccache.l_nodes if config.nodelist: - f_nodes = util.file.getListFromFile(config.nodelist) + f_nodes = file.getListFromFile(config.nodelist) l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes) elif config.node: f_nodes = [config.node] l_nodes = filter(lambda x: x['hostname'] in f_nodes, l_nodes) elif config.nodegroup: ng = api.GetNodeGroups({'name' : config.nodegroup}) - l_nodes = api.GetNodes(ng[0]['node_ids']) + l_nodes = plccache.GetNodesByIds(ng[0]['node_ids']) elif config.site: - site = api.GetSites(config.site) - l_nodes = api.GetNodes(site[0]['node_ids'], ['hostname']) + site = plccache.GetSitesByName([config.site]) + l_nodes = plccache.GetNodesByIds(site[0]['node_ids']) elif config.sitelist: site_list = config.sitelist.split(',') - sites = api.GetSites(site_list) + sites = plccache.GetSitesByName(site_list) node_ids = [] for s in sites: node_ids += s['node_ids'] - l_nodes = api.GetNodes(node_ids, ['hostname']) + l_nodes = plccache.GetNodesByIds(node_ids) l_nodes = [node['hostname'] for node in l_nodes] # perform this query after the above options, so that the filter above # does not break. if config.nodeselect: - plcnodes = api.GetNodes({'peer_id' : None}, ['hostname']) + plcnodes = plccache.l_nodes plcnodes = [ node['hostname'] for node in plcnodes ] l_nodes = node_select(config.nodeselect, plcnodes, None) @@ -145,8 +146,9 @@ def main(): if config.increment: # update global round number to force refreshes across all nodes - fbsync.round = global_round - fbsync.flush() + #fbsync.round = global_round + #fbsync.flush() + pass return 0 @@ -175,6 +177,8 @@ if __name__ == '__main__': main() except Exception, err: print traceback.print_exc() + from monitor.common import email_exception + email_exception() print "Exception: %s" % err print "Saving data... exitting." sys.exit(0)