Skip to content

Commit 7eed0f7

Browse files
authored
Fix: Specifying multiple names or IDs causing only last value to be selected (#282)
1 parent a999f41 commit 7eed0f7

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

CHANGELOG

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
<!-- released start -->
99

10-
<!-- ## [Unreleased] -->
10+
## [Unreleased]
11+
12+
### Fixed
13+
14+
- `create_maintenance_definition` with multiple host groups only including the first group in the maintenance definition for Zabbix >=6.0.
15+
- `add_user_to_usergroup` and `remove_user_from_usergroup` using deprecated API parameters for Zabbix >=6.0.
16+
- Commands that allow multiple names or IDs to be specified should now correctly handle searching for multiple values.
1117

1218
## [3.5.0](https://github.com/unioslo/zabbix-cli/releases/tag/3.5.0) - 2025-01-13
1319

zabbix_cli/commands/usergroup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def add_user_to_usergroup(
8787
) -> None:
8888
"""Add users to usergroups.
8989
90-
Ignores users not in user groups. Users and groups must exist.
90+
Users and groups must exist.
9191
"""
9292
from zabbix_cli.commands.results.usergroup import UsergroupAddUsers
9393

zabbix_cli/pyzabbix/client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ def parse_name_or_id_arg(
169169
if "*" in names_or_ids:
170170
names_or_ids = tuple()
171171

172+
if len(names_or_ids) > 1:
173+
logger.debug(
174+
"Multiple names or IDs provided, using search instead of filter for %s",
175+
names_or_ids,
176+
stacklevel=2,
177+
)
178+
search = True
179+
172180
if names_or_ids:
173181
for name_or_id in names_or_ids:
174182
name_or_id = name_or_id.strip()
@@ -1273,10 +1281,10 @@ def _update_usergroup_users(
12731281
new_userids = list(set(current_userids + ids_update))
12741282

12751283
if self.version.release >= (6, 0, 0):
1276-
params["users"] = {"userid": uid for uid in new_userids}
1284+
params["users"] = [{"userid": uid} for uid in new_userids]
12771285
else:
12781286
params["userids"] = new_userids
1279-
self.usergroup.update(usrgrpid=usergroup.usrgrpid, userids=new_userids)
1287+
self.usergroup.update(**params)
12801288

12811289
def update_usergroup_rights(
12821290
self,
@@ -2224,7 +2232,7 @@ def create_maintenance(
22242232
params["hostids"] = [h.hostid for h in hosts]
22252233
if hostgroups:
22262234
if self.version.release >= (6, 0, 0):
2227-
params["groups"] = {"groupid": hg.groupid for hg in hostgroups}
2235+
params["groups"] = [{"groupid": hg.groupid} for hg in hostgroups]
22282236
else:
22292237
params["groupids"] = [hg.groupid for hg in hostgroups]
22302238
if data_collection:

0 commit comments

Comments
 (0)