def send_link_bot(self, key, id, text): xiaoding = DingtalkChatbot(self.url, secret=self.secret) xiaoding.send_link( title='接口详情', text='{}请点击我......'.format(text), message_url='http://zhuzhanhao.cn:8000/detail/?{}={}'.format( key, id))
def POST(self): client_data = web.input() filedir = 'file' # change this to the directory you want to store the file in. try: #解析相关参数 appname = client_data.appname appname.encode('utf-8') appversion = client_data.appversion crashguid = client_data.crashguid crashrpt = client_data.crashrpt md5 = client_data.md5 md51 = HashCheck(crashrpt) if md5 != md51: return {'error'} filename = crashguid + ".zip" path = filedir + '/' + appname + '/' + appversion #判断路径是否存在,不存在则创建目录 if not os.path.exists(path): os.makedirs(path) #写文件 fout = open(path + '/' + filename, 'wb') #fout.write(x.myfile.file.read()) # writes the uploaded file to the newly created file. fout.write(crashrpt) fout.close() # closes the file, upload complete. #输出重定向 #raise web.seeother('/') #告警发送 data = { 'appname': appname, 'appversion': appversion, 'filename': filename } linkurl = "http://up.yueniucj.com:8080/download?" + urllib.urlencode( data) # *************************************这里填写自己钉钉群自定义机器人的token***************************************** token = "f79aa29ca29a30bd70319adfcd8aef14e4b65a377b417a5a9c738baa9531f455" webhook = 'https://oapi.dingtalk.com/robot/send?access_token=' + token # 用户手机号列表 at_mobiles = ['15010660722'] # 初始化机器人小丁 xiaoding = DingtalkChatbot(webhook) # link xiaoding.send_link(title=appname + '崩溃报告来啦!!!', text='版本号:' + appversion, message_url=linkurl) return "upload success" except Exception as e: return {'exception'}
def send_link_bot(self,key, id, text): xiaoding = DingtalkChatbot(self.url,secret=self.secret) xiaoding.send_link(title='接口详情', text='{}请点击我......'.format(text), message_url='http://zhuzhanhao.cn:8000/detail/?{}={}'.format(key, id)) # if __name__ == "__main__": # DingNotice().send_ding("","") # DingNotice().send_text_bot()
class SendText: def __init__(self, webhook): # 初始化机器人小丁 self.xiaoding = DingtalkChatbot(webhook) def send(self): # Text消息@所有人 self.xiaoding.send_text(msg='我是打包机器人!', is_at_all=False) self.xiaoding.send_link(title='苹果打包地址', text='测试环境', message_url='https://www.com') self.xiaoding.send_link(title='安卓打包地址', text='测试环境', message_url='https://www..com')
if __name__ == '__main__': # WebHook地址 webhook = 'https://oapi.dingtalk.com/robot/send?access_token=59117d422a069d71c0297efd3263985398a8bb0e1dd971031f1628a46d327058' # 用户手机号列表 at_mobiles = ['15982317461'] # 初始化机器人小丁 xiaoding = DingtalkChatbot(webhook) # text xiaoding.send_text(msg='我就是小丁,小丁就是我!', is_at_all=True) xiaoding.send_text(msg='我就是小丁,小丁就是我!', at_mobiles=at_mobiles) # link xiaoding.send_link( title='万万没想到,某小璐竟然...', text='故事是这样子的...', message_url= 'http://www.kwongwah.com.my/?p=454748", pic_url="https://pbs.twimg.com/media/CEwj7EDWgAE5eIF.jpg' ) # markdown # 1、提醒所有人 xiaoding.send_markdown( title='氧气文字', text='#### 广州天气\n' '> 9度,西北风1级,空气良89,相对温度73%\n\n' '> ![美景](http://www.sinaimg.cn/dy/slidenews/5_img/2013_28/453_28488_469248.jpg)\n' '> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n', is_at_all=True) # 2、提醒指定手机用户,需要在text参数中@用户 xiaoding.send_markdown( title='氧气文字',
#!/usr/bin/python3 # -*- coding: utf-8 -*- __author__ = 'YaoKun' __time__ = '2019/11/15 15:05' import sys from dingtalkchatbot.chatbot import DingtalkChatbot # WebHook地址 webhook = 'https://oapi.dingtalk.com/robot/send?access_token=?' # 初始化机器人小丁 xiaoding = DingtalkChatbot(webhook) # Link消息 if __name__ == '__main__': title = sys.argv[1] text = sys.argv[2] message_url = sys.argv[3] xiaoding.send_link(title=title, text=text, message_url=message_url)
def xiaoding_pull(user, title, type, progress=None): """ type: commit、 close、approve、feedback """ if Webhook.objects.filter().first(): webhook_addr = Webhook.objects.get().webhook_addr xiaoding = DingtalkChatbot(webhook_addr) if DomainName.objects.filter().first(): domain_name = DomainName.objects.get().domain_name if type == 'commit': xiaoding.send_link(title=f"您好、{user}提交了审核内容", text=f'{title}', message_url=f'{domain_name}') elif type == 'approve': if progress == '2': xiaoding.send_link(title=f"您好、{user}已批准,请DBA处理", text=f'{title}', message_url=f'{domain_name}') elif progress == '1': xiaoding.send_link(title=f"您好、{user}审核未通过", text=f'{title}', message_url=f'{domain_name}') elif type == 'feedback': if progress == '3': xiaoding.send_link(title=f"您好、{user}正在处理中,请稍后", text=f'{title}', message_url=f'{domain_name}') elif progress == '4': xiaoding.send_link(title=f"您好、{user}处理完成", text=f'{title}', message_url=f'{domain_name}') elif type == 'close': if progress == '5': xiaoding.send_link(title=f"您好、{user}关闭了记录,请DBA不要处理", text=f'{title}', message_url=f'{domain_name}')
res = res + dsthost + '没有发生配置变动\n' def filter(lines): list = [] for line in lines: if "subscriber static name" not in line: list.append(line) return list if __name__ == '__main__': res = res + '--------------------执行结果----------------------\n\n' res = res + '执行自动化校对核心设备配置......\n\n' for host in open(r'/usr/script/iplist/hxiplist.txt').readlines(): dsthost = host.strip('\n') tod_conf_name = dsthost + '_' + str(today) + '.txt' yes_conf_name = dsthost + '_' + str(yesterday) + '.txt' yes_file = r'/usr/tftpboot/' + str(yesterday) + '/HX/' + yes_conf_name tod_file = r'/usr/tftpboot/' + str(today) + '/HX/' + tod_conf_name text1_lines = readline(yes_file) text2_lines = readline(tod_file) text3_lines = filter(text1_lines) text4_lines = filter(text2_lines) res = res + '执行' + dsthost + '校对函数......\n' isDiff = Compare(text3_lines, text4_lines, dsthost) if isDiff == True: fileurl = Upload(dsthost) xiaoding.send_link(title=dsthost + '_' + timea + '比对结果报告', text='点击查看', message_url=fileurl) xiaoding.send_text(msg=res)