merge recent v2 changes; migrating to v3
[monitor.git] / pcubad.py
index 16a8f4f..59dfe7a 100755 (executable)
--- a/pcubad.py
+++ b/pcubad.py
@@ -31,8 +31,8 @@ def main2(config):
 
        l_pcus = None
        if config.site is not None:
-               site = api.GetSites(config.site)
-               l_nodes = api.GetNodes(site[0]['node_ids'], ['pcu_ids'])
+               site = plccache.GetSitesByName([config.site])
+               l_nodes = plccache.GetNodesByIds(site[0]['node_ids'])
                pcus = []
                for node in l_nodes:
                        pcus += node['pcu_ids']
@@ -40,10 +40,8 @@ def main2(config):
                l_pcus = [pcu for pcu in sets.Set(pcus)]
 
        elif config.node:
-               l_nodes = api.GetNodes(config.node, ['pcu_ids'])
-               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)]
 
@@ -72,7 +70,7 @@ def check_pcu_state(rec, pcu):
                pcu.status = 'offline'
                pcu.last_changed = datetime.now()
 
-       if ( pcu_state == 0 or pcu_state == "0" ) and changed_lessthan(pcu.last_changed, 0.5) and pcu.status != 'online':
+       if ( pcu_state == 0 or pcu_state == "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()
@@ -117,6 +115,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