Checks for Solr status added
This commit is contained in:
parent
68188b0940
commit
199f8830da
@ -28,22 +28,38 @@ def discover_mailcow_info(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 KBytes, so convert it to bytes
|
||||
levels_solr_size_warn = levels_solr_size_kb[0] * 1024
|
||||
levels_solr_size_crit = levels_solr_size_kb[1] * 1024
|
||||
levels_solr_size = (levels_solr_size_warn, levels_solr_size_crit)
|
||||
levels_solr_documents = params["levels_solr_documents"]
|
||||
|
||||
version = section[key]["version"]
|
||||
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))
|
||||
yield(Metric("mc_num_mailboxes", num_mailboxes))
|
||||
yield(Metric("mc_num_global_messages", num_global_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))
|
||||
|
||||
# create overall result
|
||||
summary = f"Version is {version}"
|
||||
details = f"Mailcow version: {version}\nNumber of domains: {num_domains}\nNumber of mailboxes: {num_mailboxes}\nNumber of messages: {num_global_messages}\n"
|
||||
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}"
|
||||
yield Result(state=State.OK, summary=summary, details=details)
|
||||
|
||||
# Create result for number of domains
|
||||
@ -66,7 +82,27 @@ def check_mailcow_info(params, section):
|
||||
notice = f"Number of messages: {num_global_messages}"
|
||||
if state != State.OK:
|
||||
yield(Result(state=state, notice=notice))
|
||||
|
||||
|
||||
# Create result for solr size and solr number of documents
|
||||
if solr_enabled:
|
||||
warn, crit = levels_solr_size
|
||||
# levels are given in KB, so convert the size given Bytes
|
||||
solr_size = solr_size / 1024
|
||||
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):
|
||||
parsed_data = {
|
||||
@ -78,10 +114,26 @@ 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])
|
||||
parsed_data["mailcow"]["version"] = version
|
||||
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
|
||||
return parsed_data
|
||||
|
||||
|
||||
@ -100,6 +152,8 @@ 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": (2000, 4000)
|
||||
},
|
||||
check_ruleset_name="mailcow_info",
|
||||
)
|
@ -217,6 +217,23 @@ def getMailcowInfo(headers, verify, base_url):
|
||||
sys.stderr.write(f"Request response code is {response.status_code} with URL {url}\n")
|
||||
sys.exit(1)
|
||||
|
||||
def getSolrInfo(headers, verify, base_url):
|
||||
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.exit(1)
|
||||
|
||||
|
||||
'''
|
||||
Output is as follows:
|
||||
0 mailbox name email address used for login
|
||||
@ -257,11 +274,11 @@ def doCmkOutputMailboxes():
|
||||
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):
|
||||
def doCmkOutputMailcow(version, num_domains, num_mailboxes, num_global_messages, solr_enabled, solr_size, solr_documents):
|
||||
print("<<<mailcow_info:sep(59)>>>")
|
||||
# strip semicolons, if present, since we use it as delimiter
|
||||
version = version.replace(";", "")
|
||||
print(f"{version};{num_domains};{num_mailboxes};{num_global_messages}")
|
||||
print(f"{version};{num_domains};{num_mailboxes};{num_global_messages};{solr_enabled};{solr_size};{solr_documents}")
|
||||
|
||||
|
||||
'''
|
||||
@ -355,11 +372,12 @@ def main():
|
||||
# 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_version = getMailcowInfo(headers, verify, base_url)
|
||||
# create agent output
|
||||
doCmkOutputDomains()
|
||||
doCmkOutputMailboxes()
|
||||
doCmkOutputMailcow(mailcow_version, num_domains, num_mailboxes, num_global_messages)
|
||||
doCmkOutputMailcow(mailcow_version, num_domains, num_mailboxes, num_global_messages, solr_enabled, solr_size, solr_documents)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -12,6 +12,8 @@ description:
|
||||
Shows several information about a Mailcow instance, e.g. number of domains/mailboxes/messages.
|
||||
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 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)
|
@ -69,4 +69,16 @@ metric_info["mailcow_mailboxes_messages"] = {
|
||||
"title": _("Number of 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",
|
||||
}
|
@ -56,6 +56,34 @@ def _parameter_spec_mailcow_info():
|
||||
)
|
||||
],
|
||||
)),
|
||||
("levels_solr_size", Tuple(
|
||||
title=_("Solr size"),
|
||||
elements=[
|
||||
Float(
|
||||
title=_("Warning at"),
|
||||
default_value=4096.0,
|
||||
unit="KBytes",
|
||||
),
|
||||
Float(
|
||||
title=_("Critical at"),
|
||||
default_value=8192.0,
|
||||
unit="KBytes",
|
||||
)
|
||||
],
|
||||
)),
|
||||
("levels_solr_documents", Tuple(
|
||||
title=_("Number of Solr documents"),
|
||||
elements=[
|
||||
Integer(
|
||||
title=_("Warning at"),
|
||||
default_value=2000,
|
||||
),
|
||||
Integer(
|
||||
title=_("Critical at"),
|
||||
default_value=4000,
|
||||
)
|
||||
],
|
||||
)),
|
||||
],
|
||||
)
|
||||
|
||||
@ -65,6 +93,6 @@ rulespec_registry.register(
|
||||
group=RulespecGroupCheckParametersApplications,
|
||||
match_type="dict",
|
||||
parameter_valuespec=_parameter_spec_mailcow_info,
|
||||
title=lambda: _("Mailcow Info"),
|
||||
title=lambda: _("Levels for Mailcow info"),
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user