0

我正在尝试构建一个脚本,该脚本将从最佳实用请求跟踪器安装中获取多个队列的所有开放、新和停滞票证。我有以下脚本:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import rt
from credentials import *  # Contains rturl, rtuser, rtpass

W = rt.Rt(rturl, rtuser, rtpass)
owners = ['Nobody']
queues = ['queue_a', 'queue_b', 'queue_c']
states = ['Open', 'New', 'Stalled']

def build_query():
    queues_part = "(Queue='{}')".format("'+OR+Queue='".join(queues))
    owners_part = "(Owner='{}')".format("'+OR+Owner='".join(owners))
    states_part = "(Status='{}')".format("'+OR+Status='".join(states))
    query_items = [queues_part, owners_part, states_part]
    raw_query = ("+AND+".join(query_items))
    return raw_query


def gettickets(query):
    try:
        W.login()
        tickets = W.search(raw_query=query)
        return tickets

    except Exception as e:
        print('===> Tickets ophalen mislukt:\n', str(e))

    finally:
        W.logout()


if __name__ == '__main__':
    # to check query for errors
    print(build_query())

    # should return all new, open and stalled tickets in queue_a,b,c
    print(gettickets(build_query()))

如果运行,它将打印出正确的查询(在 RT 的查询生成器中测试过,并且运行良好)。但是,返回的 'tickets' 变量只返回一个空列表:[]

由于查询本身在 RT 中运行良好,并且没有抛出任何错误,因此我不确定如何解决此问题。任何人?

附言。我使用 build_query 函数,因为(最终)脚本将从其他脚本接收它的参数。

4

0 回答 0