Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions gvm/protocols/gmp/_gmpnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ def sync_agents(self) -> T:
"""Trigger agents synchronization from all agent controllers."""
return self._send_request_and_transform_response(Agents.sync_agents())

def get_agent_support_bundle(
self,
agent_id: EntityID,
days: int = 0,
) -> T:
"""Request a support bundle for an agent.

Args:
agent_id: ID of the agent to get the support bundle for.
days: Number of days of logs to include. If None, zero is sent so the
Agent Controller uses its configured default.

Raises:
RequiredArgument: If agent_id is missing.
ValueError: If days is negative.
"""
return self._send_request_and_transform_response(
Agents.get_agent_support_bundle(
agent_id,
days=days,
)
)

def create_credential_store_credential(
self,
name: str,
Expand Down
33 changes: 33 additions & 0 deletions gvm/protocols/gmp/requests/next/_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,36 @@ def modify_agent_control_scan_config(
def sync_agents(cls) -> Request:
"""Trigger agents synchronization from all agent controllers."""
return XmlCommand("sync_agents")

@classmethod
def get_agent_support_bundle(
cls,
agent_id: EntityID,
*,
days: int = 0,
) -> Request:
"""Request a support bundle for an agent.

Args:
agent_id: ID of the agent to get the support bundle for.
days: Number of days of logs to include. If None, zero is sent so the
Agent Controller uses its configured default.

Raises:
RequiredArgument: If agent_id is missing.
ValueError: If days is negative.
"""
if not agent_id:
raise RequiredArgument(
function=cls.get_agent_support_bundle.__name__,
argument="agent_id",
)

if days < 0:
raise ValueError("days must be greater than or equal to zero")

cmd = XmlCommand("get_agent_support_bundle")
cmd.set_attribute("agent_uuid", str(agent_id))
cmd.set_attribute("days", str(days))

return cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SPDX-FileCopyrightText: 2026 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

from gvm.errors import RequiredArgument


class GmpGetAgentSupportBundleTestMixin:
def test_get_agent_support_bundle(self):
self.gmp.get_agent_support_bundle(
agent_id="agent-123",
days=7,
)

self.connection.send.has_been_called_with(
b'<get_agent_support_bundle agent_uuid="agent-123" days="7"/>'
)

def test_get_agent_support_bundle_without_days_uses_zero(self):
self.gmp.get_agent_support_bundle(
agent_id="agent-123",
)

self.connection.send.has_been_called_with(
b'<get_agent_support_bundle agent_uuid="agent-123" days="0"/>'
)

def test_get_agent_support_bundle_with_zero_days(self):
self.gmp.get_agent_support_bundle(
agent_id="agent-123",
days=0,
)

self.connection.send.has_been_called_with(
b'<get_agent_support_bundle agent_uuid="agent-123" days="0"/>'
)

def test_get_agent_support_bundle_without_agent_id(self):
with self.assertRaises(RequiredArgument):
self.gmp.get_agent_support_bundle(
agent_id=None,
days=7,
)

with self.assertRaises(RequiredArgument):
self.gmp.get_agent_support_bundle(
agent_id="",
days=7,
)

def test_get_agent_support_bundle_with_negative_days(self):
with self.assertRaises(ValueError):
self.gmp.get_agent_support_bundle(
agent_id="agent-123",
days=-1,
)
9 changes: 9 additions & 0 deletions tests/protocols/gmpnext/entities/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from .agents.test_delete_agents import (
GmpDeleteAgentsTestMixin,
)
from .agents.test_get_agent_support_bundle import (
GmpGetAgentSupportBundleTestMixin,
)
from .agents.test_get_agents import (
GmpGetAgentsTestMixin,
)
Expand Down Expand Up @@ -39,3 +42,9 @@ class GMPModifyAgentControllerScanConfigTestCase(

class GMPSyncAgentsTestCase(GmpSyncAgentsTestMixin, GMPTestCase):
pass


class GmpGetAgentSupportBundleTestCase(
GmpGetAgentSupportBundleTestMixin, GMPTestCase
):
pass
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading