Skip to content

Commit

Permalink
adds imap MKP for CMK 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Nov 22, 2024
1 parent b984c2d commit fd25053
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 62 deletions.
Binary file added imap/imap-4.0.1.mkp
Binary file not shown.
48 changes: 28 additions & 20 deletions imap/rulesets/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

from collections.abc import Mapping
from collections.abc import Mapping # type: ignore
from cmk.rulesets.v1 import Help, Label, Title
from cmk.rulesets.v1.form_specs import (
DefaultValue,
Expand All @@ -37,8 +37,9 @@
)
from cmk.rulesets.v1.rule_specs import ActiveCheck, Topic

import logging
logger = logging.getLogger(__name__)
# from pprint import pformat # type: ignore
# import logging
# logger = logging.getLogger(__name__)

_DAY = 24.0 * 3600.0

Expand All @@ -49,40 +50,47 @@ def _migrate_imap(raw_value: object) -> Mapping[str, object]:
'crit': 2,
'unknown': 3,
}

logger.warning("raw_value: %s" % (raw_value))
# logger.warning("INVOKE _migrate_imap")
# logger.warning("raw_value: %s" % pformat(raw_value))

if not isinstance(raw_value, tuple):
logger.warning("raw_value is not a tuple.")
# logger.warning("raw_value is not a tuple.")
return raw_value

new_value = {
"service_desc": raw_value[0],
}
logger.warning("new_value: %s" % new_value)
settings = raw_value[1]
logger.warning("settings: %s" % settings)
new_value["settings"] = settings.copy()
logger.warning("new_value: %s" % new_value)
if "hostname" in settings:
new_value["hostname"] = settings["hostname"]
del(new_value["settings"]["hostname"])
logger.warning("new_value: %s" % new_value)
else:
new_value["hostname"] = "$HOSTADDRESS$"
if "refuse" in settings:
new_value["settings"]["refuse"] = state_value.get(settings["refuse"])
logger.warning("new_value: %s" % new_value)
if "mismatch" in settings:
new_value["settings"]["mismatch"] = state_value.get(settings["mismatch"])
logger.warning("new_value: %s" % new_value)
if "certificate_age" in settings:
new_value["settings"]["certificate_age"] = ('fixed', (settings["certificate_age"][0] * 86400.0, settings["certificate_age"][1] * 86400.0))
logger.warning("new_value: %s" % new_value)
if "warning" in settings or "critical" in settings:
new_value["settings"]["response_time"] = ("fixed", (settings.get("warning"), settings.get("critical")))
logger.warning("new_value: %s" % new_value)
del(new_value["settings"]["warning"])
del(new_value["settings"]["critical"])
logger.warning("new_value: %s" % new_value)
new_value["settings"]["certificate_age"] = ('fixed', (settings["certificate_age"][0] * _DAY, settings["certificate_age"][1] * _DAY))
warning = None
critical = None
if "warning" in settings:
warning = float(settings["warning"])
del(new_value["settings"]["warning"])
if "critical" in settings:
critical = float(settings["critical"])
del(new_value["settings"]["critical"])

if warning or critical:
if not warning:
warning = critical
if not critical:
critical = 9999.999

new_value["settings"]["response_time"] = ("fixed", (warning, critical))

# logger.warning("new_value: %s" % pformat(new_value))

return new_value

Expand Down
47 changes: 5 additions & 42 deletions imap/server_side_calls/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

from collections.abc import Iterator, Mapping, Sequence
from enum import StrEnum
from collections.abc import Iterator, Mapping, Sequence # type: ignore
from enum import StrEnum # type: ignore

from pydantic import BaseModel

Expand All @@ -31,9 +31,6 @@
replace_macros,
)

from cmk.utils import debug
from pprint import pprint

class LevelsType(StrEnum):
NO_LEVELS = "no_levels"
FIXED = "fixed"
Expand Down Expand Up @@ -112,17 +109,9 @@ def convert_options(options) -> Iterator[str | Secret]:
yield "-c"
yield str(crit)

if 'warning' in options:
yield '-w'
yield options['warning']

if 'critical' in options:
yield '-c'
yield options['critical']

if 'timeout' in options:
yield '-t'
yield options['timeout']
yield str(options['timeout'])


def generate_imap_commands(
Expand All @@ -135,12 +124,10 @@ def generate_imap_commands(
service_desc = params["service_desc"]
else:
service_desc = "IMAP %s" % params["service_desc"]
if "hostname" not in params or not params['hostname']:
params["hostname"] = "$HOSTADDRESS$"
args = ['-H', replace_macros(params["hostname"], macros)]
args.extend(list(convert_options(options)))
if debug.enabled():
pprint(params)
pprint(host_config)
pprint(args)
yield ActiveCheckCommand(
service_description=service_desc,
command_arguments=args,
Expand All @@ -151,27 +138,3 @@ def generate_imap_commands(
parameter_parser=noop_parser,
commands_function=generate_imap_commands,
)

# def check_imap_arguments(params):
# args = ""

# service_desc, options = params

# if 'hostname' in options:
# args += " -H %s" % quote_shell_string(options['hostname'])
# else:
# args += " -H $HOSTADDRESS$"

#

# return args

# def check_imap_description(params):
# return params[0]

# active_check_info['imap'] = {
# "command_line": "$USER1$/check_imap $ARG1$",
# "argument_function": check_imap_arguments,
# "service_description": check_imap_description,
# "has_perfdata": True,
# }

0 comments on commit fd25053

Please sign in to comment.