added --node option throughout calls
[monitor.git] / grouprins.py
index cfefc6a..eb89e6a 100755 (executable)
 #  * do something else to them all.
 # 
 
-import plc
+from monitor import config
+from monitor import util
+from monitor import const
+from monitor import database
+from monitor import parser as parsermodule
+from monitor import reboot
+from monitor.wrapper import plc
 api = plc.getAuthAPI()
 
 import traceback
-import config
-import util.file
 from optparse import OptionParser
 
-import const
-from nodecommon import *
+from monitor.common import *
 from nodequery import verify,query_to_dict,node_select
-import database
-from unified_model import *
+from monitor.model import *
 import os
 
 import time
-import parser as parsermodule
 
-from model import *
 import bootman                 # debug nodes
-import reboot          # down nodes without pcu
-import mailmonitor     # down nodes with pcu
-from emailTxt import mailtxt
-#reboot.verbose = 0
+import mailmonitor     # down nodes without pcu
+from monitor.wrapper.emailTxt import mailtxt
 import sys
 
 class Reboot(object):
@@ -75,6 +73,7 @@ class Reboot(object):
                                        return ret
 
                                except Exception,e:
+                                       email_exception()
                                        print traceback.print_exc(); print e
 
                                        # NOTE: this failure could be an implementation issue on
@@ -97,6 +96,7 @@ class Reboot(object):
                                        return ret
 
                                except Exception,e:
+                                       email_exception()
                                        print traceback.print_exc(); print e
 
                                        # NOTE: this failure could be an implementation issue on
@@ -140,6 +140,7 @@ class Reboot(object):
                try:
                        return mailmonitor.reboot(host)
                except Exception, e:
+                       email_exception(host)
                        print traceback.print_exc(); print e
                        return False
 
@@ -237,10 +238,11 @@ if config.node or config.nodelist:
        if config.node: hostnames = [ config.node ] 
        else: hostnames = util.file.getListFromFile(config.nodelist)
 
-fb = database.dbLoad("findbad")
+fbquery = FindbadNodeRecord.get_all_latest()
+fb_nodelist = [ n.hostname for n in fbquery ]
 
 if config.nodeselect:
-       hostnames = node_select(config.nodeselect, fb['nodes'].keys(), fb)
+       hostnames = node_select(config.nodeselect, fb_nodelist)
 
 if config.findbad:
        # rerun findbad with the nodes in the given nodes.
@@ -262,6 +264,7 @@ for host in hostnames:
                try:
                        node = api.GetNodes(host)[0]
                except:
+                       email_exception()
                        print traceback.print_exc(); 
                        print "FAILED GETNODES for host: %s" % host
                        continue
@@ -286,6 +289,7 @@ for host in hostnames:
                                        # todo: send thank you, etc.
                                        mailmonitor.reboot(host)
                                except Exception, e:
+                                       email_exception()
                                        print traceback.print_exc(); print e
 
                                continue
@@ -356,6 +360,7 @@ for host in hostnames:
                print "Killed by interrupt"
                sys.exit(0)
        except:
+               email_exception()
                print traceback.print_exc();
                print "Continuing..."