From fd25053ac17b10c8674760b88bbef1a2843f4748 Mon Sep 17 00:00:00 2001 From: Robert Sander Date: Fri, 22 Nov 2024 15:14:59 +0100 Subject: [PATCH] adds imap MKP for CMK 2.3 --- imap/imap-4.0.1.mkp | Bin 0 -> 3631 bytes imap/rulesets/imap.py | 48 +++++++++++++++++++-------------- imap/server_side_calls/imap.py | 47 ++++---------------------------- 3 files changed, 33 insertions(+), 62 deletions(-) create mode 100644 imap/imap-4.0.1.mkp diff --git a/imap/imap-4.0.1.mkp b/imap/imap-4.0.1.mkp new file mode 100644 index 0000000000000000000000000000000000000000..4db22f4e1d94fbb36caf75ebe674c83e7c1f3804 GIT binary patch literal 3631 zcmbWw=OYx3!vJtuA>*v$WMq@G_edlw<7A(`Dx*6ia!#_ciF04qg-CW*$R0;Vc1A|B zvd)=_>kxOp=Wlr4ecpY9(io^@QF>3PDF-(Lp8ZstE+ooWH48itNWp-e;ooiWws*ZO zuK3JMM>M9ft-DGHq~Jj>9RPj z@-QjJp31Hkv7bBpD3FOH#jq$g@^?p$M18KCtXFn*nB+sN$Hs8pj@Zmoq4xM29LV9C zJ@i8Wd!+e+_RKrSUw5Nog>=r`JTxD3M3^YN-pFcdX$f3L zoG5Yk+EwOFfqi8!{mGd&pt5Lmm`@raO3{?Lhu!=n`}LZ+4MY6+yp|W-n9*Yj8>}Uo zFG4`yG67{A`uQl$7nQ*x+ziOzPb=P@)u-+1vc0%)%x%Qo*jqj8 zr>5Xq$<8$wOBbtws(JobxRHzb);xb0tkjDF=WQ#Rp&tCghxg|sLQb!tQ zDX>W9nRBJX-%Dn1DfFmYP19BX$;aGe&lqw(AW=D+n!}1>dd$Fk;#<;$^H1wF32+ZE z^JdSgVN+Qg-`FUGQ4G(SUD)bc$)q#V*hS#J3W@LkW_mEOKaic0&~@|Q7dAe?FPnb` zGj1|X(NVY`w4FwcvxwO<$PmWhC_Fddcfl?t?F(rYCJ9~?Y$vM`k4!ZZ^mf(FR?&+P z)q7FeK`xYLi)@7Lzj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ibn>2kX@4KDAlaeYD=nYdp%;`Q*`)IrEb`DbBsA>7P9m}j%Nt+BRyAu{safVYw9RC#pLJi!ZV zQ%w&>)=TLIJ07S;JzT33GNv5frjf|Zyc2juy;V+Cf7c4(mu3EImlkd^dPL{#oCwfX_0wk zQu@4>&mgsHc3^vpj*S`HUYYDPy}cakRCU+suMZ16^{3SLu?C-?{7Ly?5vizXS|i-R z_?s&QCCnEQ-Rux%4c+8Xee0AeSSc6gy#`WvjP=71qY2r^KAoUJrSoiy(ATeV_QP&# z)!T~yShH}cr#3Ilf7T0^&MB+7hRmj)pdo*&lX1|_xd2IIn4GhWd`M;4$GWA>@AQ<_ z!hEIt^qwt;O)tWX$S-KxV_ErG`wOlL(H8C>_Pfs{hO(05L?58%Gd4erXHTPoTL0MC y-9n8#2Tm`J{ThF`o<{xm4_z$d5r&$MiA&1ry 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 diff --git a/imap/server_side_calls/imap.py b/imap/server_side_calls/imap.py index 4012a728..d6b8f5a3 100644 --- a/imap/server_side_calls/imap.py +++ b/imap/server_side_calls/imap.py @@ -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 @@ -31,9 +31,6 @@ replace_macros, ) -from cmk.utils import debug -from pprint import pprint - class LevelsType(StrEnum): NO_LEVELS = "no_levels" FIXED = "fixed" @@ -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( @@ -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, @@ -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, -# }