1st version of agent completed
This commit is contained in:
parent
f05cbfec69
commit
53f70cdac6
@ -124,6 +124,21 @@ def getDomainInfo(headers, verify, base_url):
|
||||
bytes_total = data[i].get("bytes_total")
|
||||
# get maximum quota for this domain
|
||||
max_quota_for_domain = data[i].get("max_quota_for_domain")
|
||||
# store all domain data in global dictionary
|
||||
dom = {
|
||||
"active": active,
|
||||
"created": created,
|
||||
"modified": modified,
|
||||
"max_num_mboxes_for_domain": max_num_mboxes_for_domain,
|
||||
"mboxes_in_domain": mboxes_in_domain,
|
||||
"max_num_aliases_for_domain": max_num_aliases_for_domain,
|
||||
"aliases_in_domain": aliases_in_domain,
|
||||
"msgs_total": msgs_total,
|
||||
"bytes_total": bytes_total,
|
||||
"max_quota_for_domain": max_quota_for_domain
|
||||
}
|
||||
domain_data[domain_name] = {}
|
||||
domain_data[domain_name] = dom
|
||||
i += 1
|
||||
# return number of email domains
|
||||
return i
|
||||
@ -141,7 +156,6 @@ def getMailboxInfo(headers, verify, base_url):
|
||||
i = 0
|
||||
global_num_messages = 0
|
||||
while i < len(data):
|
||||
#pprint(data[i])
|
||||
# get status of mailbox (0-->inactive or 1-->active)
|
||||
active = data[i].get("active")
|
||||
# get username of mailbox
|
||||
@ -164,6 +178,22 @@ def getMailboxInfo(headers, verify, base_url):
|
||||
last_imap_login = data[i].get("last_imap_login")
|
||||
last_pop3_login = data[i].get("last_pop3_login")
|
||||
last_smtp_login = data[i].get("last_smtp_login")
|
||||
mb = {
|
||||
"active": active,
|
||||
"created": created,
|
||||
"modified": modified,
|
||||
"name": name,
|
||||
"num_messages": num_messages,
|
||||
"percent_in_use": percent_in_use,
|
||||
"quota": quota,
|
||||
"quota_used": quota_used,
|
||||
"messages": messages,
|
||||
"last_imap_login": last_imap_login,
|
||||
"last_pop3_login": last_pop3_login,
|
||||
"last_smtp_login": last_smtp_login
|
||||
}
|
||||
mailbox_data[username] = {}
|
||||
mailbox_data[username] = mb
|
||||
i += 1
|
||||
global_num_messages += num_messages
|
||||
# return number of mailboxes and global number of messages
|
||||
@ -187,6 +217,84 @@ def getMailcowInfo(headers, verify, base_url):
|
||||
sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n")
|
||||
sys.exit(1)
|
||||
|
||||
'''
|
||||
Output is as follows:
|
||||
mailbox name email address used for login
|
||||
active 1 --> active, 0 --> not active
|
||||
creation date
|
||||
last modified date "None" if never modified
|
||||
name display name
|
||||
number of messages
|
||||
percent in use quota used, rounded to full percents
|
||||
quota max quota in bytes
|
||||
quota used quota used in bytes
|
||||
last imap login seconds since epoch, 0 if never logged inin seconds since epoch
|
||||
last pop3 login seconds since epoch, 0 if never logged in
|
||||
last smtp login seconds since epoch, 0 if never logged in
|
||||
|
||||
Example:
|
||||
user1@dom1.de;1;2022-04-29 14:29:34;2022-04-29 14:29:34;Sarah;2433;2;21474836480;495481374;1692520168;0;1692281537
|
||||
user2@dom1.de;1;2022-04-29 14:38:33;2022-04-29 14:38:33;Tom;271;0;21474836480;25895752;1657394782;1692519758;1681065713
|
||||
user1@dom2.de;1;2022-04-30 09:55:37;2022-04-30 09:55:37;Melissa;53460;33;19964887040;6677677548;1692520066;0;1692510822
|
||||
'''
|
||||
|
||||
def doCmkOutputMailboxes():
|
||||
print("<<<mailcow_mailboxes:sep(59)>>>")
|
||||
for mb in mailbox_data:
|
||||
active = mailbox_data[mb]["active"]
|
||||
created = mailbox_data[mb]["created"]
|
||||
modified = mailbox_data[mb]["modified"]
|
||||
name = mailbox_data[mb]["name"]
|
||||
num_messages = mailbox_data[mb]["num_messages"]
|
||||
percent_in_use = mailbox_data[mb]["percent_in_use"]
|
||||
quota = mailbox_data[mb]["quota"]
|
||||
quota_used = mailbox_data[mb]["quota_used"]
|
||||
last_imap_login = mailbox_data[mb]["last_imap_login"]
|
||||
last_pop3_login = mailbox_data[mb]["last_pop3_login"]
|
||||
last_smtp_login = mailbox_data[mb]["last_smtp_login"]
|
||||
print(f"{mb};{active};{created};{modified};{name};{num_messages};{percent_in_use};{quota};{quota_used};{last_imap_login};{last_pop3_login};{last_smtp_login}")
|
||||
|
||||
|
||||
def doCmkOutputMailcow(version, num_domains, num_mailboxes, num_global_messages):
|
||||
print("<<<mailcow_info:sep(59)>>>")
|
||||
print(f"{version};{num_domains};{num_mailboxes};{num_global_messages}")
|
||||
|
||||
|
||||
'''
|
||||
Output is as follows:
|
||||
domain_name
|
||||
active 1 --> active, 0 --> not active
|
||||
creation date
|
||||
last modified date "None" if never modified
|
||||
max number mailboxes
|
||||
number of mailboxes
|
||||
max number of aliases
|
||||
number of aliases
|
||||
total number of messages
|
||||
total number of bytes used in bytes
|
||||
max quota in bytes
|
||||
|
||||
Example:
|
||||
dom1.de;1;2022-04-23 22:54:57;None;10;0;400;6;0;0;10737418240
|
||||
dom2.de;1;2022-04-29 13:38:42;2023-08-19 17:21:04;10;0;400;2;0;0;10737418240
|
||||
dom3.de;1;2022-04-29 13:36:08;2022-04-29 21:26:19;10;1;100;3;28132;12852485367;21474836480
|
||||
'''
|
||||
|
||||
def doCmkOutputDomains():
|
||||
print("<<<mailcow_domains:sep(59)>>>")
|
||||
for dom in domain_data:
|
||||
active = domain_data[dom]["active"]
|
||||
created = domain_data[dom]["created"]
|
||||
modified = domain_data[dom]["modified"]
|
||||
max_num_mboxes_for_domain = domain_data[dom]["max_num_mboxes_for_domain"]
|
||||
mboxes_in_domain = domain_data[dom]["mboxes_in_domain"]
|
||||
max_num_aliases_for_domain = domain_data[dom]["max_num_aliases_for_domain"]
|
||||
aliases_in_domain = domain_data[dom]["aliases_in_domain"]
|
||||
msgs_total = domain_data[dom]["msgs_total"]
|
||||
bytes_total = domain_data[dom]["bytes_total"]
|
||||
max_quota_for_domain = domain_data[dom]["max_quota_for_domain"]
|
||||
print(f"{dom};{active};{created};{modified};{max_num_mboxes_for_domain};{mboxes_in_domain};{max_num_aliases_for_domain};{aliases_in_domain};{msgs_total};{bytes_total};{max_quota_for_domain}")
|
||||
|
||||
|
||||
def main():
|
||||
getOptions()
|
||||
@ -244,6 +352,11 @@ def main():
|
||||
num_mailboxes, num_global_messages = getMailboxInfo(headers, verify, base_url)
|
||||
# get global Mailcow info
|
||||
mailcow_version = getMailcowInfo(headers, verify, base_url)
|
||||
# create agent output
|
||||
doCmkOutputDomains()
|
||||
doCmkOutputMailboxes()
|
||||
doCmkOutputMailcow(mailcow_version, num_domains, num_mailboxes, num_global_messages)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user