diff --git a/cmk/base/check_legacy_includes/db2.py b/cmk/base/check_legacy_includes/db2.py deleted file mode 100644 index 5c1bb49964e..00000000000 --- a/cmk/base/check_legacy_includes/db2.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/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. - - -def parse_db2_dbs(info): - current_instance = None - lines = iter(info) - dbs: dict = {} - global_timestamp = None - try: - while True: - line = next(lines) - if line[0].startswith("TIMESTAMP") and not current_instance: - global_timestamp = int(line[1]) - continue - - if line[0].startswith("[[["): - current_instance = line[0][3:-3] - dbs[current_instance] = [] - elif current_instance: - dbs[current_instance].append(line) - except Exception: - pass - - # By returning a tuple, we trick Checkmk - # Even if no information is available, an empty tuple is something - # Checkmk won't report any missing agent sections for this type of checks - return global_timestamp, dbs diff --git a/cmk/base/legacy_checks/db2_backup.py b/cmk/base/legacy_checks/db2_backup.py index 91463a16fdb..af09cc23bcd 100644 --- a/cmk/base/legacy_checks/db2_backup.py +++ b/cmk/base/legacy_checks/db2_backup.py @@ -6,10 +6,9 @@ import time -from cmk.base.check_legacy_includes.db2 import parse_db2_dbs - from cmk.agent_based.legacy.v0_unstable import check_levels, LegacyCheckDefinition from cmk.agent_based.v2 import IgnoreResultsError, render +from cmk.plugins.db2.agent_based.lib import parse_db2_dbs check_info = {} diff --git a/cmk/base/legacy_checks/db2_bp_hitratios.py b/cmk/base/legacy_checks/db2_bp_hitratios.py index 7dbb7873a4c..a05d940e3ac 100644 --- a/cmk/base/legacy_checks/db2_bp_hitratios.py +++ b/cmk/base/legacy_checks/db2_bp_hitratios.py @@ -6,10 +6,9 @@ # mypy: disable-error-code="var-annotated" -from cmk.base.check_legacy_includes.db2 import parse_db2_dbs - from cmk.agent_based.legacy.v0_unstable import LegacyCheckDefinition from cmk.agent_based.v2 import IgnoreResultsError +from cmk.plugins.db2.agent_based.lib import parse_db2_dbs check_info = {} diff --git a/cmk/base/legacy_checks/db2_connections.py b/cmk/base/legacy_checks/db2_connections.py index 25134ab464a..8399672256f 100644 --- a/cmk/base/legacy_checks/db2_connections.py +++ b/cmk/base/legacy_checks/db2_connections.py @@ -4,10 +4,9 @@ # conditions defined in the file COPYING, which is part of this source code package. -from cmk.base.check_legacy_includes.db2 import parse_db2_dbs - from cmk.agent_based.legacy.v0_unstable import LegacyCheckDefinition from cmk.agent_based.v2 import IgnoreResultsError +from cmk.plugins.db2.agent_based.lib import parse_db2_dbs check_info = {} diff --git a/cmk/base/legacy_checks/db2_logsizes.py b/cmk/base/legacy_checks/db2_logsizes.py index 228f72fe385..c4289b5b796 100644 --- a/cmk/base/legacy_checks/db2_logsizes.py +++ b/cmk/base/legacy_checks/db2_logsizes.py @@ -6,11 +6,11 @@ # mypy: disable-error-code="var-annotated" -from cmk.base.check_legacy_includes.db2 import parse_db2_dbs from cmk.base.check_legacy_includes.df import df_check_filesystem_single from cmk.agent_based.legacy.v0_unstable import LegacyCheckDefinition from cmk.agent_based.v2 import IgnoreResultsError +from cmk.plugins.db2.agent_based.lib import parse_db2_dbs check_info = {} diff --git a/cmk/base/legacy_checks/db2_sort_overflow.py b/cmk/base/legacy_checks/db2_sort_overflow.py index 6d741eac6aa..69712d5960c 100644 --- a/cmk/base/legacy_checks/db2_sort_overflow.py +++ b/cmk/base/legacy_checks/db2_sort_overflow.py @@ -4,10 +4,9 @@ # conditions defined in the file COPYING, which is part of this source code package. -from cmk.base.check_legacy_includes.db2 import parse_db2_dbs - from cmk.agent_based.legacy.v0_unstable import LegacyCheckDefinition from cmk.agent_based.v2 import IgnoreResultsError +from cmk.plugins.db2.agent_based.lib import parse_db2_dbs check_info = {} diff --git a/cmk/base/legacy_checks/db2_tablespaces.py b/cmk/base/legacy_checks/db2_tablespaces.py index 3a766da3c53..13e99e8701d 100644 --- a/cmk/base/legacy_checks/db2_tablespaces.py +++ b/cmk/base/legacy_checks/db2_tablespaces.py @@ -6,11 +6,10 @@ # mypy: disable-error-code="arg-type" -from cmk.base.check_legacy_includes.db2 import parse_db2_dbs - import cmk.plugins.lib.db from cmk.agent_based.legacy.v0_unstable import LegacyCheckDefinition from cmk.agent_based.v2 import IgnoreResultsError, render +from cmk.plugins.db2.agent_based.lib import parse_db2_dbs check_info = {} diff --git a/cmk/plugins/db2/agent_based/lib.py b/cmk/plugins/db2/agent_based/lib.py new file mode 100644 index 00000000000..e86829d9586 --- /dev/null +++ b/cmk/plugins/db2/agent_based/lib.py @@ -0,0 +1,29 @@ +#!/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 collections.abc import Mapping + +from cmk.agent_based.v2 import StringTable + +# this is the truth, but Sequence/tuple would be more desirable than a list. +Section = tuple[int | None, Mapping[str, list[list[str]]]] + + +def parse_db2_dbs(string_table: StringTable) -> Section: + current_instance = None + dbs: dict[str, list[list[str]]] = {} + global_timestamp = None + for line in string_table: + if line[0].startswith("TIMESTAMP") and not current_instance: + global_timestamp = int(line[1]) + continue + + if line[0].startswith("[[["): + current_instance = line[0][3:-3] + dbs[current_instance] = [] + elif current_instance: + dbs[current_instance].append(line) + + return global_timestamp, dbs