def send_message(biz_cc_id, executor, notify_type, receivers, title, content): client = get_client_by_user_and_biz_id(executor, biz_cc_id) if 'weixin' in notify_type: kwargs = { 'receiver__username': receivers, 'data': { 'heading': title, 'message': content, } } result = client.cmsi.send_weixin(kwargs) if not result['result']: logger.error('taskflow send weixin, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) if 'sms' in notify_type: kwargs = { 'receiver__username': receivers, 'content': u"%s\n%s" % (title, content), } result = client.cmsi.send_sms(kwargs) if not result['result']: logger.error('taskflow send sms, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) if 'email' in notify_type: kwargs = { 'receiver__username': receivers, 'title': title, 'content': content, } result = client.cmsi.send_mail(kwargs) if not result['result']: logger.error('taskflow send mail, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) if 'voice' in notify_type: kwargs = { 'receiver__username': receivers, 'auto_read_message': u"%s\n%s" % (title, content), } result = client.cmsi.send_voice_msg(kwargs) if not result['result']: logger.error('taskflow send voice, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) return True
def send_message(self, msg_type, atom_node_name=''): template = self.template pipeline_inst = self.pipeline_instance executor = pipeline_inst.executor notify_type = json.loads(template.notify_type) receivers_list = template.get_notify_receivers_list(executor) receivers = ','.join(receivers_list) if msg_type == 'atom_failed': title = _(u"【标准运维APP通知】执行失败") content = _( u"您在【{cc_name}】业务中的任务【{task_name}】执行失败,当前失败节点是【{node_name}】," u"操作员是【{executor}】,请前往标准运维APP({url})查看详情!").format( cc_name=self.business.cc_name, task_name=pipeline_inst.name, node_name=atom_node_name, executor=executor, url=self.url) elif msg_type == 'task_finished': title = _(u"【标准运维APP通知】执行完成") content = _( u"您在【{cc_name}】业务中的任务【{task_name}】执行成功,操作员是【{executor}】," u"请前往标准运维APP({url})查看详情!").format( cc_name=self.business.cc_name, task_name=pipeline_inst.name, executor=executor, url=self.url) else: return False client = get_client_by_user_and_biz_id(executor, self.business.cc_id) if 'weixin' in notify_type: kwargs = { 'receiver__username': receivers, 'data': { 'heading': title, 'message': content, } } result = client.cmsi.send_weixin(kwargs) if not result['result']: logger.error('taskflow send weixin, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) if 'sms' in notify_type: kwargs = { 'receiver__username': receivers, 'content': u"%s\n%s" % (title, content), } result = client.cmsi.send_sms(kwargs) if not result['result']: logger.error('taskflow send sms, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) if 'mail' in notify_type: kwargs = { 'receiver__username': receivers, 'title': title, 'content': content, } result = client.cmsi.send_mail(kwargs) if not result['result']: logger.error('taskflow send mail, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) if 'voice' in notify_type: kwargs = { 'receiver__username': receivers, 'auto_read_message': u"%s\n%s" % (title, content), } result = client.cmsi.send_voice_msg(kwargs) if not result['result']: logger.error('taskflow send voice, kwargs=%s, result=%s' % (json.dumps(kwargs), json.dumps(result))) return True