Kanboard 简介:

Kanboard流程图指示十分利于我们每天对工作的复盘,同时让团队成员相互了解在做什么,将要做什么,完成了什么。现在大部分公司开始使用阿里钉钉用于工作沟通,当我们在Kanboard新增任务时候,推送一份到MQ,同时通过脚本方式,触发钉钉接口传送消息到钉钉群,这样子有利于团队试试查看任务情况。

Kanboard 不仅可以推送到MQ,同时还可以接入LDAP,这对于公司使用域账号登录来说可谓是福音

Kanboard 推送到RabbitMQ

  • 参考文档: https://github.com/kanboard/plugin-rabbitmq

    配置过程如下:

  • Install the plugin from the Kanboard plugin manager in one click
  • Download the zip file and decompress everything under the directory plugins/RabbitMQ
  • Clone this repository into the folder plugins/RabbitMQ
  • vim config.php

    1
    2
    3
    4
    5
    6
    define('RABBITMQ_QUEUE', 'kanboard_queue');
    define('RABBITMQ_EXCHANGE', 'kanboard_exchange');
    define('RABBITMQ_HOSTNAME', '127.0.0.1');
    define('RABBITMQ_PORT', 5672);
    define('RABBITMQ_USERNAME', 'guest');
    define('RABBITMQ_PASSWORD', 'guest');
  • /path/to/kanboard/cli worker

从RabbitMQ获取队列信息推送到钉钉群

  • pip install pika

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

#-*-coding:utf-8-*-
#!/usr/bin/env python
# v1:2018-01-04

import pika
import json
import requests
import datetime
import sys
reload(sys)
sys.setdefaultencoding('utf8')


# Step #6
def Dingding_Send(title, description,creator_username,url,column_title):
headers = {'Content-Type': 'application/json'}
dingtalk_token = ["https://oapi.dingtalk.com/robot/send?access_token=xxxx"]
data = {
"msgtype": "markdown",
"markdown": {
"title": "Kanban信息推送通知",
"text": "### Kanban信息推送通知:\n"+
"------------------- \n" +
"- **任务名称:** {0} \n".format(title)+
"- **任务描述:** {0} \n".format(description)+
"- **创建人为:** {0} \n".format(creator_username) +
"- [详情请点击URL]({0}) \n".format(url) +
"- **任务状态:** **{0}** \n".format(column_title)

},
"at": {
"isAtAll": 'True'
}
}
for Api_Url in dingtalk_token:
print requests.post(url=Api_Url, headers=headers, data=json.dumps(data)).text



# Step #5
def get_mq_kb(channel, method_frame, header_frame, body):
print(" [GET MQ INFO] %r" % body)

### ["task.create_update","task.update"]
if len(json.loads(body)["params"]) == 5 :
if json.loads(body)["params"][1][1]=="task.update":
pass
elif json.loads(body)["params"][1][1] == "task.create":
pass
else:
if json.loads(body)["params"][0] != str(2):
title=json.loads(body)["params"][0]["task"]["title"]
description = json.loads(body)["params"][0]["task"]["description"]
creator_username = json.loads(body)["params"][0]["task"]["creator_name"]
column_title = json.loads(body)["params"][0]["task"]["column_title"]
url = "http://kb.xxx.com/project/{project_id}/task/{task_id}".format(project_id=json.loads(body)["params"][0]["project_id"],task_id=json.loads(body)["params"][0]["task_id"])
if column_title != "要做":
Dingding_Send(title, description,creator_username,url,column_title)

# Step #3
def on_open(connection):
connection.channel(on_channel_open)

# Step #4
def on_channel_open(channel):
''' Start a queue consumer
basic_consume(self, queue='', consumer_tag='', no_local=False,
no_ack=False, exclusive=False, nowait=False,
callback=None, arguments=None, on_cancel=None):
'''
channel.basic_consume(get_mq_kb,queue='kanboard_queue',no_ack=True)



if __name__ == "__main__":

# Step #1: Connect to RabbitMQ
parameters = pika.URLParameters('amqp://guest:guest@host:5672/%2F')
# Create our connection object, passing in the on_open method
connection = pika.SelectConnection(parameters=parameters, on_open_callback=on_open)

try:
# Step #2 - Block on the IOLoop
connection.ioloop.start()

except Exception,e:
# Gracefully close the connection
connection.close()

# Start the IOLoop again so Pika can communicate, it will stop on its own when the connection is closed
connection.ioloop.start()

Comments

2018-01-07