-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathggus_generate_report.py
executable file
·202 lines (152 loc) · 5.92 KB
/
ggus_generate_report.py
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python2.7
# Get the latest version from the following URL:
# https://github.com/alvarolopez/ggus_report_generator
# AUTHOR: Alvaro Lopez <[email protected]>
from __future__ import print_function
import argparse
import requests
import xml.parsers.expat
from xml.dom import minidom
__version__ = 20141002
# Change it if you want to use it for your NGI without specifing
# it in the command-line
SUPPORT_UNIT = "NGI_IBERGRID"
message_header = """
### Open GGUS tickets ###
There are %(ticket count)s open tickets under %(support_unit)s scope. Please
find below a short summary of them. Please take the appropriate actions:
- Change the ticket status from "ASSIGNED" to "IN PROGRESS".
- Provide feedback on the issue as regularly as possible.
- In case of problems, ask for help in <[email protected]>
- For long pending issues, put your site/node in downtime.
- Do not forget to close the ticket when you have solved the problem.
"""
class GGUSReportException(Exception):
pass
class GGUSTicket(object):
support_unit_tag = "SUPPORT UNIT"
site_tag = "SITE"
body_template = """%(title)s: %(affected_site)s
GGUS ID : %(request_id)s
Open since : %(date_of_creation)s UTC
Status : %(status)s
Description : %(subject)s
Link : https://ggus.eu/ws/ticket_info.php?ticket=%(request_id)s"""
def __init__(self, ticket, support_unit):
self.ticket = ticket
self.support_unit = support_unit
def _get_by_xml_tag(self, tag):
aux = self.ticket.getElementsByTagName(tag)
if aux:
return aux[0].firstChild.nodeValue
return None
@property
def affected_site(self):
return self._get_by_xml_tag("affected_site")
@property
def date_of_creation(self):
return self._get_by_xml_tag("date_of_creation")
@property
def status(self):
return self._get_by_xml_tag("status")
@property
def subject(self):
return self._get_by_xml_tag("subject")
@property
def request_id(self):
return self._get_by_xml_tag("request_id")
def render(self):
d = {
"request_id": self.request_id,
"date_of_creation": self.date_of_creation,
"status": self.status,
"subject": self.subject
}
if self.affected_site:
d["title"] = self.site_tag
d["affected_site"] = self.affected_site
else:
d["title"] = self.support_unit_tag
d["affected_site"] = self.support_unit
return self.body_template % d
class GGUSConnection(object):
url = ("https://ggus.eu/index.php?mode=ticket_search&ticket_id="
"&supportunit=%(support_unit)s&su_hierarchy=0&vo=all&user="
"&keyword=&involvedsupporter=&assignedto=&affectedsite="
"&specattrib=none&status=open&priority=&typeofproblem=all"
"&ticket_category=all&mouarea=&date_type=creation+date"
"&tf_radio=1&timeframe=any&from_date=&to_date=&untouched_date="
"&orderticketsby=REQUEST_ID&orderhow=desc&search_submit=GO%%21"
"&writeFormat=XML")
def __init__(self, user, password, support_unit):
self.session = None
self.user = user
self.password = password
self.support_unit = support_unit
self.url = self.url % {"support_unit": support_unit}
def _get_ggus_session(self):
s = requests.Session()
s.verify = False
data = {"login": self.user, "password": self.password}
url = "https://ggus.eu/index.php?mode=login"
s.post(url, data=data)
self.session = s
def login(self):
self._get_ggus_session()
if not self.session.cookies:
raise GGUSReportException("Could not authenticate with GGUS")
def tickets(self):
if not self.session:
self.login()
r = self.session.get(self.url)
try:
aux = minidom.parseString(r.content)
except xml.parsers.expat.ExpatError:
raise GGUSReportException("Could not parse XML content")
tickets = aux.getElementsByTagName('ticket')
return [GGUSTicket(ticket, self.support_unit) for ticket in tickets]
def parse_args():
global SUPPORT_UNIT
parser = argparse.ArgumentParser(description='TBD.')
parser.add_argument('username',
metavar='USERNAME',
type=str,
help='GGUS username.')
parser.add_argument('password',
metavar='PASSWORD',
type=str,
help='GGUS user password.')
parser.add_argument('-s', '--support-unit',
dest='support_unit',
metavar='SUPPORT_UNIT',
default=SUPPORT_UNIT,
help=('Only tickets belonging to this support unit '
'will be collected'))
parser.add_argument('-r', '--reverse',
dest='reverse',
default=False,
action='store_true',
help='Sort tickets in reverse chronological order.')
return parser.parse_args()
def main():
args = parse_args()
ggus = GGUSConnection(args.username,
args.password,
args.support_unit)
tickets = ggus.tickets()
if args.reverse:
tickets.reverse()
print (message_header % {"support_unit": args.support_unit,
"ticket count": len(tickets)})
separator = "-" * 80
su_tickets = []
for ticket in tickets:
if not ticket.affected_site:
su_tickets.append(ticket)
continue
print(separator, ticket.render(), sep='\n')
for ticket in su_tickets:
print(separator, ticket.render(), sep='\n')
print("-" * 80)
if __name__ == "__main__":
main()