forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate agent_elasticsearch to new ssc API
Change-Id: I3b648b56aa8ac14c6250430fcb0306a620e4f9d2
- Loading branch information
Showing
4 changed files
with
103 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2 | ||
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and | ||
# conditions defined in the file COPYING, which is part of this source code package. | ||
|
||
# { | ||
# 'port': 443, | ||
# 'password': 'baem', | ||
# 'infos': ['cluster_health', 'nodestats', 'stats'], | ||
# 'user': 'blub' | ||
# } | ||
|
||
|
||
from collections.abc import Iterable, Mapping | ||
|
||
from cmk.server_side_calls.v1 import ( | ||
get_secret_from_params, | ||
HostConfig, | ||
HTTPProxy, | ||
noop_parser, | ||
Secret, | ||
SpecialAgentCommand, | ||
SpecialAgentConfig, | ||
) | ||
|
||
|
||
def _agent_elasticsearch_arguments( | ||
params: Mapping[str, object], hostconfig: HostConfig, proxy_config: Mapping[str, HTTPProxy] | ||
) -> Iterable[SpecialAgentCommand]: | ||
args: list[str | Secret] = [ | ||
"-P", | ||
str(params["protocol"]), | ||
"-m", | ||
*(str(i) for i in params["infos"]), # type: ignore[attr-defined] | ||
] | ||
|
||
if "user" in params: | ||
args.extend(["-u", str(params["user"])]) | ||
if "password" in params: | ||
args.extend(["-s", get_secret_from_params(*params["password"])]) # type: ignore[misc] | ||
if "port" in params: | ||
args.extend(["-p", str(params["port"])]) | ||
if params.get("no-cert-check", False): | ||
args.append("--no-cert-check") | ||
|
||
args.extend(str(h) for h in params["hosts"]) # type: ignore[attr-defined] | ||
|
||
yield SpecialAgentCommand(args) | ||
|
||
|
||
special_agent_elasticsearch = SpecialAgentConfig( | ||
name="elasticsearch", | ||
parameter_parser=noop_parser, | ||
commands_function=_agent_elasticsearch_arguments, | ||
) |
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
tests/unit/cmk/plugins/collection/server_side_calls/test_agent_elasticsearch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2 | ||
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and | ||
# conditions defined in the file COPYING, which is part of this source code package. | ||
|
||
|
||
from cmk.plugins.collection.agent_based.agent_elasticsearch import special_agent_elasticsearch | ||
from cmk.server_side_calls.v1 import HostConfig, IPAddressFamily, PlainTextSecret | ||
|
||
TEST_HOST_CONFIG = HostConfig("my_host", "1.2.3.4", "my_alias", IPAddressFamily.IPV4) | ||
|
||
|
||
def test_agent_elasticsearch_arguments_cert_check() -> None: | ||
params: dict[str, object] = { | ||
"hosts": ["testhost"], | ||
"protocol": "https", | ||
"infos": ["cluster_health", "nodestats", "stats"], | ||
} | ||
(cmd,) = special_agent_elasticsearch.commands_function(params, TEST_HOST_CONFIG, {}) | ||
assert "--no-cert-check" not in cmd.command_arguments | ||
|
||
params["no-cert-check"] = True | ||
(cmd,) = special_agent_elasticsearch.commands_function(params, TEST_HOST_CONFIG, {}) | ||
assert "--no-cert-check" in cmd.command_arguments | ||
|
||
|
||
def test_agent_elasticsearch_arguments_password_store() -> None: | ||
params: dict[str, object] = { | ||
"hosts": ["testhost"], | ||
"protocol": "https", | ||
"infos": ["cluster_health", "nodestats", "stats"], | ||
"user": "user", | ||
"password": ("password", "pass"), | ||
} | ||
(cmd,) = special_agent_elasticsearch.commands_function(params, TEST_HOST_CONFIG, {}) | ||
assert cmd.command_arguments == [ | ||
"-P", | ||
"https", | ||
"-m", | ||
"cluster_health", | ||
"nodestats", | ||
"stats", | ||
"-u", | ||
"user", | ||
"-s", | ||
PlainTextSecret("pass"), | ||
"testhost", | ||
] |