zoukankan      html  css  js  c++  java
  • 发钉钉消息

    #!/bin/bash
    #临时存放查询到的数据
    TMP_DIR=/data/mysql_tmp
    #在mysql中查询到的数据,导入到一个文件中,是以文本格式显示,如果是使用wps查看,将此文本格式的后缀改为xls
    # 也是可以打开的,不过如果是苹果系统,是打不开的,所以就考虑到了转码
    mysql -uroot -p****** -e "SELECT *****" >$TMP_DIR/Article_statistics_`date +%F`.txt
    #使用python将txt转化为xls格式
    #此转码脚本使用的是xlwt库 可以使用pip install xlwt 下载安装
    #转码支持中文,使用的是python2.7
    python /server/scripts/txt_to_xls.py $TMP_DIR/Article_statistics_`date +%F`
    #将转码后的文件,放到web服务器上,访问此文件会直接进行下载
    scp $TMP_DIR/Article_statistics_`date +%F`.xls web_server01:/var/www/article_statistics/download/
    #通过钉钉发送通知--(在dingmail中已经做好了固定连接,比如http://download.gaoyunwei.com/ )
    #所以只需要添加后部分就可以通过点击打开连接进行下载
    #因为是非公开数据,所以要进行配置nginx的auth认证
    dingmail "download/Article_statistics_`date +%F`.xls"


    #!/bin/bash
    ACCESS_TOKEN="*********"
    #上面提到的固定的连接
    URL="https://oapi.dingtalk.com/robot/send?access_token="
    #钉钉的api调用接口
    Dingding_Url="https://oapi.dingtalk.com/robot/send?access_token=${ACCESS_TOKEN}"
    #这里采用的是每次推送都发送新的nginx认证密码
    #生成10位的随机密码
    PASSWD=`strings /dev/urandom |tr -dc A-Za-z0-9 | head -c10`
    #将密码写入临时文件,nginx认证请研究下其他人的博客
    printf "downloaduser:$(openssl passwd -crypt $PASSWD) " >/tmp/httpasswd
    #发送密码覆盖上一次产生的密码到web服务器
    scp /tmp/httpasswd web_server01:/etc/nginx/httpasswd
    #信息发送
    # 注意这里的写法,使用的是markdown格式。
    # [![download]($URL/png/4.png)]($URL/$1) 这一个实际上就是一个图片链接,钉钉上的消息看起来不是很枯燥
    #这里可能会有朋友注意到我使用了ssh java2 远程来执行curl命令,这是因为我们数据库服务器不能上网^^^^^^,只能借网执行了,也算是个小技巧
    SendMessageToDingding(){
    ssh JAVA2 "curl -s ${Dingding_Url} -H 'Content-Type: application/json' -d '
    {
    "msgtype": "markdown",
    "markdown": {
    "title":"文章数据统计",
    "text":"#### app文章数据统计 > 采集时间:`date +%F_%T` > [![download]($URL/png/4.png)]($URL/$1) > ###### 账号:downloaduser密码:$PASSWD"
    },
    "at": {
    "atMobiles": [""],
    "isAtAll": false
    }
    }'"
    }
    #这里采用了一个参数传递,关于钉钉的格式,也是有很多细节需要注意

    #!/bin/bash
    ACCESS_TOKEN="11"
    KEY="22"
    titime=`date +%s`
    temp="${titime} ${KEY}"
    REPORTNAME=`ls -lt /opt/pic | grep moreTickets_CI_Report | head -n 1 |awk '{print $9}'`
    REPORT="http://118.25.182.23:8051/img/${REPORTNAME}"
    PICURL="https://www.moretickets.com/images/logo-b17998409b.png"
    TITLE="摩天轮MTL接口自动化测试"
    TEXTLINK="线上环境的摩天轮PC端执行情况 点击链接查看全部 总共14条主要链接渠道,点击report页脚查看失败原因"
    function SendMessageToDingding(){

    Dingding_Url="https://oapi.dingtalk.com/robot/send?access_token=${ACCESS_TOKEN}"
    # 发送钉钉消息
    curl "${Dingding_Url}" -H 'Content-Type: application/json' -d "
    {
    "link": {
    "messageUrl": ${REPORT},
    "picUrl": ${PICURL},
    "title": ${TITLE},
    "text": ${TEXTLINK}
    },
    "msgtype": "link"
    }"
    }
    SendMessageToDingding

  • 相关阅读:
    Codeforces Round #384 (Div. 2) 解题报告
    Codeforces Round #383 (Div. 2) 解题报告
    (DFS、bitset)AOJ-0525 Osenbei
    (DFS、全排列)POJ-3187 Backward Digit Sums
    自考新教材-p169
    自考新教材-p167
    自考新教材-p166
    自考新教材-p165
    自考新教材-p161
    自考新教材-p159
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/12056003.html
Copyright © 2011-2022 走看看