Skip to content

Commit

Permalink
change create_user to check if group already exists in list and chang…
Browse files Browse the repository at this point in the history
…e alias to username and type roleid when zabbix version upper or egal 6
  • Loading branch information
Mélissa BERTIN committed May 31, 2022
1 parent ebcfce8 commit 0000b3c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions zabbix_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3338,12 +3338,14 @@ def do_create_user(self, args):
for usrgrp in usergroup_default.split(','):
if usrgrp != '':
usrgrp_id = str(self.get_usergroup_id(usrgrp.strip()))
usergroup_list.append({"usrgrpid": usrgrp_id})
if {"usrgrpid": usrgrp_id} not in usergroup_list:
usergroup_list.append({"usrgrpid": usrgrp_id})

for usrgrp in usrgrps.split(','):
if usrgrp != '':
usrgrp_id = str(self.get_usergroup_id(usrgrp.strip()))
usergroup_list.append({"usrgrpid": usrgrp_id})
if {"usrgrpid": usrgrp_id} not in usergroup_list:
usergroup_list.append({"usrgrpid": usrgrp_id})

except Exception as e:
logger.error('Problems getting usergroupID - %s', e)
Expand All @@ -3355,7 +3357,11 @@ def do_create_user(self, args):
#

try:
result = self.zapi.user.get(search={'alias': alias}, output='extend', searchWildcardsEnabled=True)
if self.zabbix_version >=6:
search = {'username': alias}
else:
search = {'alias': alias}
result = self.zapi.user.get(search=search, output='extend', searchWildcardsEnabled=True)
logger.debug('Checking if user (%s) exists', alias)

except Exception as e:
Expand All @@ -3374,7 +3380,17 @@ def do_create_user(self, args):
self.generate_feedback('Warning', 'This user (' + alias + ') already exists.')
return False
else:
result = self.zapi.user.create(alias=alias,
if self.zabbix_version >=6:
result = self.zapi.user.create(username=alias,
name=name,
surname=surname,
passwd=passwd,
roleid=type,
autologin=autologin,
autologout=autologout,
usrgrps=usergroup_list)
else:
result = self.zapi.user.create(alias=alias,
name=name,
surname=surname,
passwd=passwd,
Expand Down

0 comments on commit 0000b3c

Please sign in to comment.