-
Notifications
You must be signed in to change notification settings - Fork 90
/
list-tickets.gmp.py
executable file
·58 lines (44 loc) · 1.64 KB
/
list-tickets.gmp.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
# SPDX-FileCopyrightText: 2024 Martin Boller
#
# SPDX-License-Identifier: GPL-3.0-or-later
from argparse import Namespace
from gvm.protocols.gmp import Gmp
from gvmtools.helper import Table
def main(gmp: Gmp, args: Namespace) -> None:
# pylint: disable=unused-argument
response_xml = gmp.get_tickets(filter_string="rows=-1")
tickets_xml = response_xml.xpath("ticket")
heading = ["#", "ID", "Name", "Host", "Task", "Status", "Note"]
rows = []
numberRows = 0
print("Listing tickets.\n")
for ticket in tickets_xml:
# Count number of reports
numberRows = numberRows + 1
# Cast/convert to text to show in list
rowNumber = str(numberRows)
name = "".join(ticket.xpath("name/text()"))
ticket_id = ticket.get("id")
ticket_status = "".join(ticket.xpath("status/text()"))
ticket_task = "".join(ticket.xpath("task/name/text()"))
ticket_host = "".join(ticket.xpath("host/text()"))
if ticket_status.upper() == "OPEN":
ticket_note = "".join(ticket.xpath("open_note/text()"))
elif ticket_status.upper() == "FIXED":
ticket_note = "".join(ticket.xpath("fixed_note/text()"))
elif ticket_status.upper() == "CLOSED":
ticket_note = "".join(ticket.xpath("closed_note/text()"))
rows.append(
[
rowNumber,
ticket_id,
name,
ticket_host,
ticket_task,
ticket_status,
ticket_note,
]
)
print(Table(heading=heading, rows=rows))
if __name__ == "__gmp__":
main(gmp, args)