From 276e67d4732b99aef95ebc00ae3a1be8b93f1e4a Mon Sep 17 00:00:00 2001 From: mellis Date: Fri, 26 Jan 2024 11:39:01 +0100 Subject: [PATCH] added password store option for api-key --- .../check_mk/agents/special/agent_mailcow | 2 ++ local/share/check_mk/checks/agent_mailcow | 2 +- .../web/plugins/wato/mailcow_params.py | 25 +++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/local/share/check_mk/agents/special/agent_mailcow b/local/share/check_mk/agents/special/agent_mailcow index d4d36c8..c2718cc 100755 --- a/local/share/check_mk/agents/special/agent_mailcow +++ b/local/share/check_mk/agents/special/agent_mailcow @@ -6,6 +6,7 @@ import requests import urllib3 import json import os +import cmk.utils.password_store from pprint import pprint from requests.structures import CaseInsensitiveDict from requests.auth import HTTPBasicAuth @@ -391,6 +392,7 @@ def doCmkOutputDomains() -> None: def main(): global debugLogFilename + cmk.utils.password_store.replace_passwords() getOptions() # do some parameter checks if (opt_hostname == ""): diff --git a/local/share/check_mk/checks/agent_mailcow b/local/share/check_mk/checks/agent_mailcow index a82d5da..6218ba8 100644 --- a/local/share/check_mk/checks/agent_mailcow +++ b/local/share/check_mk/checks/agent_mailcow @@ -1,7 +1,7 @@ def agent_mailcow_arguments(params, hostname, ipaddress): return [ "--hostname", params["hostname"], - "--apikey", params["apikey"], + "--apikey", passwordstore_get_cmdline("%s", params["apikey"]), "--port", params["port"], "--no-https", params["no_https"], "--no-cert-check", params["no_cert_check"], 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 ad18a07..47856e6 100644 --- a/local/share/check_mk/web/plugins/wato/mailcow_params.py +++ b/local/share/check_mk/web/plugins/wato/mailcow_params.py @@ -1,8 +1,4 @@ from cmk.gui.i18n import _ -from cmk.gui.plugins.wato import ( - CheckParameterRulespecWithItem, - rulespec_registry, -) from cmk.gui.plugins.wato.special_agents.common import ( RulespecGroupDatasourceProgramsApps, @@ -12,29 +8,36 @@ from cmk.gui.plugins.wato.special_agents.common import ( RulespecGroupDatasourceProgramsTesting, ) +from cmk.gui.plugins.wato.utils import ( + IndividualOrStoredPassword, + rulespec_registry, + CheckParameterRulespecWithItem, + CheckParameterRulespecWithoutItem, + HostRulespec, + Rulespec, +) + from cmk.gui.valuespec import ( Dictionary, ListChoice, Checkbox, TextAscii, Password, + NetworkPort, + Integer, ) -from cmk.gui.plugins.wato import ( - HostRulespec, -) - -from cmk.gui.plugins.wato.datasource_programs import RulespecGroupDatasourceProgramsCustom - def _valuespec_special_agent_mailcow(): return Dictionary( title=_("Mailcow Server Information"), 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", TextAscii(title=_("API Key"), + ("apikey", IndividualOrStoredPassword(title=_("API Key"), + size=32, allow_empty=False, help=_("API Key, mandatory"))), ("port", TextAscii(title=_("Port"),