Skip to content

Commit db6ae9e

Browse files
ozgengreenbonebot
authored andcommitted
add: add get_report_errors GMP request
Implement the get_report_errors GMP request command. Add unit tests to verify required arguments, filters, pagination handling, and details output.
1 parent 15c7246 commit db6ae9e

5 files changed

Lines changed: 149 additions & 0 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ReportApplications,
2323
ReportClosedCVEs,
2424
ReportCVEs,
25+
ReportErrors,
2526
ReportHosts,
2627
ReportOperatingSystems,
2728
ReportPorts,
@@ -1203,3 +1204,33 @@ def get_report_closed_cves(
12031204
details=details,
12041205
)
12051206
)
1207+
1208+
def get_report_errors(
1209+
self,
1210+
report_id: EntityID,
1211+
*,
1212+
filter_string: str | None = None,
1213+
filter_id: str | None = None,
1214+
ignore_pagination: bool | None = None,
1215+
details: bool | None = True,
1216+
) -> T:
1217+
"""Request errors of a single report.
1218+
1219+
Args:
1220+
report_id: UUID of an existing report.
1221+
filter_string: Filter term to use to filter results in the report
1222+
filter_id: UUID of filter to use to filter results in the report
1223+
ignore_pagination: Whether to ignore the filter terms "first" and
1224+
"rows".
1225+
details: Request additional report error information details.
1226+
Defaults to True.
1227+
"""
1228+
return self._send_request_and_transform_response(
1229+
ReportErrors.get_report_errors(
1230+
report_id=report_id,
1231+
filter_string=filter_string,
1232+
filter_id=filter_id,
1233+
ignore_pagination=ignore_pagination,
1234+
details=details,
1235+
)
1236+
)

gvm/protocols/gmp/requests/next/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
from gvm.protocols.gmp.requests.next._report_cves import (
2424
ReportCVEs,
2525
)
26+
from gvm.protocols.gmp.requests.next._report_errors import (
27+
ReportErrors,
28+
)
2629
from gvm.protocols.gmp.requests.next._report_hosts import (
2730
ReportHosts,
2831
)
@@ -158,6 +161,7 @@
158161
"ReportClosedCVEs",
159162
"ReportConfigParameter",
160163
"ReportConfigs",
164+
"ReportErrors",
161165
"ReportFormatType",
162166
"ReportFormats",
163167
"ReportHosts",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from gvm.errors import RequiredArgument
2+
from gvm.protocols.core import Request
3+
from gvm.protocols.gmp.requests import EntityID
4+
from gvm.utils import to_bool
5+
from gvm.xml import XmlCommand
6+
7+
8+
class ReportErrors:
9+
@classmethod
10+
def get_report_errors(
11+
cls,
12+
report_id: EntityID,
13+
*,
14+
filter_string: str | None = None,
15+
filter_id: str | None = None,
16+
ignore_pagination: bool | None = None,
17+
details: bool | None = True,
18+
) -> Request:
19+
"""Request errors of a single report.
20+
21+
Args:
22+
report_id: UUID of an existing report.
23+
filter_string: Filter term to use to filter results in the report
24+
filter_id: UUID of filter to use to filter results in the report
25+
ignore_pagination: Whether to ignore the filter terms "first" and
26+
"rows".
27+
details: Request additional report error information details.
28+
Defaults to True.
29+
"""
30+
cmd = XmlCommand("get_report_errors")
31+
32+
if not report_id:
33+
raise RequiredArgument(
34+
function=cls.get_report_errors.__name__, argument="report_id"
35+
)
36+
37+
cmd.set_attribute("report_id", str(report_id))
38+
39+
cmd.add_filter(filter_string, filter_id)
40+
41+
if ignore_pagination is not None:
42+
cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination))
43+
44+
cmd.set_attribute("details", to_bool(details))
45+
46+
return cmd
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from gvm.errors import RequiredArgument
7+
8+
9+
class GmpGetReportErrorsTestMixin:
10+
def test_get_report_errors_without_id(self):
11+
with self.assertRaises(RequiredArgument):
12+
self.gmp.get_report_errors(None)
13+
14+
with self.assertRaises(RequiredArgument):
15+
self.gmp.get_report_errors("")
16+
17+
def test_get_report_errors_with_filter_string(self):
18+
self.gmp.get_report_errors(report_id="r1", filter_string="name=foo")
19+
20+
self.connection.send.has_been_called_with(
21+
b'<get_report_errors report_id="r1" filter="name=foo" details="1"/>'
22+
)
23+
24+
def test_get_report_errors_with_filter_id(self):
25+
self.gmp.get_report_errors(report_id="r1", filter_id="f1")
26+
27+
self.connection.send.has_been_called_with(
28+
b'<get_report_errors report_id="r1" filt_id="f1" details="1"/>'
29+
)
30+
31+
def test_get_report_errors_with_ignore_pagination(self):
32+
self.gmp.get_report_errors(report_id="r1", ignore_pagination=True)
33+
34+
self.connection.send.has_been_called_with(
35+
b'<get_report_errors report_id="r1" ignore_pagination="1" details="1"/>'
36+
)
37+
38+
self.gmp.get_report_errors(report_id="r1", ignore_pagination=False)
39+
40+
self.connection.send.has_been_called_with(
41+
b'<get_report_errors report_id="r1" ignore_pagination="0" details="1"/>'
42+
)
43+
44+
def test_get_report_errors_with_details(self):
45+
self.gmp.get_report_errors(report_id="r1", details=True)
46+
47+
self.connection.send.has_been_called_with(
48+
b'<get_report_errors report_id="r1" details="1"/>'
49+
)
50+
51+
self.gmp.get_report_errors(report_id="r1", details=False)
52+
53+
self.connection.send.has_been_called_with(
54+
b'<get_report_errors report_id="r1" details="0"/>'
55+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2026 Greenbone AG
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
#
5+
6+
from ...gmpnext import GMPTestCase
7+
from .report_errors.test_get_report_errors import (
8+
GmpGetReportErrorsTestMixin,
9+
)
10+
11+
12+
class GmpGetReportErrorsTestCase(GmpGetReportErrorsTestMixin, GMPTestCase):
13+
pass

0 commit comments

Comments
 (0)