deprecate www directory and its legacy scripts
[monitor.git] / pcubad.py
index 9f0468c..085389f 100755 (executable)
--- 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