当问题 24/36/48 小时开放时,如何通过电子邮件向预定义的邮件组创建通知。
对于这些类型中的任何一种 (24/36/48) 都应该有一个提醒,如果问题被重新打开,则应该重新开始计数。
当问题 24/36/48 小时开放时,如何通过电子邮件向预定义的邮件组创建通知。
对于这些类型中的任何一种 (24/36/48) 都应该有一个提醒,如果问题被重新打开,则应该重新开始计数。
经过大量的搜索,我已经解决了这个问题:
编码:
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)
JQL:
project = XXX AND status= Open ORDER BY updated ASC, key DESC
蟒蛇代码:
#!/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')
这种方法的主要优点是它是高度可定制的,并且通过将数据保存到自定义字段,可以轻松创建过滤器和报告以显示已打开很长时间的问题。
我一般同意 Kuf 的方法,但最近 JIRA 插件发布了自动化插件和PDF 自动化插件,可以进一步增强它。
因此,您定义和更新脚本化自定义字段,如上所述。如上所述,您可以使用 JQL 查询创建已保存的过滤器。
(有趣的部分从这里开始。)
您使用自动化插件设置新的自动化规则:
定义基于 CRON 表达式的触发器以匹配您的首选计划(例如,每 5 分钟一次)
选择“发送 PDF”动作来执行,选择一个 PDF 模板(如果一个简单的问题列表就足够了,那么使用“问题导航器”模板)并输入电子邮件地址来 ping。
与您的原始解决方案相比,它的优势:
它更易于维护:它都是基于插件的,所有的乐趣都发生在 JIRA 内部。没有外部依赖,没有要维护的脚本。
与简单的问题链接相比,PDF 格式允许更好的格式化和可视化可能性(图表!)。
免责声明:我是这个付费 JIRA 插件的开发者。
这最好通过订阅来实现。
首先为每种类型(24 小时、36 小时等)创建一个搜索过滤器。注意:在这一点上,我们必须更准确地理解“24 小时开放”的含义。我假设您关心长期未分配的问题。
因此,要过滤掉这些问题,您可以使用如下过滤器:
created <= -24h and status = Open and assignee is null
如果您想要 24 小时未触及的问题,请使用“更新”而不是在上面的示例中创建。单击此处了解如何使用 Jira 查询语言。
使用有意义的名称保存过滤器(例如“24h open”)。
现在在问题->管理过滤器下有一个“订阅”列,您可以在其中为自己或任何 Jira 组订阅此过滤器。只需每天使用时间表和每天一次的间隔,选择一个方便的时间,然后就可以了。
对重新打开的问题使用相同的技术,但将过滤器查询更改为:
status = Reopened AND updated <= -24h