Skip to content

Commit

Permalink
improve typing: legacy includes / db2
Browse files Browse the repository at this point in the history
Change-Id: I675130a4eab43a88c7db284163d212a59d581702
  • Loading branch information
mo-ki committed Jan 14, 2025
1 parent c4f5c17 commit 5d4bc24
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 41 deletions.
30 changes: 0 additions & 30 deletions cmk/base/check_legacy_includes/db2.py

This file was deleted.

3 changes: 1 addition & 2 deletions cmk/base/legacy_checks/db2_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
3 changes: 1 addition & 2 deletions cmk/base/legacy_checks/db2_bp_hitratios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
3 changes: 1 addition & 2 deletions cmk/base/legacy_checks/db2_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
2 changes: 1 addition & 1 deletion cmk/base/legacy_checks/db2_logsizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
3 changes: 1 addition & 2 deletions cmk/base/legacy_checks/db2_sort_overflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
3 changes: 1 addition & 2 deletions cmk/base/legacy_checks/db2_tablespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
29 changes: 29 additions & 0 deletions cmk/plugins/db2/agent_based/lib.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5d4bc24

Please sign in to comment.