Commit ac4d391e authored by root's avatar root
Browse files

Merge branch 'master' of https://github.com/tribe29/checkmk

parents ea7ad5ae 01756438
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 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 typing import Mapping
from .agent_based_api.v1 import Attributes, register
from .agent_based_api.v1.type_defs import InventoryResult, StringTable
from .utils import docker
Section = Mapping[str, object]
def parse_docker_container_node_name(string_table: StringTable) -> Section:
return docker.parse(string_table).data
register.agent_section(
name="inventory_docker_container_node_name",
parse_function=parse_docker_container_node_name,
)
def inventory_docker_container_node_name(section: Section) -> InventoryResult:
if (node := section.get("NodeName")) is not None:
yield Attributes(
path=["software", "applications", "docker", "container"],
inventory_attributes={"node_name": str(node)},
)
register.inventory_plugin(
name="inventory_docker_container_node_name",
inventory_function=inventory_docker_container_node_name,
)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 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.
import cmk.base.plugins.agent_based.utils.docker as docker
def inv_docker_container_node_name(info, inventory_tree):
parsed = docker.parse(info).data
container = inventory_tree.get_dict("software.applications.docker.container.")
if parsed.get("NodeName") is not None:
container["node_name"] = parsed["NodeName"]
inv_info["docker_container_node_name"] = { # pylint: disable=undefined-variable
"inv_function": inv_docker_container_node_name,
}
......@@ -108,7 +108,6 @@ def test_no_plugins_with_trivial_sections(fix_register):
"aix_service_packs",
"couchbase_nodes_ports",
"docker_container_network",
"docker_container_node_name",
"docker_node_images",
"k8s_assigned_pods",
"k8s_daemon_pod_containers",
......
......@@ -6,32 +6,33 @@
import pytest
from cmk.utils.type_defs import InventoryPluginName
from cmk.base.plugins.agent_based.agent_based_api.v1 import Attributes
from cmk.base.plugins.agent_based.inventory_docker_container_node_name import (
inventory_docker_container_node_name,
parse_docker_container_node_name,
Section,
)
from cmk.base.plugins.agent_based.utils.docker import AgentOutputMalformatted
from .utils_inventory import sort_inventory_result
AGENT_OUTPUT = """@docker_version_info\0{"PluginVersion": "0.1", "DockerPyVersion": "4.1.0", "ApiVersion": "1.41"}
{"NodeName": "klappben"}"""
def test_inv_docker_container_node_name(fix_register):
info = [line.split("\0") for line in AGENT_OUTPUT.split("\n")]
plugin = fix_register.inventory_plugins[InventoryPluginName("docker_container_node_name")]
assert sort_inventory_result(plugin.inventory_function(info)) == sort_inventory_result(
[
Attributes(
path=["software", "applications", "docker", "container"],
inventory_attributes={"node_name": "klappben"},
status_attributes={},
)
]
)
@pytest.fixture(name="section", scope="module")
def _get_section() -> Section:
return parse_docker_container_node_name([line.split("\0") for line in AGENT_OUTPUT.split("\n")])
def test_inv_docker_container_node_name(section: Section) -> None:
assert list(inventory_docker_container_node_name(section)) == [
Attributes(
path=["software", "applications", "docker", "container"],
inventory_attributes={"node_name": "klappben"},
status_attributes={},
)
]
def test_inv_docker_container_node_name_legacy_agent_output(fix_register):
plugin = fix_register.inventory_plugins[InventoryPluginName("docker_container_node_name")]
def test_inv_docker_container_node_name_legacy_agent_output():
with pytest.raises(AgentOutputMalformatted):
list(plugin.inventory_function([["node_name"]]))
parse_docker_container_node_name([["node_name"]])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment