1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| #!/bin/sh
HOST="127.0.0.1" USER="root" PASSWORD="password" DATABASE="zentao"
SQL_COMMAND1="SELECT CONCAT(p.name, ':', u.realname, '-', count(b.id), ',') as '现未解决bug总数:\\\\n' from zt_user u inner join zt_bug b on b.assignedTo = u.account inner join zt_product p on p.id = b.product where u.type = 'inside' #内部员工 #and u.role = 'dev' #研发 and b.status = 'active' #bug状态:激活 and b.deleted = '0' #未删除 and p.status = 'normal' #项目状态:正常 group by u.realname, p.name order by p.name, count(b.id) desc;"
SQL_COMMAND2="SELECT CONCAT(p.name, ':', u.realname, '-', count(b.id), ',') as '【P1】bug数:\\\\n' from zt_user u inner join zt_bug b on b.assignedTo = u.account inner join zt_product p on p.id = b.product where u.type = 'inside' #内部员工 #and u.role = 'dev' #研发 and b.status = 'active' #bug状态:激活 and b.severity = 1 #严重等级:P1 and b.deleted = '0' #未删除 and p.status = 'normal' #项目状态:正常 group by u.realname, p.name order by p.name, count(b.id) desc;"
SQL_COMMAND3="SELECT CONCAT(p.NAME, ':', u.realname, '-已解决:', COUNT(b.id)) AS '---昨日已解决---\\\\n' FROM zt_user u INNER JOIN zt_bug b ON b.resolvedBy = u.account INNER JOIN zt_product p ON p.id = b.product WHERE u.type = 'inside' #内部员工 #AND u.role = 'dev' #研发 AND b.status = 'resolved' #bug 状态为已解决 AND b.deleted = '0' #未删除 AND p.status = 'normal' #项目状态:正常 AND b.openedDate >= CURDATE() - INTERVAL 1 DAY AND b.openedDate < CURDATE() #限定为昨日数据 GROUP BY u.realname, p.NAME ORDER BY p.NAME, COUNT(b.id) DESC;"
RESULT1=$(/opt/zbox/bin/mysql -h $HOST -u $USER -p$PASSWORD $DATABASE -e "$SQL_COMMAND1") RESULT2=$(/opt/zbox/bin/mysql -h $HOST -u $USER -p$PASSWORD $DATABASE -e "$SQL_COMMAND2") RESULT3=$(/opt/zbox/bin/mysql -h $HOST -u $USER -p$PASSWORD $DATABASE -e "$SQL_COMMAND3")
echo $RESULT1 > /tmp/totalBugs echo $RESULT2 > /tmp/p1Bugs echo $RESULT3 > /tmp/resolvedBugs
cat /tmp/totalBugs echo cat /tmp/p1Bugs echo cat /tmp/resolvedBugs
CURL_URL='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=yyy'
push_webhook_msg() { currentDate=`date +%Y-%m-%d` totalBugs=`perl -pe 's/,/\\\\n/g' /tmp/totalBugs` echo totalBugs=$totalBugs p1Bugs=`perl -pe 's/,/\\\\n/g' /tmp/p1Bugs` echo p1Bugs=$p1Bugs resolvedBugs=`perl -pe 's/,/\\\\n/g' /tmp/resolvedBugs` echo resolvedBugs=$resolvedBugs
if [[ -z "$totalBugs" && -z "$p1Bugs" ]]; then CURL_DATA="{\"msgtype\": \"text\", \"text\": {\"content\": \"截止$currentDate >> bug统计:\\n 今日无遗留BUG。\\n\\n $resolvedBugs \", \"mentioned_list\":[\"@all\"]}}" else CURL_DATA="{\"msgtype\": \"text\", \"text\": {\"content\": \"截止$currentDate >> bug统计:\\n $totalBugs \\n $p1Bugs \\n\\n $resolvedBugs \", \"mentioned_list\":[\"@all\"]}}" fi echo "$CURL_DATA"
CURL_CMD="curl \"$CURL_URL\" -H \"Content-Type: application/json\" -d '$CURL_DATA'"
CURL_RES=$(eval $CURL_CMD) echo $CURL_RES }
push_webhook_msg
exit 0
|