Skip to content

Instantly share code, notes, and snippets.

@iomarmochtar
Created September 22, 2018 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iomarmochtar/5bf74f283c065f9e2db0bcb5664c6f9f to your computer and use it in GitHub Desktop.
Save iomarmochtar/5bf74f283c065f9e2db0bcb5664c6f9f to your computer and use it in GitHub Desktop.
Get all COS (Class Of Service) including user assigned to it. #zimbra
#!/opt/zimbra/bin/zmpython
__author__ = ('Imam Omar Mochtar', ('iomarmochtar@gmail.com', 'imam.omar@jabetto.com'))
"""
Get all COS including user assigned to it. you may run this script inside zimbra's server (LDAP server is recommended)
"""
from com.zimbra.cs.account import Provisioning
prov = Provisioning.getInstance()
default_cos_name = 'default'
default_id = None
coses = {'na': {'name': 'UNKNOWN', 'members': []}}
for cos in prov.getAllCos():
if cos.name == default_cos_name:
default_id = cos.id
coses[cos.id] = {'name': cos.name, 'members': []}
for user in prov.getAllAccounts(None):
if user.isIsSystemAccount():
continue
mail = user.getMail()
cos_id = user.COSId
# if COS id not exist then set to default one
if not cos_id and default_id:
cos_id = default_id
elif not cos_id:
cos_id = 'na'
coses[cos_id]['members'].append(mail)
# print out the result
xn = 10
for cos_id, data in coses.items():
if data['name'] == 'na' and not data['members']:
continue
print("#"*xn)
print("# %s"%data['name'])
print("%s"%("#"*xn))
if not data['members']:
print("*EMPTY*")
else:
for member in data['members']:
print("- %s"%member)
print("%s\n"%("#"*xn))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment