Example #1
0
def dingtalk(webhook, message: str):
    secret = 'SEC11b9...这里填写自己的加密设置密钥'  # 可选:创建机器人勾选“加签”选项时使用
    # 初始化机器人小丁
    #xiaoding = DingtalkChatbot(webhook)  # 方式一:通常初始化方式
    # xiaoding = DingtalkChatbot(webhook, secret=secret)  # 方式二:勾选“加签”选项时使用(v1.5以上新功能)
    ding = DingtalkChatbot(webhook, pc_slide=True)
    ding.send_text(msg='-%s' % message, is_at_all=False)
Example #2
0
 def __init__(self,
              token=None,
              keyWord=None,
              weiboRef=None,
              weiboCookie=None,
              weiboSCF=None,
              weixinToken=None):
     self.useDingTalk = False
     self.useWeibo = False
     self.useSCF = False
     self.useWeixin = False
     if token and keyWord:
         self.useDingTalk = True
         self.d = DingtalkChatbot(
             'https://oapi.dingtalk.com/robot/send?access_token=%s' % token)
         self.keyWord = keyWord
     if weiboRef and weiboCookie:
         self.useWeibo = True
         self.weibo = Weibo(weiboRef, weiboCookie)
     if weiboSCF:
         self.useSCF = True
         self.weiboSCF = weiboSCF
     if weixinToken:
         self.useWeixin = True
         self.wxurl = 'https://sc.ftqq.com/%s.send' % weixinToken
Example #3
0
def send_dingtalk_markdown(webhook, title, text):
    if (text is not None or text != ''):
        dingtalk = DingtalkChatbot(webhook)
        dingtalk.send_markdown(
            title=title,
            text=text,
            at_mobiles=['15257183801', '13738375762', '18310593253'])
Example #4
0
    def dingding(self, dic):
        # WebHook地址
        webhook = 'https://oapi.dingtalk.com/robot/send?access_token=e5cc9f86eb85e5c9caef97638c6b92c36e09123c541f77289a7840071146a463'
        # 初始化机器人小丁
        dingding = DingtalkChatbot(webhook)

        self.logger.info("开始发送钉钉.....")
        dic = dict(sorted(dic.items(), key=lambda x: x[0]))
        content = '[' + time.strftime('%Y-%m-%d',
                                      time.localtime()) + '日]Redis数据',

        data = ''
        for k, v in dic.items():
            data += "> **" + str(k) + "**  :  " + "<font color=#FF0000>" + str(
                v) + "</font> \n\n"

        try:
            dingding.send_markdown(
                title='Redis数据',
                text='# ' + str(content[0]) + '\n\n' + data,
            )
            self.logger.info("发送成功.....")
        except Exception as e:
            self.logger.info("发送失败.....")
            self.logger.info("失败原因:" + str(e))
            sys.exit(1)
Example #5
0
def send_msg(webhook, secret, msg):
    """
    :param webhook: 钉钉机器人webhook
    :param secret: 钉钉机器人secret
    :msg 消息对象
    """
    
    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(webhook, secret=secret)

    # 构建消息体
    btns = [
        CardItem(
            title=msg["btn_label"][0]['title'],
            url=msg["btn_label"][0]['url'],
        ),
        CardItem(
            title=msg["btn_label"][1]['title'],
            url=msg["btn_label"][1]['url'],
        )
    ]
    actioncard = ActionCard(
        title=msg["title"],
        text=msg["content"],
        btns=btns,
        btn_orientation=1,
        hide_avatar=0,
    )

    # 发送卡片消息
    xiaoding.send_action_card(actioncard)
Example #6
0
 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))
Example #7
0
def send_dingtalk(alert_type, params, is_at_all=False):
    """
    发送钉钉消息
    @webhook: "https://oapi.dingtalk.com/robot/send?access_token=bd92817749b11207820971bab315e0b46b59d1cf422f33e976495acf4aa89ef7"
    @msg: "发送消息"
    """
    exec_id = params['exec_id']
    dispatch_id = params['dispatch_id']
    dispatch_name = params['dispatch_name']
    update_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                time.localtime(params['update_time']))
    webhook = params['param_config']
    if alert_type == 1:
        sub = '调度id: %s执行成功' % dispatch_id
    else:
        sub = '调度id: %s执行失败' % dispatch_id
    content = '%s\n调度id: %s\n调度名称: %s\n执行id: %s\n执行时间: %s' % (
        sub, dispatch_id, dispatch_name, exec_id, update_time)
    try:
        bot = DingtalkChatbot(webhook)
        bot.send_text(msg=content, is_at_all=is_at_all)
        log.info("params: %s, 发送钉钉成功" % str({
            'exec_id': exec_id,
            'alert_type': alert_type
        }))
    except Exception as e:
        log.error("发送钉钉消息失败[ERROR: %s]" % e, exc_info=True)
Example #8
0
def job_ip():
    subp = subprocess.Popen('curl ip.42.pl/raw',
                            shell=True,
                            stdout=subprocess.PIPE)
    subp2 = subprocess.Popen('cat /etc/public_ip/public_ip.txt',
                             shell=True,
                             stdout=subprocess.PIPE)
    old_ip = subp2.stdout.readline().decode().strip()
    new_ip = subp.stdout.readline().decode().strip()
    while len(new_ip) == 0:
        subp = subprocess.Popen('curl ip.cip.cc',
                                shell=True,
                                stdout=subprocess.PIPE)
        new_ip = subp.stdout.readline().decode().strip()
    if new_ip == old_ip:
        f = open("/etc/public_ip/public_ip.txt", "w")
        print(old_ip, file=f)
    else:
        webhook = 'https://oapi.dingtalk.com/robot/send?access_token=d8e39e1882ce3cc441f6a74c761e488ab3e0d0ba883444dd8aef6079a37ca29a'
        secret = 'SEC5c6455acea1d51a5187d682cfd93bbc6d7d32d704ae717b31ea2c4b72e51db8f'
        xiaoding = DingtalkChatbot(webhook, secret=secret)
        at_mobiles = [18566744982]
        xiaoding.send_text(msg='公网IP已经变动,请添加白名单,公网IP:%s ' % (new_ip),
                           at_mobiles=at_mobiles)
        f = open("/etc/public_ip/public_ip.txt", "w")
        print(new_ip, file=f)
Example #9
0
def send_msg_to_dingding(msg='none'):
    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=%s' % os.environ[
        'DINGDING_TOKEN']
    secret = os.environ['DINGDING_SECRET']  # 可选:创建机器人勾选“加签”选项时使用
    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(webhook, secret=secret)
    xiaoding.send_text(msg=msg, is_at_all=False)
Example #10
0
def sendding(title, content):
    at_mobiles = ['186xxxx2487', '158xxxx3364']
    Dingtalk_access_token = 'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxx'
    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(Dingtalk_access_token)
    # Markdown消息@指定用户
    xiaoding.send_markdown(title=title, text=content, at_mobiles=at_mobiles)
Example #11
0
class DingTalkRobot(Robot):
    def __init__(self, webhook):
        self.bot = DingtalkChatbot(webhook)
        super().__init__()

    def send_text(self, msg):
        self.bot.send_text(msg, is_at_all=True)
Example #12
0
def send(message,at_mobiles=[]):
    #引用settings里面配置的钉钉群消息通知的Webhook地址:
    # webhook = 'https://oapi.dingtalk.com/robot/send?access_token=47306afa3a6574c1c0d4a3a8b33b717c93290ea27d2881c7fcc019df08e681b5'
    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=a557b417e2ba7eb81982451aa14010b42ad7102ef45b0ff5cf864a801d18a119'
    #初始化机器人小丁,方式一:通常初始化
    xiaoming = DingtalkChatbot(webhook)
    #text消息@所有人
    xiaoming.send_text(msg=("面试hello通知:%s"%message), at_mobiles = at_mobiles)
Example #13
0
def ding(text):
    from dingtalkchatbot.chatbot import DingtalkChatbot
    webhook = '这里放钉钉的token这里放钉钉的token这里放钉钉的token这里放钉钉的token'
    xiaoding = DingtalkChatbot(webhook)
    #前置信息可以包含在钉钉上设置的关键词,我这里是大家好
    news = '大家好!\n以下是今天的体彩预测:\n' + str(text)
    xiaoding.send_text(msg=news, is_at_all=True)
    print('进程结束:' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
Example #14
0
    def post_receive(self, alert):
        if alert.repeat:
            return

        ding = DingtalkChatbot(DING_WEBHOOK_URL)
        message = self._prepare_payload(alert)
        LOG.debug('DingTalk: %s', message)
        ding.send_text(msg='Received Alert {}'.format(message))
Example #15
0
class DingdingMes():
    def __init__(self, game_time):
        self.webhook = game_ding
        self.ding_robot = DingtalkChatbot(self.webhook)
        self.mes = "9人局预约:" + game_time

    def send_text(self, mobiles=["15757115453"]):
        self.ding_robot.send_text(self.mes, at_mobiles=mobiles)
 def __init__(self, run_type):
     self.run_type = run_type
     if run_type == 'auto':
         webhook = 'https://oapi.dingtalk.com/robot/send?access_token=998422738ca7d32f8641e9369da7f1b5545aa09c8fcec5ae17324e609c5d1af0'
         # webhook = 'https://oapi.dingtalk.com/robot/send?access_token=cb1ece248f594144a11bc0cf467ae4fd0f73beb3133f6a79b16d07ef23da0a59' # 调试机器人
     elif run_type == 'deploy':
         webhook = 'https://oapi.dingtalk.com/robot/send?access_token=16c4dbf613c5f1f288bbf695c1997ad41d37ad580d94ff1a0b7ceae6797bbc70'
         # webhook = 'https://oapi.dingtalk.com/robot/send?access_token=cb1ece248f594144a11bc0cf467ae4fd0f73beb3133f6a79b16d07ef23da0a59' # 调试机器人
     self.robot = DingtalkChatbot(webhook)
Example #17
0
def sendDingDing(msg, token, secret):
    log('正在发送钉钉机器人通知...')
    shijian = getTimeStr() + '\n'
    webhook = 'https://oapi.dingtalk.com/robot/send?access_token={0}'.format(
        token)
    secret = '{0}'.format(secret)
    xiaoding = DingtalkChatbot(webhook,
                               secret=secret)  # 方式二:勾选“加签”选项时使用(v1.5以上新功能)
    xiaoding.send_text(str(shijian) + str(msg), is_at_all=False)
Example #18
0
def send(message, at_mobiles=[]):
    # 引用 settings里面配置的钉钉群消息通知的WebHook地址:
    webhook = settings.DINGTALK_WEB_HOOK

    # 初始化机器人小丁, # 方式一:通常初始化方式
    xiaoding = DingtalkChatbot(webhook)

    # Text消息@所有人
    xiaoding.send_text(msg=('面试通知: %s' % message), at_mobiles=at_mobiles)
Example #19
0
 def __init__(self, webhook_url, secret):
     timestamp = str(round(time.time() * 1000))
     secret_enc = secret.encode('utf-8')
     string_to_sign = '{}\n{}'.format(timestamp, secret)
     string_to_sign_enc = string_to_sign.encode('utf-8')
     hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
     sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
     url = webhook_url + '&timestamp=%s&sign=%s' % (str(timestamp), sign)
     self.robot = DingtalkChatbot(url)
Example #20
0
def DingMsg(msg):
    #WebHook地址
    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=xxxx'

    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(webhook)

    #Text消息@所有人
    xiaoding.send_text(msg, is_at_all=True)
Example #21
0
def send_dingding(message):
    """
    利用钉钉推送公交信息
    :param message:
    :return:
    """
    webhook = "钉钉机器人的webhood"
    xiaoding = DingtalkChatbot(webhook)
    xiaoding.send_text(msg=message, is_at_all=True)
Example #22
0
def send_dingding(message):
    """
    利用钉钉推送公交信息
    :param message:
    :return:
    """
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=623a7fdc4d9e037895e4aeeb128de88c19ae32e2f314c4e4142c560bc6a271b9"
    xiaoding = DingtalkChatbot(webhook)
    xiaoding.send_text(msg=message, is_at_all=True)
Example #23
0
    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'}
Example #24
0
def send_msg(message, at_mobiles=[]):
    # 引用 settings 里面的 webhook 配置地址
    webhook = settings.DINGTALK_WEBHOOK
    secret = settings.DINGTALK_SECRET
    # 初始化一个机器人
    bot = DingtalkChatbot(webhook)
    # 示例2:如果机器人勾选了“加签”,需要传入 secret
    bot2 = DingtalkChatbot(webhook=webhook, secret=secret)

    bot.send_text(message, at_mobiles=at_mobiles, is_at_all=True)
Example #25
0
    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()
Example #26
0
def send_message(message):
    """和钉钉关联起来,给钉钉的群发消息"""

    # WebHook地址
    webhook = '{Webhook 地址}'  # 在{Webhook 地址}填入钉钉的Webhook 地址
    # 初始化机器人
    xiaoding = DingtalkChatbot(webhook)
    # 当前时间
    now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())  # time.localtime():计算机当地时间
    # Test消息@所有人
    xiaoding.send_text(msg=f"滴滴滴:{message} \n当前时间:{now_time}", is_at_all=False)  # "滴滴滴:"是钉钉的安全设置的自定义关键词
Example #27
0
def sen():
    if new != old:
        webhook = ''
        xiaoding = DingtalkChatbot(webhook)
        xiaoding.send_markdown(title='News',
                               text='### ' + titl + '\n'
                               'ITNews:' + new + '\n\n'
                               'Link:' + link)
        pickle.dump(new, open('summary.txt', 'wb'))
    else:
        print('Nothing')
Example #28
0
 def __init__(self, settings):
     self.settings = settings
     self.xiaoding = DingtalkChatbot(webhook=settings.get('WEBHOOK'))
     self.max_failed = settings.get('PROXY_MAX_FAILED_NUM')
     self.redis = redis.Redis(host=settings.get('REDIS_URI_'),
                              password=settings.get('REDIS_PASSWORD_'))
     #self.redis = redis.Redis(db=1)
     self.eff_duration = settings.get('EFF_DURATION') * 60
     self.no_answer_id = open('./json_file/no_answer_id.txt',
                              'a',
                              encoding='utf-8')
Example #29
0
def send_url_msg(title, url):
    """将登陆连接以Markdown发送至手机,点击后即可完成登陆"""

    # 获取钉钉消息信息
    webhook = global_config.getRaw('messenger', 'webhook')
    secret = global_config.getRaw('messenger', 'secret')
    
    xiaoding = DingtalkChatbot(webhook, secret=secret)
    xiaoding.send_markdown(
        title=title,
        text="[%s](%s)" % (url, url)
    )
Example #30
0
def ding_message():
    '''初始化钉钉对象'''
    xiaoding = DingtalkChatbot(webhook)
    at_mobiles = ['1373633366']
    '''获取所有服务的app名和服务类型,并存到字典中'''
    applicationLists = get_applications()
    # print(applicationLists)
    '''轮询application,查询每个application在过去五分钟内的总错误数,并通过钉钉报警'''
    for app in applicationLists:
        application_name = app['applicationName']
        service_type = app['serviceType']
        error_count = update_servermap(application_name,
                                       from_time=From_TimeStamp,
                                       to_time=To_TimeStamp,
                                       serviceType=service_type)[0]
        slow_count = update_servermap(application_name,
                                      from_time=From_TimeStamp,
                                      to_time=To_TimeStamp,
                                      serviceType=service_type)[1]
        threes_count = update_servermap(application_name,
                                        from_time=From_TimeStamp,
                                        to_time=To_TimeStamp,
                                        serviceType=service_type)[2]
        fives_count = update_servermap(application_name,
                                       from_time=From_TimeStamp,
                                       to_time=To_TimeStamp,
                                       serviceType=service_type)[3]
        error_text = message_text("ERROR", error_count, service_type,
                                  application_name)
        slow_text = message_text("SLOW", error_count, service_type,
                                 application_name)
        threes_text = message_text("3s", error_count, service_type,
                                   application_name)
        fives_text = message_text("5s", error_count, service_type,
                                  application_name)
        '''如果总调用错误数超过阈值5(根据实际需求进行设置),则报警'''
        if error_count >= 1:

            xiaoding.send_markdown(title='pinpoint报警',
                                   text=error_text,
                                   at_mobiles=at_mobiles)
        if slow_count >= 3:
            xiaoding.send_markdown(title='pinpoint报警',
                                   text=slow_text,
                                   at_mobiles=at_mobiles)
        if threes_count >= 60:
            xiaoding.send_markdown(title='pinpoint报警',
                                   text=threes_text,
                                   at_mobiles=at_mobiles)
        if fives_count >= 30:
            xiaoding.send_markdown(title='pinpoint报警',
                                   text=fives_text,
                                   at_mobiles=at_mobiles)