Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Monitoring
Checkmk
Commits
01756438
Commit
01756438
authored
May 21, 2022
by
Moritz Kiemer
Browse files
migrate docker_container_node_name
Change-Id: I530ad96f501df6935b4967fadf592dc530122ac4
parent
aa65e346
Changes
4
Hide whitespace changes
Inline
Side-by-side
cmk/base/plugins/agent_based/inventory_docker_container_node_name.py
0 → 100644
View file @
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
,
)
inventory/docker_container_node_name
deleted
100644 → 0
View file @
aa65e346
#!/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
,
}
tests/unit/cmk/base/plugins/agent_based/test_check_plugin_properties.py
View file @
01756438
...
...
@@ -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"
,
...
...
tests/unit/cmk/base/plugins/agent_based/test_inv_docker_container_node_name.py
View file @
01756438
...
...
@@ -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"
]])
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment