diff --git a/local/lib/python3/cmk/base/plugins/agent_based/mailcow_info.py b/local/lib/python3/cmk/base/plugins/agent_based/mailcow_info.py index 2c7568c..3dabad3 100644 --- a/local/lib/python3/cmk/base/plugins/agent_based/mailcow_info.py +++ b/local/lib/python3/cmk/base/plugins/agent_based/mailcow_info.py @@ -22,23 +22,16 @@ def getStateLower(levels, value): def discover_mailcow_info(section): - yield(Service()) + yield (Service()) -def check_mailcow_info(params, section): +def check_mailcow_info(params, section): for key in section: if key == "mailcow": # get thresholds levels_num_domains = params["levels_num_domains"] levels_num_mailboxes = params["levels_num_mailboxes"] levels_num_global_messages = params["levels_num_global_messages"] - levels_solr_size_kb = params["levels_solr_size"] - # Levels for Solr size are given in MBytes, so convert it to bytes - levels_solr_size_warn = levels_solr_size_kb[0] * 1024 * 1024 - levels_solr_size_crit = levels_solr_size_kb[1] * 1024 * 1024 - levels_solr_size = (levels_solr_size_warn, levels_solr_size_crit) - levels_solr_documents = params["levels_solr_documents"] - version = section[key]["version"] git_version = section[key]["git_version"] check_version_enabled = section[key]["check_version_enabled"] @@ -46,19 +39,19 @@ def check_mailcow_info(params, section): num_domains = section[key]["num_domains"] num_mailboxes = section[key]["num_mailboxes"] num_global_messages = section[key]["num_global_messages"] - solr_enabled = section[key]["solr_enabled"] - solr_size = section[key]["solr_size"] - solr_documents = section[key]["solr_documents"] # create graphs for number of domains, mailboxes and messages - yield(Metric("mc_num_domains", num_domains, levels=levels_num_domains)) - yield(Metric("mc_num_mailboxes", num_mailboxes, levels=levels_num_mailboxes)) - yield(Metric("mc_num_global_messages", num_global_messages, levels=levels_num_global_messages)) - - # create graphs for solr size and number of solr documents - if solr_enabled: - yield(Metric("mc_solr_size", solr_size, levels=levels_solr_size)) - yield(Metric("mc_solr_documents", solr_documents, levels=levels_solr_documents)) + yield (Metric("mc_num_domains", num_domains, levels=levels_num_domains)) + yield ( + Metric("mc_num_mailboxes", num_mailboxes, levels=levels_num_mailboxes) + ) + yield ( + Metric( + "mc_num_global_messages", + num_global_messages, + levels=levels_num_global_messages, + ) + ) # create overall result if check_version_enabled: @@ -71,7 +64,7 @@ def check_mailcow_info(params, section): else: summary = f"Version is {version}, Update check is disabled" state = State.OK - details = f"Mailcow version: {version}\nNumber of domains: {num_domains}\nNumber of mailboxes: {num_mailboxes}\nNumber of messages: {num_global_messages}\n\nSolr size: {render.bytes(solr_size)}\nNumber of Solr documents: {solr_documents}" + details = f"Mailcow version: {version}\nNumber of domains: {num_domains}\nNumber of mailboxes: {num_mailboxes}\nNumber of messages: {num_global_messages}" yield Result(state=state, summary=summary, details=details) # Create result for number of domains @@ -79,45 +72,27 @@ def check_mailcow_info(params, section): state = getStateUpper((warn, crit), num_domains) notice = f"Number of domains: {num_domains}" if state != State.OK: - yield(Result(state=state, notice=notice)) + yield (Result(state=state, notice=notice)) # Create result for number of mailboxes warn, crit = levels_num_mailboxes state = getStateUpper((warn, crit), num_mailboxes) notice = f"Number of mailboxes: {num_mailboxes}" if state != State.OK: - yield(Result(state=state, notice=notice)) + yield (Result(state=state, notice=notice)) # Create result for number of global messages warn, crit = levels_num_global_messages state = getStateUpper((warn, crit), num_global_messages) notice = f"Number of messages: {num_global_messages}" if state != State.OK: - yield(Result(state=state, notice=notice)) + yield (Result(state=state, notice=notice)) - # Create result for solr size and solr number of documents - if solr_enabled: - warn, crit = levels_solr_size - state = getStateUpper((warn, crit), solr_size) - notice = f"Solr size: {render.bytes(solr_size)}" - if state != State.OK: - yield(Result(state=state, notice=notice)) - warn, crit = levels_solr_documents - state = getStateUpper((warn, crit), solr_documents) - notice = f"Number of Solr documents: {solr_documents}" - if state != State.OK: - yield(Result(state=state, notice=notice)) - else: - state = State.WARN - notice = f"Solr is disabled" - yield(Result(state=state, notice=notice)) - - def parse_mailcow_info_section(string_table): - #pprint(string_table) + # pprint(string_table) parsed_data = { - "mailcow" : {}, + "mailcow": {}, } # we expect only one line line = string_table[0] @@ -125,26 +100,13 @@ def parse_mailcow_info_section(string_table): num_domains = int(line[1]) num_mailboxes = int(line[2]) num_global_messages = int(line[3]) - solr_enabled = bool(line[4]) - # solr size comes with value and unit, unfortunately - solr_size_str = line[5] - solr_size_list = solr_size_str.split() - solr_size_unit = solr_size_list[1] - solr_size = float(solr_size_list[0]) - if solr_size_unit == "KB": - solr_size = solr_size * 1024.0 - elif solr_size_unit == "MB": - solr_size = solr_size * 1024.0 * 1024.0 - elif solr_size_unit == "GB": - solr_size = solr_size * 1024.0 * 1024.0 * 1024.0 - solr_documents = int(line[6]) - git_version = line[7] - update_available = line[8] + git_version = line[4] + update_available = line[5] if update_available == "True": update_available = True else: update_available = False - check_version_enabled = line[9] + check_version_enabled = line[6] if check_version_enabled == "True": check_version_enabled = True else: @@ -153,13 +115,10 @@ def parse_mailcow_info_section(string_table): parsed_data["mailcow"]["num_domains"] = num_domains parsed_data["mailcow"]["num_mailboxes"] = num_mailboxes parsed_data["mailcow"]["num_global_messages"] = num_global_messages - parsed_data["mailcow"]["solr_enabled"] = solr_enabled - parsed_data["mailcow"]["solr_size"] = solr_size - parsed_data["mailcow"]["solr_documents"] = solr_documents parsed_data["mailcow"]["git_version"] = git_version parsed_data["mailcow"]["update_available"] = update_available parsed_data["mailcow"]["check_version_enabled"] = check_version_enabled - #pprint(parsed_data) + # pprint(parsed_data) return parsed_data @@ -178,8 +137,6 @@ register.check_plugin( "levels_num_domains": (100, 200), "levels_num_mailboxes": (500, 1000), "levels_num_global_messages": (100000, 250000), - "levels_solr_size": (4096.0, 8192.0), - "levels_solr_documents": (20000, 40000) }, check_ruleset_name="mailcow_info", -) \ No newline at end of file +) diff --git a/local/share/check_mk/agents/special/agent_mailcow b/local/share/check_mk/agents/special/agent_mailcow index c27eed9..88c8b3e 100755 --- a/local/share/check_mk/agents/special/agent_mailcow +++ b/local/share/check_mk/agents/special/agent_mailcow @@ -11,11 +11,15 @@ from pprint import pprint from requests.structures import CaseInsensitiveDict from requests.auth import HTTPBasicAuth from time import ( - time, localtime, strftime, + time, + localtime, + strftime, ) + def showUsage() -> None: - sys.stderr.write("""CheckMK Mailcow Special Agent + sys.stderr.write( + """CheckMK Mailcow Special Agent USAGE: agent_nextcloud -H [hostname] -k [apikey] agent_nextcloud -h @@ -28,10 +32,12 @@ OPTIONS: --no-https True|False If "True": Disable HTTPS, use HTTP (not recommended!) --no-cert-check True|False If "True": Disable TLS certificate check (not recommended!) -h, --help Show this help message and exit -""") +""" + ) + # set this to True to produce debug output (this clutters the agent output) -# be aware: activating this logs very sensitive information to debug files in ~/tmp +# be aware: activating this logs very sensitive information to debug files in ~/tmp # !!DO NOT FORGET to delete these files after debugging is done!! DEBUG = False @@ -45,9 +51,15 @@ opt_check_version = False opt_no_https = False opt_no_cert_check = False -short_options = 'hH:k:P:' +short_options = "hH:k:P:" long_options = [ - 'hostname=', 'apikey=', 'port=', 'check-version=', 'no-https=', 'no-cert-check=', 'help' + "hostname=", + "apikey=", + "port=", + "check-version=", + "no-https=", + "no-cert-check=", + "help", ] domain_data = {} @@ -55,11 +67,11 @@ mailbox_data = {} debugLogFilename = "" SEP = "|" -#SEP = "\t" +# SEP = "\t" TIMEFMT = "%Y-%m-%d %H:%M:%S" FLOATFMT = "{:.4f}" -''' +""" Decorator function for debugging purposes creates a file with many information regarding the function call, like: timestamp @@ -70,7 +82,9 @@ Decorator function for debugging purposes return value of function call type of return value all parameters given to function -''' +""" + + def debugLog(function): def wrapper(*args, **kwargs): # execute function and measure runtime @@ -82,7 +96,7 @@ def debugLog(function): len_kwargs = len(kwargs) # format the output seconds = FLOATFMT.format(end - start) - local_time = strftime(TIMEFMT,localtime(start)) + local_time = strftime(TIMEFMT, localtime(start)) # get function name fname = function.__name__ # create output @@ -103,12 +117,15 @@ def debugLog(function): with open(debugLogFilename, "a+") as f: f.write(f"{out1}{out2}{out3}\n") except: - sys.stderr.write(f"Something went wrong when writing to file {debugLogFilename}\n") + sys.stderr.write( + f"Something went wrong when writing to file {debugLogFilename}\n" + ) sys.exit(1) else: sys.stderr.write(f"Debug activated, but no debug filename given.\n") sys.exit(1) return value + return wrapper @@ -129,28 +146,28 @@ def getOptions() -> None: opts, args = getopt.getopt(sys.argv[1:], short_options, long_options) for opt, arg in opts: - if opt in ['-H', '--hostname']: + if opt in ["-H", "--hostname"]: opt_hostname = arg - elif opt in ['-k', '--apikey']: + elif opt in ["-k", "--apikey"]: opt_apikey = arg - elif opt in ['-P', '--port']: + elif opt in ["-P", "--port"]: opt_port = arg - elif opt in ['--check-version']: - if arg == 'True': + elif opt in ["--check-version"]: + if arg == "True": opt_check_version = True else: opt_check_version = False - elif opt in ['--no-https']: - if arg == 'True': + elif opt in ["--no-https"]: + if arg == "True": opt_no_https = True else: opt_no_https = False - elif opt in ['--no-cert-check']: - if arg == 'True': + elif opt in ["--no-cert-check"]: + if arg == "True": opt_no_cert_check = True else: opt_no_cert_check = False - elif opt in ['-h', '--help']: + elif opt in ["-h", "--help"]: showUsage() sys.exit(0) if DEBUG: @@ -158,10 +175,12 @@ def getOptions() -> None: tmp_path = f"{home_path}/tmp" help_file = f"{tmp_path}/mailcow_{opt_hostname}_debug.txt" with open(help_file, "a") as file: - file.write(f"Number of Arguments: {len(sys.argv)}, Argument List: {str(sys.argv)}\n") + file.write( + f"Number of Arguments: {len(sys.argv)}, Argument List: {str(sys.argv)}\n" + ) -#@debugLog +# @debugLog def showOptions() -> None: print(f"Hostname: {opt_hostname}") print(f"Username: {opt_apikey}") @@ -173,24 +192,27 @@ def showOptions() -> None: tmp_path = f"{home_path}/tmp" help_file = f"{tmp_path}/mailcow_{opt_hostname}_debug.txt" with open(help_file, "a") as file: - file.write(f"Hostname: {opt_hostname}, Port: {opt_port}, No HTTPS: {opt_no_https}, No Cert Check: {opt_no_cert_check}\n") + file.write( + f"Hostname: {opt_hostname}, Port: {opt_port}, No HTTPS: {opt_no_https}, No Cert Check: {opt_no_cert_check}\n" + ) -#@debugLog + +# @debugLog def getDomainInfo(headers: str, verify: bool, base_url: str) -> int: url = f"{base_url}/domain/all" response = requests.get(url, headers=headers, verify=verify) - if (response.status_code == 200): + if response.status_code == 200: jsdata = response.text - data = json.loads(jsdata) # returns a list of dictionaries + data = json.loads(jsdata) # returns a list of dictionaries i = 0 while i < len(data): - #pprint(data[i]) + # pprint(data[i]) # get domain name and status (active (1) or not (0)) domain_name = data[i].get("domain_name") active = data[i].get("active") # get creation and last modification date created = data[i].get("created") - modified = data[i].get("modified") # returns "None" or date + modified = data[i].get("modified") # returns "None" or date # get maximum and current number of mailboxes in this domain max_num_mboxes_for_domain = data[i].get("max_num_mboxes_for_domain") mboxes_in_domain = data[i].get("mboxes_in_domain") @@ -214,7 +236,7 @@ def getDomainInfo(headers: str, verify: bool, base_url: str) -> int: "aliases_in_domain": aliases_in_domain, "msgs_total": msgs_total, "bytes_total": bytes_total, - "max_quota_for_domain": max_quota_for_domain + "max_quota_for_domain": max_quota_for_domain, } domain_data[domain_name] = {} domain_data[domain_name] = dom @@ -222,16 +244,19 @@ def getDomainInfo(headers: str, verify: bool, base_url: str) -> int: # return number of email domains return i else: - sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n") + sys.stderr.write( + f"Request response code is {response.status_code} with URL {url}\n" + ) sys.exit(1) -#@debugLog + +# @debugLog def getMailboxInfo(headers: str, verify: bool, base_url: str) -> tuple: url = f"{base_url}/mailbox/all" response = requests.get(url, headers=headers, verify=verify) - if (response.status_code == 200): + if response.status_code == 200: jsdata = response.text - data = json.loads(jsdata) # returns a list of dictionaries + data = json.loads(jsdata) # returns a list of dictionaries i = 0 global_num_messages = 0 while i < len(data): @@ -269,7 +294,7 @@ def getMailboxInfo(headers: str, verify: bool, base_url: str) -> tuple: "messages": messages, "last_imap_login": last_imap_login, "last_pop3_login": last_pop3_login, - "last_smtp_login": last_smtp_login + "last_smtp_login": last_smtp_login, } mailbox_data[username] = {} mailbox_data[username] = mb @@ -278,29 +303,35 @@ def getMailboxInfo(headers: str, verify: bool, base_url: str) -> tuple: # return number of mailboxes and global number of messages return i, global_num_messages else: - sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n") + sys.stderr.write( + f"Request response code is {response.status_code} with URL {url}\n" + ) sys.exit(1) + def getGitVersion() -> str: url = "https://api.github.com/repos/mailcow/mailcow-dockerized/releases/latest" git_version = "" response = requests.get(url) - if (response.status_code == 200): + if response.status_code == 200: jsdata = response.text - data = json.loads(jsdata) # returns a dictionary + data = json.loads(jsdata) # returns a dictionary git_version = data["tag_name"] - #print(git_version) + # print(git_version) else: - sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n") + sys.stderr.write( + f"Request response code is {response.status_code} with URL {url}\n" + ) sys.exit(1) return git_version + def compareVersions(mc_ver: str, git_ver: str) -> bool: update_available = False try: mc_year, mc_month = mc_ver.split("-") git_year, git_month = git_ver.split("-") - #print(mc_year, mc_month, git_year, git_month) + # print(mc_year, mc_month, git_year, git_month) mc_year_int = int(mc_year) git_year_int = int(git_year) if git_year_int > mc_year_int: @@ -332,23 +363,24 @@ def compareVersions(mc_ver: str, git_ver: str) -> bool: pass return update_available -#@debugLog + +# @debugLog def getMailcowInfo(headers: str, verify: bool, base_url: str) -> dict: info_data = {} url = f"{base_url}/status/version" response = requests.get(url, headers=headers, verify=verify) - if (response.status_code == 200): + if response.status_code == 200: jsdata = response.text - data = json.loads(jsdata) # returns a dictionary - #pprint(data) + data = json.loads(jsdata) # returns a dictionary + # pprint(data) # get Mailcow version mc_version = data["version"] # if enabled, check this version against the official Mailcow repo on Github if opt_check_version: git_version = getGitVersion() update_available = compareVersions(mc_version, git_version) - #update_available = compareVersions("2023-01a", "2023-02") - #print(update_available) + # update_available = compareVersions("2023-01a", "2023-02") + # print(update_available) info_data["git_version"] = git_version info_data["update_available"] = update_available else: @@ -358,28 +390,13 @@ def getMailcowInfo(headers: str, verify: bool, base_url: str) -> dict: info_data["check_version_enabled"] = opt_check_version return info_data else: - sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n") - sys.exit(1) - -#@debugLog -def getSolrInfo(headers: str, verify: bool, base_url: str) -> tuple: - url = f"{base_url}/status/solr" - response = requests.get(url, headers=headers, verify=verify) - if (response.status_code == 200): - jsdata = response.text - data = json.loads(jsdata) # returns a dictionary - #pprint(data) - # get Solr infos - solr_enabled = data["solr_enabled"] - solr_size = data["solr_size"] - solr_documents = data["solr_documents"] - return solr_enabled, solr_size, solr_documents - else: - sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n") + sys.stderr.write( + f"Request response code is {response.status_code} with URL {url}\n" + ) sys.exit(1) -''' +""" Output is as follows: 0 mailbox name email address used for login 1 active 1 --> active, 0 --> not active @@ -398,9 +415,10 @@ 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 -''' +""" -#@debugLog + +# @debugLog def doCmkOutputMailboxes() -> None: print("<<>>") for mb in mailbox_data: @@ -408,7 +426,7 @@ def doCmkOutputMailboxes() -> None: created = mailbox_data[mb]["created"] modified = mailbox_data[mb]["modified"] name = mailbox_data[mb]["name"] - # strip semicolons, if present, since we use it as delimiter + # strip semicolons, if present, since we use it as delimiter name = name.replace(";", "") num_messages = mailbox_data[mb]["num_messages"] percent_in_use = mailbox_data[mb]["percent_in_use"] @@ -417,21 +435,30 @@ def doCmkOutputMailboxes() -> None: 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}") + print( + f"{mb};{active};{created};{modified};{name};{num_messages};{percent_in_use};{quota};{quota_used};{last_imap_login};{last_pop3_login};{last_smtp_login}" + ) -#@debugLog -def doCmkOutputMailcow(version: str, - num_domains: int, num_mailboxes: int, num_global_messages: int, - solr_enabled: bool, solr_size: float, solr_documents: int, - git_version: str, update_available: bool, check_version_enabled: bool - ) -> None: + +# @debugLog +def doCmkOutputMailcow( + version: str, + num_domains: int, + num_mailboxes: int, + num_global_messages: int, + git_version: str, + update_available: bool, + check_version_enabled: bool, +) -> None: print("<<>>") # strip semicolons, if present, since we use it as delimiter version = version.replace(";", "") - print(f"{version};{num_domains};{num_mailboxes};{num_global_messages};{solr_enabled};{solr_size};{solr_documents};{git_version};{update_available};{check_version_enabled}") + print( + f"{version};{num_domains};{num_mailboxes};{num_global_messages};{git_version};{update_available};{check_version_enabled}" + ) -''' +""" Output is as follows: 0 domain_name 1 active 1 --> active, 0 --> not active @@ -449,9 +476,10 @@ 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 -''' +""" -#@debugLog + +# @debugLog def doCmkOutputDomains() -> None: print("<<>>") for dom in domain_data: @@ -465,7 +493,9 @@ def doCmkOutputDomains() -> None: 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}") + 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(): @@ -473,39 +503,39 @@ def main(): cmk.utils.password_store.replace_passwords() getOptions() # do some parameter checks - if (opt_hostname == ""): + if opt_hostname == "": sys.stderr.write(f"No hostname given.\n") showUsage() sys.exit(1) else: hostname = opt_hostname - if (opt_apikey == ""): + if opt_apikey == "": sys.stderr.write(f"No API key given.\n") showUsage() sys.exit(1) - if (opt_no_cert_check): + if opt_no_cert_check: # disable certificate warnings urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) verify = False else: verify = True - if (opt_port == ""): - if (opt_no_https): + if opt_port == "": + if opt_no_https: protocol = "http" port = "80" else: protocol = "https" port = "443" else: - if (opt_no_https): + if opt_no_https: protocol = "http" else: protocol = "https" port = opt_port - if (protocol == "http" and port == "443"): + if protocol == "http" and port == "443": sys.stderr.write(f"Combining HTTP with port 443 is not supported.\n") sys.exit(1) - if (protocol == "https" and port == "80"): + if protocol == "https" and port == "80": sys.stderr.write(f"Combining HTTPS with port 80 is not supported.\n") sys.exit(1) headers = CaseInsensitiveDict() @@ -519,14 +549,15 @@ def main(): debugLogFilename = getDebugFilename(hostname) if DEBUG: showOptions() - print(f"hostname: {hostname}, protocol: {protocol}, port: {port}, verify: {verify}") + print( + f"hostname: {hostname}, protocol: {protocol}, port: {port}, verify: {verify}" + ) base_url = f"{protocol}://{hostname}:{port}/{mc_api_base}" # get domain data num_domains = getDomainInfo(headers, verify, base_url) # get mailbox data num_mailboxes, num_global_messages = getMailboxInfo(headers, verify, base_url) # get global Mailcow info - solr_enabled, solr_size, solr_documents = getSolrInfo(headers, verify, base_url) mailcow_info = getMailcowInfo(headers, verify, base_url) mailcow_version = mailcow_info["mc_version"] github_version = mailcow_info["git_version"] @@ -535,12 +566,16 @@ def main(): # create agent output doCmkOutputDomains() doCmkOutputMailboxes() - doCmkOutputMailcow(mailcow_version, - num_domains, num_mailboxes, num_global_messages, - solr_enabled, solr_size, solr_documents, - github_version, update_available, check_version_enabled + doCmkOutputMailcow( + mailcow_version, + num_domains, + num_mailboxes, + num_global_messages, + github_version, + update_available, + check_version_enabled, ) if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/local/share/check_mk/checkman/mailcow_info b/local/share/check_mk/checkman/mailcow_info index 08415b6..9b117bb 100644 --- a/local/share/check_mk/checkman/mailcow_info +++ b/local/share/check_mk/checkman/mailcow_info @@ -14,7 +14,5 @@ description: The check will raise WARN/CRIT if the number of domains is above the configurable levels. The check will raise WARN/CRIT if the number of mailboxes is above the configurable levels. The check will raise WARN/CRIT if the number of messages is above the configurable levels. - The check will raise WARN/CRIT if the solr size is above the configurable levels. - The check will raise WARN/CRIT if the number of solr documents is above the configurable levels. inventory: one service is created (with several details) \ No newline at end of file diff --git a/local/share/check_mk/checks/agent_mailcow b/local/share/check_mk/checks/agent_mailcow index da216ae..c6607f8 100644 --- a/local/share/check_mk/checks/agent_mailcow +++ b/local/share/check_mk/checks/agent_mailcow @@ -1,12 +1,19 @@ def agent_mailcow_arguments(params, hostname, ipaddress): - return [ - "--hostname", params["hostname"], - "--apikey", passwordstore_get_cmdline("%s", params["apikey"]), - "--port", params["port"], - "--check-version", params["check_version"], - "--no-https", params["no_https"], - "--no-cert-check", params["no_cert_check"], - ipaddress, - ] + return [ + "--hostname", + params["hostname"], + "--apikey", + passwordstore_get_cmdline("%s", params["apikey"]), + "--port", + params["port"], + "--check-version", + params["check_version"], + "--no-https", + params["no_https"], + "--no-cert-check", + params["no_cert_check"], + ipaddress, + ] -special_agent_info['mailcow'] = agent_mailcow_arguments + +special_agent_info["mailcow"] = agent_mailcow_arguments diff --git a/local/share/check_mk/web/plugins/metrics/mailcow_metrics.py b/local/share/check_mk/web/plugins/metrics/mailcow_metrics.py index f96d6ee..a9a4e00 100644 --- a/local/share/check_mk/web/plugins/metrics/mailcow_metrics.py +++ b/local/share/check_mk/web/plugins/metrics/mailcow_metrics.py @@ -70,15 +70,3 @@ metric_info["mailcow_mailboxes_messages"] = { "unit": "count", "color": "24/b", } - -metric_info["mc_solr_size"] = { - "title": _("Solr Size"), - "unit": "bytes", - "color": "24/b", -} - -metric_info["mc_solr_documents"] = { - "title": _("Number of Solr Documents"), - "unit": "count", - "color": "24/a", -} \ No newline at end of file diff --git a/local/share/check_mk/web/plugins/perfometer/mailcow_perfometers.py b/local/share/check_mk/web/plugins/perfometer/mailcow_perfometers.py index b7bfea5..dc71130 100644 --- a/local/share/check_mk/web/plugins/perfometer/mailcow_perfometers.py +++ b/local/share/check_mk/web/plugins/perfometer/mailcow_perfometers.py @@ -1,54 +1,44 @@ #!/usr/bin/env python3 from cmk.gui.plugins.metrics import perfometer_info -perfometer_info.append({ - "type": "stacked", - "perfometers": [ - { - "type": "linear", - "segments": ["mc_num_domains","mc_num_mailboxes","mc_num_global_messages"], - }, - ], -}) +perfometer_info.append( + { + "type": "stacked", + "perfometers": [ + { + "type": "linear", + "segments": [ + "mc_num_domains", + "mc_num_mailboxes", + "mc_num_global_messages", + ], + }, + ], + } +) -perfometer_info.append({ - "type": "stacked", - "perfometers": [ - { - "type": "linear", - "segments": ["mailcow_domains_used_quota"], - "total": 100.0, - }, - ], -}) +perfometer_info.append( + { + "type": "stacked", + "perfometers": [ + { + "type": "linear", + "segments": ["mailcow_domains_used_quota"], + "total": 100.0, + }, + ], + } +) -perfometer_info.append({ - "type": "stacked", - "perfometers": [ - { - "type": "linear", - "segments": ["mailcow_mailboxes_used_quota"], - "total": 100.0, - }, - ], -}) - -#perfometer_info.append({ -# "type": "stacked", -# "perfometers": [ -# { -# "type": "linear", -# "segments": ["mc_num_mailboxes"], -# }, -# ], -#}) - -#perfometer_info.append({ -# "type": "stacked", -# "perfometers": [ -# { -# "type": "linear", -# "segments": ["mc_num_global_messages"], -# }, -# ], -#}) +perfometer_info.append( + { + "type": "stacked", + "perfometers": [ + { + "type": "linear", + "segments": ["mailcow_mailboxes_used_quota"], + "total": 100.0, + }, + ], + } +) diff --git a/local/share/check_mk/web/plugins/wato/mailcow_info_rules.py b/local/share/check_mk/web/plugins/wato/mailcow_info_rules.py index cb1fb52..058877b 100644 --- a/local/share/check_mk/web/plugins/wato/mailcow_info_rules.py +++ b/local/share/check_mk/web/plugins/wato/mailcow_info_rules.py @@ -2,7 +2,7 @@ from cmk.gui.i18n import _ from cmk.gui.plugins.wato import ( CheckParameterRulespecWithoutItem, rulespec_registry, - RulespecGroupCheckParametersApplications + RulespecGroupCheckParametersApplications, ) from cmk.gui.valuespec import ( @@ -14,11 +14,14 @@ from cmk.gui.valuespec import ( Float, ) + def _parameter_spec_mailcow_info(): return Dictionary( elements=[ - ("levels_num_domains", Tuple( - title=_("Number of email domains"), + ( + "levels_num_domains", + Tuple( + title=_("Number of email domains"), elements=[ Integer( title=_("Warning at"), @@ -29,11 +32,14 @@ def _parameter_spec_mailcow_info(): title=_("Critical at"), size=32, default_value=200, - ) + ), ], - )), - ("levels_num_mailboxes", Tuple( - title=_("Number of mailboxes"), + ), + ), + ( + "levels_num_mailboxes", + Tuple( + title=_("Number of mailboxes"), elements=[ Integer( title=_("Warning at"), @@ -44,11 +50,14 @@ def _parameter_spec_mailcow_info(): title=_("Critical at"), size=32, default_value=1000, - ) + ), ], - )), - ("levels_num_global_messages", Tuple( - title=_("Number of messages"), + ), + ), + ( + "levels_num_global_messages", + Tuple( + title=_("Number of messages"), elements=[ Integer( title=_("Warning at"), @@ -59,44 +68,14 @@ def _parameter_spec_mailcow_info(): title=_("Critical at"), size=32, default_value=250000, - ) - ], - )), - ("levels_solr_size", Tuple( - title=_("Solr size"), - elements=[ - Float( - title=_("Warning at"), - size=32, - default_value=4096.0, - unit="MBytes", ), - Float( - title=_("Critical at"), - size=32, - default_value=8192.0, - unit="MBytes", - ) ], - )), - ("levels_solr_documents", Tuple( - title=_("Number of Solr documents"), - elements=[ - Integer( - title=_("Warning at"), - size=32, - default_value=20000, - ), - Integer( - title=_("Critical at"), - size=32, - default_value=40000, - ) - ], - )), + ), + ), ], ) + rulespec_registry.register( CheckParameterRulespecWithoutItem( check_group_name="mailcow_info", @@ -105,4 +84,4 @@ rulespec_registry.register( parameter_valuespec=_parameter_spec_mailcow_info, title=lambda: _("Levels for Mailcow info"), ) -) \ No newline at end of file +) diff --git a/local/share/check_mk/web/plugins/wato/mailcow_params.py b/local/share/check_mk/web/plugins/wato/mailcow_params.py index 6e7052c..c9dfc76 100644 --- a/local/share/check_mk/web/plugins/wato/mailcow_params.py +++ b/local/share/check_mk/web/plugins/wato/mailcow_params.py @@ -27,36 +27,72 @@ from cmk.gui.valuespec import ( Integer, ) + def _valuespec_special_agent_mailcow(): return Dictionary( title=_("Mailcow Server Information"), - help = _("Checking Mailcow instances via API"), + help=_("Checking Mailcow instances via API"), elements=[ - ("hostname", TextAscii(title=_("Hostname"), - size=32, - allow_empty=False, - help=_("Hostname of Mailcow server (bare FQDN or IP), mandatory"))), - ("apikey", IndividualOrStoredPassword(title=_("API Key"), - size=32, - allow_empty=False, - help=_("API Key, mandatory"))), - ("port", TextAscii(title=_("Port"), - allow_empty=True, - help=_("Specify port if not listening to HTTPS/HTTP, optional"))), - ("check_version", Checkbox(title=_("Check version"), - help=_("Checks the running version against the public Github repo"))), - ("no_https", Checkbox(title=_("Disable HTTPS"), - help=_("Activate to disable TLS encryption (not recommended), optional"))), - ("no_cert_check", Checkbox(title=_("Disable certificate validation"), - help=_("Activate to disable certificate validation (not recommended), optional"))), + ( + "hostname", + TextAscii( + title=_("Hostname"), + size=32, + allow_empty=False, + help=_("Hostname of Mailcow server (bare FQDN or IP), mandatory"), + ), + ), + ( + "apikey", + IndividualOrStoredPassword( + title=_("API Key"), + size=32, + allow_empty=False, + help=_("API Key, mandatory"), + ), + ), + ( + "port", + TextAscii( + title=_("Port"), + allow_empty=True, + help=_("Specify port if not listening to HTTPS/HTTP, optional"), + ), + ), + ( + "check_version", + Checkbox( + title=_("Check version"), + help=_("Checks the running version against the public Github repo"), + ), + ), + ( + "no_https", + Checkbox( + title=_("Disable HTTPS"), + help=_( + "Activate to disable TLS encryption (not recommended), optional" + ), + ), + ), + ( + "no_cert_check", + Checkbox( + title=_("Disable certificate validation"), + help=_( + "Activate to disable certificate validation (not recommended), optional" + ), + ), + ), ], optional_keys=[], ) + rulespec_registry.register( HostRulespec( group=RulespecGroupDatasourceProgramsApps, name="special_agents:mailcow", valuespec=_valuespec_special_agent_mailcow, ) -) \ No newline at end of file +) diff --git a/mkp/Mailcow-1.3.0.mkp b/mkp/Mailcow-1.3.0.mkp new file mode 100644 index 0000000..47ac9a9 Binary files /dev/null and b/mkp/Mailcow-1.3.0.mkp differ