Jira发出提醒

时间:2012-07-15 08:36:34

标签: jira

如果在24/36/48小时内打开问题,如何通过电子邮件向预定义的邮件组创建通知。

对于任何类型(24/36/48)应该有一个提醒,如果重新打开问题,则应重新启动计数。

3 个答案:

答案 0 :(得分:2)

最好通过subscriptions来实现。

首先为每种类型(24小时,36小时等)创建搜索过滤器。注意:此时我们必须更准确地说明“24h open”的含义。我认为你关心长期未分配的问题。

因此,要过滤掉这些问题,您可以使用这样的过滤器:

created <= -24h and status = Open and assignee is null

如果您想要24小时未触及的问题,请使用“更新”而不是在上面的示例中创建。关于如何使用Jira查询语言的Click here

使用有意义的名称保存过滤器(例如“24h open”)。

现在,在“问题” - >“管理过滤器”下,有一个“订阅”列,您可以在此订阅自己或此过滤器的任何Jira组。只需每天使用时间表和每天一次,请选择一个方便的时间,然后去。

对重新打开的问题使用相同的技术,但将过滤器查询更改为:

status = Reopened AND updated <= -24h

答案 1 :(得分:2)

经过多次搜索,我已经解决了这个问题:

  • 创建了一个名为“Open since”的自定义字段 - “日期时间”字段,用于保存问题的打开时间。
  • 创建了一个名为“通知”的自定义字段 - 一个只读文本字段。
  • 使用Jira Scripting Suite,我创建了一个后期功能,并将其置于每个转换到“打开”状态。这是为了保持问题的开放时间。

代码:

from com.atlassian.jira import ComponentManager
from datetime import datetime

opend_since_field = "customfield_10001"

# get opened since custom field:
cfm = ComponentManager.getInstance().getCustomFieldManager()
# get current time
currentTime = datetime.today()
# save current time
issue.setCustomFieldValue(cfm.getCustomFieldObject(opend_since_field),currentTime)
  • 我创建了一个新的过滤器,以获取24小时内打开的问题列表:

JQL:

project = XXX AND status= Open ORDER BY updated ASC, key DESC
  • 最后 - 我使用Jira remote API - XML-RPC方法编写了一个计划每5分钟运行一次的python脚本。剧本 读取从过滤器发出的所有内容,将所有具有“打开”状态的内容拉出超过24小时/ 36小时/ 48小时,发送提醒电子邮件,并将其标记为已通知,因此只会发送一种类型的提醒。< / LI>

python代码:

#!/usr/bin/python

# Refer to the XML-RPC Javadoc to see what calls are available:
# http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/com/atlassian/jira/rpc/xmlrpc/XmlRpcService.html
# /home/issues_reminder.py

import xmlrpclib
import time
from time import mktime
from datetime import datetime
from datetime import timedelta
import smtplib,email
from smtplib import SMTP 
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders

# Jira connction info
server = 'https://your.jira.com/rpc/xmlrpc'
user = 'user'
password = 'password'
filter = '10302' # Filter ID
# Email definitions 
smtpserver = 'mail.server.com'
fromAddr = 'support@your.jira.com'
mail_user = 'jira_admin@your.domain.com'
mail_password = 'password'
toAddr = 'support@your.domain.com'
mysubject = "hrs Issue notification!!!"
opend_since_field = "customfield_10101"


COMMASPACE = ', '
def email_issue(issue,esc_time):
    # create html email
    subject = '['+issue+'] '+esc_time+mysubject
    html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
    html +='"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
    html +='<body style="font-size:12px;font-family:Verdana">'
    html +='<p align="center"><img src="your_logo.jpg" alt="logo" height="43" width="198"></p> '
    html +='<p> The issue ['+issue+'] is open for over '+esc_time+' hours.</p>'
    html +='<p> A link to view the issue: https://your.jira.com/browse/'+issue+'.</p>'
    html +='<BR><p> This is an automated email sent from Jira.</p>'
    html +='</body></html>'
    emailMsg = email.MIMEMultipart.MIMEMultipart('alternative')
    emailMsg['Subject'] = subject
    emailMsg['From'] = fromAddr
    emailMsg['To'] = toAddr
    emailMsg.attach(MIMEText(html, 'html'))
    # Send the email
    emailserver = SMTP(smtpserver) # ip or domain name of smtp server
    emailserver.login(mail_user, mail_password)
    emailserver.sendmail(fromAddr, [toAddr], emailMsg.as_string())
    emailserver.quit()
    return


s = xmlrpclib.ServerProxy(server)
auth = s.jira1.login(user, password)

esc12List = []
esc24List = []
esc48List = []


issues = s.jira1.getIssuesFromFilter(auth, filter)
print "Modifying issue..."
for issue in issues:
        creation = 0;
        # get open since time
        for customFields in issue['customFieldValues']:
                if customFields['customfieldId'] == opend_since_field :
                        print "found field!"+  customFields['values']
                        creation = customFields['values']
        if (creation == 0):
                creation = issue['created']
                print "field not found"
    creationTime = datetime.fromtimestamp(mktime(time.strptime(creation, '%d/%b/%y %I:%M %p')))
    currentTime = datetime.fromtimestamp(mktime(time.gmtime()))
    delta = currentTime - creationTime
    esc12 = timedelta(hours=12)
    esc24 = timedelta(hours=24)
    esc48 = timedelta(hours=48)
    print "\nchecking issue "+issue['key']
    if (delta < esc12):
        print "less than 12 hours"
        print "not updating"
        continue
    if (delta < esc24):
        print "less than 24 hours"
        for customFields in issue['customFieldValues']:
            if customFields['customfieldId'] == 'customfield_10412':
                if customFields['values'] == '12h':
                    print "not updating"
                    break
                else:
                    print "updating !!!"
                    s.jira1.updateIssue(auth, issue['key'], {"customfield_10412": ["12h"]})
                    esc12List.append(issue['key'])
                    break
        continue
    if (delta < esc48):
        print "less than 48 hours"
        for customFields in issue['customFieldValues']:
            if customFields['customfieldId'] == 'customfield_10412':
                if customFields['values'] == '24h':
                    print "not updating"
                    break
                else:
                    print "updating !!!"
                    s.jira1.updateIssue(auth, issue['key'], {"customfield_10412": ["24h"]})
                    esc24List.append(issue['key'])
                    break
        continue
    print "more than 48 hours"
    for customFields in issue['customFieldValues']:
        if customFields['customfieldId'] == 'customfield_10412':
            if customFields['values'] == '48h':
                print "not updating"
                break
            else:
                print "updating !!!"
                s.jira1.updateIssue(auth, issue['key'], {"customfield_10412": ["48h"]})
                esc48List.append(issue['key'])
                break

for key in esc12List:
    email_issue(key,'12')
for key in esc24List:
    email_issue(key,'24')
for key in esc48List:
    email_issue(key,'48')

这种方法的主要优点是它可以高度自定义,通过将数据保存到自定义字段,可以轻松创建过滤器和报告,以显示已经打开很长时间的问题。

答案 2 :(得分:1)

我普遍同意Kuf的方法,但最近的JIRA插件发布Automation PluginPDF Automation Plugin可以进一步增强

因此,您可以定义和更新脚本化的自定义字段,如上所述。您可以使用JQL查询创建已保存的过滤器,如上所述。

(有趣的部分从这里开始。)

使用自动化插件设置新的automation rule

  1. 定义基于CRON表达式的触发器以匹配您的首选计划(例如,每5分钟)

  2. 选择要执行的“发送PDF”操作,选择一个PDF模板(如果一个简单的问题列表就足够了,然后使用“问题导航器”模板)并输入要ping的电子邮件地址。

  3. 这优于原始解决方案:

    1. 它更易于维护:它基于所有插件,所有乐趣都在JIRA内部发生。没有外部依赖,没有要维护的脚本。

    2. 与简单的问题链接相比,PDF格式允许更好的格式化和可视化(图表!)。

    3. 免责声明:我是这款付费JIRA插件的开发者。