MKP 0.1.0 2nd try
This commit is contained in:
parent
0d241f6521
commit
c0cb43d894
105
local/lib/python3/cmk/base/plugins/agent_based/mailcow_info.py
Normal file
105
local/lib/python3/cmk/base/plugins/agent_based/mailcow_info.py
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from pprint import pprint
|
||||||
|
from .agent_based_api.v1 import register, render, Service, Result, State, Metric
|
||||||
|
|
||||||
|
|
||||||
|
def getStateUpper(levels, value):
|
||||||
|
warn, crit = levels
|
||||||
|
if value >= crit:
|
||||||
|
return State.CRIT
|
||||||
|
if value >= warn:
|
||||||
|
return State.WARN
|
||||||
|
return State.OK
|
||||||
|
|
||||||
|
|
||||||
|
def getStateLower(levels, value):
|
||||||
|
warn, crit = levels
|
||||||
|
if value < crit:
|
||||||
|
return State.CRIT
|
||||||
|
if value < warn:
|
||||||
|
return State.WARN
|
||||||
|
return State.OK
|
||||||
|
|
||||||
|
|
||||||
|
def discover_mailcow_info(section):
|
||||||
|
yield(Service())
|
||||||
|
|
||||||
|
|
||||||
|
def check_mailcow_info(params, section):
|
||||||
|
for key in section:
|
||||||
|
if key == "mailcow":
|
||||||
|
levels_num_domains = params["levels_num_domains"]
|
||||||
|
levels_num_mailboxes = params["levels_num_mailboxes"]
|
||||||
|
levels_num_global_messages = params["levels_num_global_messages"]
|
||||||
|
version = section[key]["version"]
|
||||||
|
num_domains = section[key]["num_domains"]
|
||||||
|
num_mailboxes = section[key]["num_mailboxes"]
|
||||||
|
num_global_messages = section[key]["num_global_messages"]
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
yield Result(state=State.OK, summary=summary, details=details)
|
||||||
|
|
||||||
|
# Create result for number of domains
|
||||||
|
warn, crit = levels_num_domains
|
||||||
|
state = getStateUpper((warn, crit), num_domains)
|
||||||
|
notice = f"Number of domains: {num_domains}"
|
||||||
|
if state != State.OK:
|
||||||
|
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))
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
|
||||||
|
def parse_mailcow_info_section(string_table):
|
||||||
|
parsed_data = {
|
||||||
|
"mailcow" : {},
|
||||||
|
}
|
||||||
|
# we expect only one line
|
||||||
|
line = string_table[0]
|
||||||
|
version = line[0]
|
||||||
|
num_domains = int(line[1])
|
||||||
|
num_mailboxes = int(line[2])
|
||||||
|
num_global_messages = int(line[3])
|
||||||
|
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
|
||||||
|
return parsed_data
|
||||||
|
|
||||||
|
|
||||||
|
register.agent_section(
|
||||||
|
name="mailcow_info",
|
||||||
|
parse_function=parse_mailcow_info_section,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
register.check_plugin(
|
||||||
|
name="mailcow_info",
|
||||||
|
service_name="Mailcow Info",
|
||||||
|
discovery_function=discover_mailcow_info,
|
||||||
|
check_function=check_mailcow_info,
|
||||||
|
check_default_parameters={
|
||||||
|
"levels_num_domains": (100, 200),
|
||||||
|
"levels_num_mailboxes": (500, 1000),
|
||||||
|
"levels_num_global_messages": (100000, 250000),
|
||||||
|
},
|
||||||
|
check_ruleset_name="mailcow_info",
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user