Module: check_mk
Branch: master
Commit: 8ad10f120261487d922998ed9e6b632a8e1c1d41
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8ad10f12026148…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 19 20:42:19 2018 +0200
agent_3par: Now able to use passwords from the password store
Change-Id: Icb49efe26f7ffcd0f8d3f18ec6410a08215010d8
---
agents/special/agent_3par | 4 ++++
checks/agent_3par | 12 +++++-----
cmk/gui/plugins/wato/active_checks.py | 2 +-
cmk/gui/plugins/wato/datasource_programs.py | 5 +++--
tests/testlib/__init__.py | 13 +++++++++++
tests/unit/checks/test_agent_3par.py | 35 +++++++++++++++++++++++++++++
6 files changed, 62 insertions(+), 9 deletions(-)
diff --git a/agents/special/agent_3par b/agents/special/agent_3par
index 3cf8ccb..c8eb568 100755
--- a/agents/special/agent_3par
+++ b/agents/special/agent_3par
@@ -31,6 +31,10 @@ import sys
import requests
import urllib3
+import cmk.password_store
+
+cmk.password_store.replace_passwords()
+
# .--Arguments-----------------------------------------------------------.
# | _ _ |
diff --git a/checks/agent_3par b/checks/agent_3par
index cb74add..5469c8d 100644
--- a/checks/agent_3par
+++ b/checks/agent_3par
@@ -25,16 +25,16 @@
# Boston, MA 02110-1301 USA.
def agent_3par_arguments(params, hostname, ipaddress):
- args = ''
+ args = []
- args += " -u " + quote_shell_string(params["user"])
- args += " -p " + quote_shell_string(params["password"])
- args += " --verify-certs=%s" % ("yes" if
params.get("verify_cert", False) else "no")
+ args += [ "-u", params["user"] ]
+ args += [ passwordstore_get_cmdline("-p%s", params["password"])
]
+ args += [ "--verify-certs=%s" % ("yes" if
params.get("verify_cert", False) else "no") ]
if "values" in params:
- args += " -v " +
quote_shell_string(",".join(params["values"]))
+ args += [ "-v", ",".join(params["values"]) ]
- args += " " + quote_shell_string(ipaddress)
+ args.append(ipaddress)
return args
diff --git a/cmk/gui/plugins/wato/active_checks.py
b/cmk/gui/plugins/wato/active_checks.py
index 4669e43..05a32fe 100644
--- a/cmk/gui/plugins/wato/active_checks.py
+++ b/cmk/gui/plugins/wato/active_checks.py
@@ -29,7 +29,7 @@ from cmk.gui.i18n import _
# TODO: Clean this * import up!
from cmk.gui.valuespec import *
-from . import (
+from cmk.gui.plugins.wato import (
register_rulegroup,
register_rule,
PluginCommandLine,
diff --git a/cmk/gui/plugins/wato/datasource_programs.py
b/cmk/gui/plugins/wato/datasource_programs.py
index 3c109b4..66ad3a1 100644
--- a/cmk/gui/plugins/wato/datasource_programs.py
+++ b/cmk/gui/plugins/wato/datasource_programs.py
@@ -28,10 +28,11 @@ import cmk.gui.watolib as watolib
from cmk.gui.i18n import _
from cmk.gui.valuespec import *
-from . import (
+from cmk.gui.plugins.wato import (
register_rulegroup,
register_rule,
monitoring_macro_help,
+ IndividualOrStoredPassword,
)
register_rulegroup("datasource_programs",
@@ -1166,7 +1167,7 @@ register_rule("datasource_programs",
("user", TextAscii(title = _("Username"),
allow_empty = False,
)),
- ("password", Password(title = _("Password"),
+ ("password", IndividualOrStoredPassword(title =
_("Password"),
allow_empty = False,
)),
("verify_cert", DropdownChoice(
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index c5adeca..2e33ff1 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -1815,6 +1815,10 @@ class CheckManager(object):
self.load([name])
return ActiveCheck(name)
+ def get_special_agent(self, name):
+ self.load([name])
+ return SpecialAgent(name)
+
class MissingCheckInfoError(KeyError):
pass
@@ -1918,3 +1922,12 @@ class ActiveCheck(BaseCheck):
def run_service_description(self, params):
return self.info['service_description'](params)
+
+
+class SpecialAgent(object):
+ def __init__(self, name):
+ import cmk_base.config as config
+ super(SpecialAgent, self).__init__()
+ self.name = name
+ assert self.name.startswith('agent_'), 'Specify the full name of the
active check, e.g. agent_3par'
+ self.argument_func =
config.special_agent_info[self.name[len('agent_'):]]
diff --git a/tests/unit/checks/test_agent_3par.py b/tests/unit/checks/test_agent_3par.py
new file mode 100644
index 0000000..739e323
--- /dev/null
+++ b/tests/unit/checks/test_agent_3par.py
@@ -0,0 +1,35 @@
+import pytest
+
+(a)pytest.mark.parametrize("params,result"sult", [
+ ({
+ "user": "user",
+ "password": "d1ng",
+ "verify_cert": False,
+ "values": ["x","y"],
+ }, ['-u', 'user', '-pd1ng', '--verify-certs=no',
'-v', 'x,y', "address"]),
+ ({
+ "user": "user",
+ "password": "d1ng",
+ "values": ["x","y"],
+ }, ['-u', 'user', '-pd1ng', '--verify-certs=no',
'-v', 'x,y', "address"]),
+ ({
+ "user": "user",
+ "password": "d1ng",
+ "verify_cert": True,
+ "values": ["x","y"],
+ }, ['-u', 'user', '-pd1ng', '--verify-certs=yes',
'-v', 'x,y', "address"]),
+ ({
+ "user": "user",
+ "password": "d1ng",
+ "verify_cert": True,
+ }, ['-u', 'user', '-pd1ng', '--verify-certs=yes',
"address"]),
+ ({
+ "user": "user",
+ "password": ("store", "pw-id"),
+ "verify_cert": True,
+ }, ['-u', 'user', ('store', 'pw-id', '-p%s'),
'--verify-certs=yes', "address"]),
+])
+def test_3par(check_manager, params, result):
+ agent = check_manager.get_special_agent("agent_3par")
+ arguments = agent.argument_func(params, "host", "address")
+ assert arguments == result