Esempio n. 1
0
    def do_job(self):
        try:
            job_id = self.a_job.get_id()
            service_name = self.a_job.get_service_name()
            healthy_code = self.a_job.do_all_check()

            # Refresh job status
            Logger.report('job_id[%s] [%s] is healthy_code[%s]' % (job_id, service_name, healthy_code))
            self.status_holder.set_one_status(job_id, healthy_code, self.a_job.get_check_cmd_healthy_code())

            # Success
            if healthy_code is StatusCode.GREEN_CODE:
                return

            # Monitor operation occur error
            if healthy_code == StatusCode.WHITE_CODE or healthy_code == StatusCode.YELLOW_CODE:
                content = 'job_id[%s] [%s], healthy_code[%s] cat not be monitored successfully' % (job_id, service_name, healthy_code)
                Logger.error(content)
                SendMail.send(self.a_job.get_mail_receiver(), service_name, content)
                return

            # Do not need to be recovered
            if not self.a_job.get_auto_recover():
                return

            # Stopped process
            stopped = self.a_job.stop()
            if stopped is None:
                content = 'job_id[%s] [%s] stop failed' % (job_id, self.a_job.get_service_name())
                Logger.info(content)
                return

            # Check relies
            relies = self.a_job.get_all_rely()
            if not self.status_holder.is_group_healthy(relies):
                content = 'services job_id[%s] [%s] relying is not healthy' % (job_id, self.a_job.get_service_name())
                Logger.info(content)
                return

            # Start process
            ok = self.a_job.start()
            if not ok:
                content = 'job_id[%s] [%s] start failed' % (job_id, self.a_job.get_service_name())
                Logger.info(content)
                return

            # Start ok
            content = 'job_id[%s] [%s] start success' % (job_id, self.a_job.get_service_name())
            Logger.info(content)
            SendMail.send(self.a_job.get_mail_receiver(), self.a_job.get_service_name(), content)
        except Exception, e:
            Logger.error(e.message)
Esempio n. 2
0
def gen_invalid_warn():
    warncontent = "\r\n".join(invalidtask.values())
    sendm = SendMail()
    sendm.settitle("邮件关闭提醒")
    sendm.settocopy(["*****@*****.**"])
    body = warncontent + "\r\n当前的配置状态请查看附件;若不想关闭,请到%s修改%s\r\n,确保截止日期大于当前日期且设置开关状态为on\r\n" % (
        sendm.hostname,
        task_status,
    )
    print body
    return 0
    sendm.setbody(body)
    sendm.setattach(task_status)  # 发送当前的配置状态
    sendm.send()
Esempio n. 3
0
    def sendBookInfo(self):
        '''将预约成功信息发送到邮箱'''
        seat_name = self.book_result['data']['list']['spaceInfo']['name']
        book_time = self.book_result['data']['list']['beginTime']['date']
        deadline = time.mktime(time.strptime(book_time,
                                             '%Y-%m-%d %H:%M:%S')) + 1800
        deadline = time.strftime(
            "%Y-%m-%d %H:%M:%S",
            time.localtime(deadline))  # 格式化成 2020-09-16 19:45:33 形式

        mail = SendMail()
        mail.smtp_server = self.stu.smtp_server
        mail.username = self.stu.from_email
        mail.password = self.stu.from_pw
        mail.to_email = self.stu.to_email
        mail.subject = f'已成功预约 {seat_name} 号座位'
        mail.message = (f'已成功为您预约了位于三楼平层北区的 {seat_name} 号座位~\n\n'
                        f'预约开始时间: {book_time}\n'
                        f'请务必于 {deadline} 之前抵达图书馆并签到\n\n'
                        '“While there\'s life, there\'s hope.”\n'
                        '    ― Marcus Tullius Cicero\n')

        mail.send()