X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=pcubad.py;h=085389faa8a794b520c8c7818e5dda1937a2f8a0;hb=ecea36bbf6aad3bbd3e544d336b89a45cff4ab34;hp=9f0468cd2545a7112080960c610063053eef9cb0;hpb=c9d06f3b274ecbc092a0b3eb1f5ceb6c0f734aad;p=monitor.git diff --git a/pcubad.py b/pcubad.py index 9f0468c..085389f 100755 --- a/pcubad.py +++ b/pcubad.py @@ -17,7 +17,7 @@ from monitor.wrapper import plc,plccache from monitor.const import MINUP from monitor.common import * -from nodequery import verify,query_to_dict,node_select +from monitor.query import verify,query_to_dict,node_select from monitor.model import * api = plc.getAuthAPI() @@ -40,10 +40,8 @@ def main2(config): l_pcus = [pcu for pcu in sets.Set(pcus)] elif config.node: - l_nodes = plccache.GetNodeByName(config.node) - pcus = [] - for node in l_nodes: - pcus += node['pcu_ids'] + node = plccache.GetNodeByName(config.node) + pcus = node['pcu_ids'] # clear out dups. l_pcus = [pcu for pcu in sets.Set(pcus)] @@ -66,17 +64,20 @@ def check_pcu_state(rec, pcu): pcu_state = rec.reboot_trial_status - if ( pcu_state == 'NetDown' or pcu_state == 'Not_Run' or not ( pcu_state == 0 or pcu_state == "0" ) ) and \ - ( pcu.status == 'online' or pcu.status == 'good' ): - print "changed status from %s to offline" % pcu.status - pcu.status = 'offline' - pcu.last_changed = datetime.now() + # DOWN + if pcu_state not in [0, "0"] and pcu.status not in ['offline', 'down']: + print "changed status from %s to offline" % pcu.status + pcu.status = 'offline' + pcu.last_changed = datetime.now() - if ( pcu_state == 0 or pcu_state == "0" ) and pcu.status not in [ 'online', 'good' ]: + # ONLINE + if pcu_state in [0, "0"] and pcu.status not in [ 'online', 'good' ]: print "changed status from %s to online" % pcu.status pcu.status = 'online' pcu.last_changed = datetime.now() + + # STATE TRANSITIONS if pcu.status == 'online' and changed_greaterthan(pcu.last_changed, 0.5): #send thank you notice, or on-line notice. print "changed status from %s to good" % pcu.status @@ -87,12 +88,11 @@ def check_pcu_state(rec, pcu): # send down pcu notice print "changed status from %s to down" % pcu.status pcu.status = 'down' - pcu.last_changed = datetime.now() - if ( pcu.status == 'offline' or pcu.status == 'down' ) and changed_greaterthan(pcu.last_changed, 2*30): - print "changed status from %s to down" % pcu.status - pcu.status = 'down' - pcu.last_changed = datetime.now() +# if pcu.status in [ 'offline', 'down' ] and changed_greaterthan(pcu.last_changed, 2*30): +# print "changed status from %s to down" % pcu.status +# pcu.status = 'down' +# pcu.last_changed = datetime.now() def checkAndRecordState(l_pcus, l_plcpcus): count = 0 @@ -117,6 +117,7 @@ def checkAndRecordState(l_pcus, l_plcpcus): except: print "COULD NOT FIND FB record for %s" % reboot.pcu_name(d_pcu) import traceback + email_exception() print traceback.print_exc() # don't have the info to create a new entry right now, so continue. continue