Beispiel #1
0
 def on_ok(self,host,res):
     
     if type(res) == dict:
         if 'verbose_override' not in res:
             data = res.copy()
             invocation = data['invocation']
             print data['invocation']
             if(invocation['module_name'] != 'check2restart'):
                 #print type(data['changed'])
                 if(data['changed'] > 0):
                     msg = 'the process - [%s:%s] of %s restart SUCCESSFULLY'
                     logging.info(msg % (invocation['module_name'],invocation['module_args'],host))
             else:
                 if(not data['changed']):
                     msg = 'the process - [%s] of %s exsits and  do nothing'
                     logging.info(msg % (invocation['module_args'],host))                                 
Beispiel #2
0
    def restartProcess(self):
        if type(self.target) == list:
            for item in self.target:
                changed = 0
                failures = 0
                unreachable = 0

                if item["errorType"] == "host":
                    res = playbook.PlayBook(
                        playbook="common.yml",
                        callbacks=notification.SMSCallbacks(),
                        runner_callbacks=notification.SMSRunnerCallbacks(self.stats),
                        stats=self.stats,
                        subset=item["host"],
                        # check = True
                    ).run()
                elif item["errorType"] == "process":
                    logging.info("ready to restart the process - [%(processList)s] of the %(host)s" % item)
                    res = playbook.PlayBook(
                        playbook="common.yml",
                        callbacks=notification.SMSCallbacks(),
                        runner_callbacks=notification.SMSRunnerCallbacks(self.stats),
                        stats=self.stats,
                        only_tags=item["processList"].split(","),
                        skip_tags=["common"],
                        subset=item["host"],
                    ).run()
                for host, status in res.items():
                    failures = status["failures"]
                    unreachable = status["unreachable"]
                    msg = ""
                    if item["errorType"] == "host":
                        msg += "after the host %(host)s crash down"
                    if failures == 0 and unreachable == 0:
                        msg += "all process - [%(processList)s] of %(host)s restart SUCCESSFULLY"
                        logging.info(msg % item)
                    else:
                        msg += (
                            "some process of %(host)s restart encounter problems,please check it manually in %(host)s"
                        )
                        logging.warn(msg % item)