Closed shnacharya closed 5 years ago
Zabbix 4.0 had changes in the Email media type and in the user API. There is no more a user.updatemedia method. Every user update is done by the user.update method. And the "sendto" parameter for the Email media type is now an array and no more a string. I'm not a developer, but I'll take a look at the code and see if I can fix, as we are planning on updating to 4.0 before October 31. One may refer to the API documentation (user.create,user.update) on how to deal with user media types.
Also getting this exception when updating users:
pyzabbix.ZabbixAPIException: ('Error -32602: Invalid params., Incorrect method "usergroup.massadd".', -32602)
Yes, we are experiencing the same problem. This is because usergroup.massadd has been deprecated. This is used in lib/zabbixconn.py. It states to replace this with usergroup.update but I could not get it working as my Python skills are not that great. Hopefully, the maintainer will see this and correct this in the update_user function.
Noticed the same issue. Changing usergroup.massadd to the supported API method is not enough.
Hi again. I finally did get this working using supported API calls. I am basically getting a list of the userids for the groupid passed with the function. I then check to see if the userid from the user sent with the function is in the list. If it isn't I append it and the userid list is rewritten. I added a function called get_group_memberids that returns the array of userids in a group. The function get_group_members returned the usernames. All changes were done in the lib/zabbixconn.py file. I will see if there is someway to update the file here on github. Need to speak to a colleague about that.
I changed the update_user function as follows: def update_user(self, user, groupid): """ Adds an existing Zabbix user to a group
Args:
user (dict): A dict containing the user details
groupid (int): The groupid to add the user to
"""
userid = self.get_user_id(user)
userlist = self.get_group_memberids(groupid)
if userid not in userlist:
userlist.append(userid)
result = self.conn.usergroup.update(usrgrpid=groupid, userids=userlist)
return result
And here the new function: def get_group_memberids(self, groupid): """ Retrieves group memberids for a Zabbix group
Args:
groupid (int): The group id
Returns:
A list of the Zabbix user ids for the specified group id
"""
result = self.conn.user.get(output='extend', usrgrpids=groupid)
userids = [user['userid'] for user in result]
return userids
Fix with pull request.
Traceback (most recent call last):
File "./zabbix-ldap-sync", line 92, in
On Mon, 25 Feb 2019 at 02:27, Marc Schöchlin notifications@github.com wrote:
Closed #7 https://github.com/zabbix-tooling/zabbix-ldap-sync/issues/7.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/zabbix-tooling/zabbix-ldap-sync/issues/7#event-2160330476, or mute the thread https://github.com/notifications/unsubscribe-auth/AMMLU3bAMYbDC_MkY8HTaUfymzBdBG7Yks5vQvzCgaJpZM4Wx8Ae .
Traceback (most recent call last): File "./zabbix-ldap-sync", line 92, in
main()
File "./zabbix-ldap-sync", line 89, in main
zabbix_conn.sync_users()
File "/usr/local/zabbix-ldap-sync/lib/zabbixconn.py", line 428, in sync_users
self.update_media(eachUser, self.media_description, sendto, media_opt_filtered)
File "/usr/local/zabbix-ldap-sync/lib/zabbixconn.py", line 263, in update_media
result = self.conn.user.updatemedia(users=[{"userid": str(userid)}], medias=media_defaults)
File "/usr/lib/python3.6/site-packages/pyzabbix/init.py", line 157, in fn
args or kwargs
File "/usr/lib/python3.6/site-packages/pyzabbix/init.py", line 134, in do_request
raise ZabbixAPIException(msg, response_json['error']['code'])
pyzabbix.ZabbixAPIException: ('Error -32602: Invalid params., Incorrect method "user.updatemedia".', -32602)