Skip to content

Commit

Permalink
Fix: Specifying multiple names or IDs causing only last value to be s…
Browse files Browse the repository at this point in the history
…elected (#282)
  • Loading branch information
pederhan authored Jan 17, 2025
1 parent a999f41 commit 7eed0f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- released start -->

<!-- ## [Unreleased] -->
## [Unreleased]

### Fixed

- `create_maintenance_definition` with multiple host groups only including the first group in the maintenance definition for Zabbix >=6.0.
- `add_user_to_usergroup` and `remove_user_from_usergroup` using deprecated API parameters for Zabbix >=6.0.
- Commands that allow multiple names or IDs to be specified should now correctly handle searching for multiple values.

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

Expand Down
2 changes: 1 addition & 1 deletion zabbix_cli/commands/usergroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def add_user_to_usergroup(
) -> None:
"""Add users to usergroups.
Ignores users not in user groups. Users and groups must exist.
Users and groups must exist.
"""
from zabbix_cli.commands.results.usergroup import UsergroupAddUsers

Expand Down
14 changes: 11 additions & 3 deletions zabbix_cli/pyzabbix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def parse_name_or_id_arg(
if "*" in names_or_ids:
names_or_ids = tuple()

if len(names_or_ids) > 1:
logger.debug(
"Multiple names or IDs provided, using search instead of filter for %s",
names_or_ids,
stacklevel=2,
)
search = True

if names_or_ids:
for name_or_id in names_or_ids:
name_or_id = name_or_id.strip()
Expand Down Expand Up @@ -1273,10 +1281,10 @@ def _update_usergroup_users(
new_userids = list(set(current_userids + ids_update))

if self.version.release >= (6, 0, 0):
params["users"] = {"userid": uid for uid in new_userids}
params["users"] = [{"userid": uid} for uid in new_userids]
else:
params["userids"] = new_userids
self.usergroup.update(usrgrpid=usergroup.usrgrpid, userids=new_userids)
self.usergroup.update(**params)

def update_usergroup_rights(
self,
Expand Down Expand Up @@ -2224,7 +2232,7 @@ def create_maintenance(
params["hostids"] = [h.hostid for h in hosts]
if hostgroups:
if self.version.release >= (6, 0, 0):
params["groups"] = {"groupid": hg.groupid for hg in hostgroups}
params["groups"] = [{"groupid": hg.groupid} for hg in hostgroups]
else:
params["groupids"] = [hg.groupid for hg in hostgroups]
if data_collection:
Expand Down

0 comments on commit 7eed0f7

Please sign in to comment.