Skip to content

Commit 7f355dd

Browse files
committed
fix: fix agent group command by adding scheduler_cron_time
Update the create and modify agent group command to include the mandatory scheduler_cron_time parameter.
1 parent acf6ccf commit 7f355dd

4 files changed

Lines changed: 62 additions & 5 deletions

File tree

gvm/protocols/gmp/_gmpnext.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def create_agent_group(
228228
self,
229229
name: str,
230230
agent_ids: list[str],
231+
scheduler_cron_time: str,
231232
*,
232233
comment: str | None = None,
233234
) -> T:
@@ -236,6 +237,7 @@ def create_agent_group(
236237
Args:
237238
name: Name of the new agent group.
238239
agent_ids: List of agent UUIDs to include in the group (required).
240+
scheduler_cron_time: Scheduler cron to use.
239241
comment: Optional comment for the group.
240242
241243
Raises:
@@ -246,12 +248,14 @@ def create_agent_group(
246248
name=name,
247249
comment=comment,
248250
agent_ids=agent_ids,
251+
scheduler_cron_time=scheduler_cron_time,
249252
)
250253
)
251254

252255
def modify_agent_group(
253256
self,
254257
agent_group_id: EntityID,
258+
scheduler_cron_time: str,
255259
*,
256260
name: str | None = None,
257261
comment: str | None = None,
@@ -262,6 +266,7 @@ def modify_agent_group(
262266
Args:
263267
agent_group_id: UUID of the group to modify.
264268
name: Optional new name for the group.
269+
scheduler_cron_time: Scheduler cron to use.
265270
comment: Optional comment for the group.
266271
agent_ids: Optional list of agent UUIDs to set for the group.
267272
@@ -274,6 +279,7 @@ def modify_agent_group(
274279
name=name,
275280
comment=comment,
276281
agent_ids=agent_ids,
282+
scheduler_cron_time=scheduler_cron_time,
277283
)
278284
)
279285

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def create_agent_group(
1616
cls,
1717
name: str,
1818
agent_ids: list[str],
19+
scheduler_cron_time: str,
1920
*,
2021
comment: str | None = None,
2122
) -> Request:
@@ -24,6 +25,7 @@ def create_agent_group(
2425
Args:
2526
name: Name of the new agent group.
2627
agent_ids: List of agent UUIDs to include in the group (required).
28+
scheduler_cron_time: Cron-like time to schedule new agent groups (required).
2729
comment: Optional comment for the group.
2830
2931
Raises:
@@ -38,9 +40,15 @@ def create_agent_group(
3840
raise RequiredArgument(
3941
function=cls.create_agent_group.__name__, argument="agent_ids"
4042
)
43+
if not scheduler_cron_time:
44+
raise RequiredArgument(
45+
function=cls.create_agent_group.__name__,
46+
argument="scheduler_cron_time",
47+
)
4148

4249
cmd = XmlCommand("create_agent_group")
4350
cmd.add_element("name", name)
51+
cmd.add_element("scheduler_cron_time", scheduler_cron_time)
4452

4553
if comment:
4654
cmd.add_element("comment", comment)
@@ -76,6 +84,7 @@ def clone_agent_group(cls, agent_group_id: EntityID) -> Request:
7684
def modify_agent_group(
7785
cls,
7886
agent_group_id: EntityID,
87+
scheduler_cron_time: str,
7988
*,
8089
name: str | None = None,
8190
comment: str | None = None,
@@ -85,6 +94,7 @@ def modify_agent_group(
8594
8695
Args:
8796
agent_group_id: UUID of the group to modify.
97+
scheduler_cron_time: Cron-like time to schedule the agent groups.
8898
name: Optional new name for the group.
8999
comment: Optional comment for the group.
90100
agent_ids: Optional list of agent UUIDs to set for the group.
@@ -98,9 +108,15 @@ def modify_agent_group(
98108
argument="agent_group_id",
99109
)
100110

111+
if not scheduler_cron_time:
112+
raise RequiredArgument(
113+
function=cls.modify_agent_group.__name__,
114+
argument="scheduler_cron_time",
115+
)
116+
101117
cmd = XmlCommand("modify_agent_group")
102118
cmd.set_attribute("agent_group_id", str(agent_group_id))
103-
119+
cmd.add_element("scheduler_cron_time", scheduler_cron_time)
104120
if name:
105121
cmd.add_element("name", name)
106122

tests/protocols/gmpnext/entities/agent_groups/test_create_agent_group.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,49 @@ def test_create_agent_group(self):
1111
name="ExampleGroup",
1212
agent_ids=["agent-1", "agent-2"],
1313
comment="Sample comment",
14+
scheduler_cron_time="0 */5 * * *",
1415
)
1516

1617
self.connection.send.has_been_called_with(
1718
b"<create_agent_group>"
1819
b"<name>ExampleGroup</name>"
20+
b"<scheduler_cron_time>0 */5 * * *</scheduler_cron_time>"
1921
b"<comment>Sample comment</comment>"
2022
b'<agents><agent id="agent-1"/><agent id="agent-2"/></agents>'
2123
b"</create_agent_group>"
2224
)
2325

2426
def test_create_agent_group_without_name(self):
2527
with self.assertRaises(RequiredArgument):
26-
self.gmp.create_agent_group(name="", agent_ids=["agent-1"])
28+
self.gmp.create_agent_group(
29+
name="",
30+
agent_ids=["agent-1"],
31+
scheduler_cron_time="0 */5 * * *",
32+
)
2733

2834
def test_create_agent_group_without_agents(self):
2935
with self.assertRaises(RequiredArgument):
30-
self.gmp.create_agent_group(name="Group", agent_ids=[])
36+
self.gmp.create_agent_group(
37+
name="Group", agent_ids=[], scheduler_cron_time="0 */5 * * *"
38+
)
39+
40+
def test_create_agent_group_without_scheduler_cron_time(self):
41+
with self.assertRaises(RequiredArgument):
42+
self.gmp.create_agent_group(
43+
name="Group", agent_ids=["agent-1"], scheduler_cron_time=None
44+
)
3145

3246
def test_create_agent_group_without_comment(self):
33-
self.gmp.create_agent_group(name="GroupX", agent_ids=["a1", "a2"])
47+
self.gmp.create_agent_group(
48+
name="GroupX",
49+
agent_ids=["a1", "a2"],
50+
scheduler_cron_time="0 */5 * * *",
51+
)
3452

3553
self.connection.send.has_been_called_with(
3654
b"<create_agent_group>"
3755
b"<name>GroupX</name>"
56+
b"<scheduler_cron_time>0 */5 * * *</scheduler_cron_time>"
3857
b'<agents><agent id="a1"/><agent id="a2"/></agents>'
3958
b"</create_agent_group>"
4059
)

tests/protocols/gmpnext/entities/agent_groups/test_modify_agent_group.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ def test_modify_agent_group(self):
1111
agent_group_id="group-1",
1212
name="NewName",
1313
comment="Updated comment",
14+
scheduler_cron_time="0 */5 * * *",
1415
agent_ids=["agent-1", "agent-2"],
1516
)
1617

1718
self.connection.send.has_been_called_with(
1819
b'<modify_agent_group agent_group_id="group-1">'
20+
b"<scheduler_cron_time>0 */5 * * *</scheduler_cron_time>"
1921
b"<name>NewName</name>"
2022
b"<comment>Updated comment</comment>"
2123
b'<agents><agent id="agent-1"/><agent id="agent-2"/></agents>'
@@ -24,17 +26,27 @@ def test_modify_agent_group(self):
2426

2527
def test_modify_agent_group_without_id(self):
2628
with self.assertRaises(RequiredArgument):
27-
self.gmp.modify_agent_group(agent_group_id=None)
29+
self.gmp.modify_agent_group(
30+
agent_group_id=None, scheduler_cron_time="0 */5 * * *"
31+
)
32+
33+
def test_modify_agent_group_without_scheduler_cron_time(self):
34+
with self.assertRaises(RequiredArgument):
35+
self.gmp.modify_agent_group(
36+
agent_group_id="group-1", scheduler_cron_time=None
37+
)
2838

2939
def test_modify_agent_group_without_name(self):
3040
self.gmp.modify_agent_group(
3141
agent_group_id="group-1",
3242
comment="Updated comment",
43+
scheduler_cron_time="0 */5 * * *",
3344
agent_ids=["agent-1", "agent-2"],
3445
)
3546

3647
self.connection.send.has_been_called_with(
3748
b'<modify_agent_group agent_group_id="group-1">'
49+
b"<scheduler_cron_time>0 */5 * * *</scheduler_cron_time>"
3850
b"<comment>Updated comment</comment>"
3951
b'<agents><agent id="agent-1"/><agent id="agent-2"/></agents>'
4052
b"</modify_agent_group>"
@@ -44,11 +56,13 @@ def test_modify_agent_group_without_comment(self):
4456
self.gmp.modify_agent_group(
4557
agent_group_id="group-1",
4658
name="NewName",
59+
scheduler_cron_time="0 */5 * * *",
4760
agent_ids=["agent-1", "agent-2"],
4861
)
4962

5063
self.connection.send.has_been_called_with(
5164
b'<modify_agent_group agent_group_id="group-1">'
65+
b"<scheduler_cron_time>0 */5 * * *</scheduler_cron_time>"
5266
b"<name>NewName</name>"
5367
b'<agents><agent id="agent-1"/><agent id="agent-2"/></agents>'
5468
b"</modify_agent_group>"
@@ -59,10 +73,12 @@ def test_modify_agent_group_without_agent_ids(self):
5973
agent_group_id="group-1",
6074
name="NewName",
6175
comment="Updated comment",
76+
scheduler_cron_time="0 */5 * * *",
6277
)
6378

6479
self.connection.send.has_been_called_with(
6580
b'<modify_agent_group agent_group_id="group-1">'
81+
b"<scheduler_cron_time>0 */5 * * *</scheduler_cron_time>"
6682
b"<name>NewName</name>"
6783
b"<comment>Updated comment</comment>"
6884
b"</modify_agent_group>"

0 commit comments

Comments
 (0)