Skip to content

Commit 9ebcb4d

Browse files
committed
modernize: agent_elasticsearch II
Change-Id: I5294b5cf8bdd6d0c55262ce43f0d5d08462e5f65
1 parent d6e1af5 commit 9ebcb4d

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

cmk/plugins/elasticsearch/special_agent/agent_elasticsearch.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# mypy: disable-error-code="possibly-undefined"
77

88
import argparse
9+
import json
910
import sys
1011
from collections.abc import Mapping, Sequence
1112

@@ -14,7 +15,6 @@
1415

1516
from cmk.password_store.v1_unstable import parser_add_secret_option, resolve_secret_option
1617
from cmk.server_side_programs.v1_unstable import report_agent_crashes, vcrtrace
17-
from cmk.special_agents.v0_unstable.agent_common import SectionWriter
1818

1919
__version__ = "2.5.0b1"
2020

@@ -139,9 +139,9 @@ def parse_arguments(argv: Sequence[str]) -> argparse.Namespace:
139139

140140

141141
def handle_cluster_health(response: Mapping[str, object]) -> None:
142-
with SectionWriter("elasticsearch_cluster_health", separator=" ") as writer:
143-
for item, value in response.items():
144-
writer.append(f"{item} {value}")
142+
sys.stdout.write("<<<elasticsearch_cluster_health:sep(32)>>>\n")
143+
for item, value in response.items():
144+
sys.stdout.write(f"{item} {value}\n")
145145

146146

147147
class _CPUResponse(pydantic.BaseModel, frozen=True):
@@ -170,26 +170,25 @@ class _NodesReponse(pydantic.BaseModel, frozen=True):
170170

171171

172172
def handle_nodes(response: Mapping[str, object]) -> None:
173-
with SectionWriter("elasticsearch_nodes", separator=" ") as writer:
174-
for node_response in _NodesReponse.model_validate(response).nodes.values():
175-
writer.append(
176-
f"{node_response.name} open_file_descriptors {node_response.process.open_file_descriptors}"
177-
)
178-
writer.append(
179-
f"{node_response.name} max_file_descriptors {node_response.process.max_file_descriptors}"
180-
)
181-
writer.append(f"{node_response.name} cpu_percent {node_response.process.cpu.percent}")
182-
writer.append(
183-
f"{node_response.name} cpu_total_in_millis {node_response.process.cpu.total_in_millis}"
184-
)
185-
writer.append(
186-
f"{node_response.name} mem_total_virtual_in_bytes {node_response.process.mem.total_virtual_in_bytes}"
187-
)
173+
sys.stdout.write("<<<elasticsearch_nodes:sep(32)>>>\n")
174+
for node_response in _NodesReponse.model_validate(response).nodes.values():
175+
sys.stdout.write(
176+
f"{node_response.name} open_file_descriptors {node_response.process.open_file_descriptors}\n"
177+
)
178+
sys.stdout.write(
179+
f"{node_response.name} max_file_descriptors {node_response.process.max_file_descriptors}\n"
180+
)
181+
sys.stdout.write(f"{node_response.name} cpu_percent {node_response.process.cpu.percent}\n")
182+
sys.stdout.write(
183+
f"{node_response.name} cpu_total_in_millis {node_response.process.cpu.total_in_millis}\n"
184+
)
185+
sys.stdout.write(
186+
f"{node_response.name} mem_total_virtual_in_bytes {node_response.process.mem.total_virtual_in_bytes}\n"
187+
)
188188

189189

190190
def handle_stats(response: Mapping[str, object]) -> None:
191-
with SectionWriter("elasticsearch_indices") as writer:
192-
writer.append_json(response["indices"])
191+
sys.stdout.write(f"<<<elasticsearch_indices:sep(0)>>>\n{json.dumps(response['indices'])}\n")
193192

194193

195194
@report_agent_crashes(AGENT, __version__)

0 commit comments

Comments
 (0)