Skip to content

Commit

Permalink
improve typing: legacy includes / dell_omx.py
Browse files Browse the repository at this point in the history
Change-Id: I1a33cbb15c92ee06ed9bbcc7ccd22df5dbb87764
  • Loading branch information
mo-ki committed Feb 12, 2025
1 parent 9bf2195 commit cd076e9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cmk/base/check_legacy_includes/dell_om.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
# 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 Iterable, Mapping

from cmk.agent_based.v2 import StringTable

# The OpenManage module attaches itself to the SNMP agent of the
# operating system. We trigger on all Windows and Linux systems.
# This is not optimal but still enough for excluding network
# devices and similar stuff


def parse_omreport(info):
result = {}
def _parse_single_objects(string_table: StringTable) -> Iterable[Mapping[str, str]]:
current_obj: dict = {}

def insert(obj):
result[obj["ID"]] = obj.copy()
obj.clear()

for line in info:
for line in string_table:
try:
idx = line.index(":")
except ValueError:
Expand All @@ -27,13 +25,17 @@ def insert(obj):
key = " ".join(line[:idx])
value = " ".join(line[idx + 1 :])
if key == "ID" and current_obj:
insert(current_obj)
yield current_obj
current_obj = {}

current_obj[key] = value

insert(current_obj)
return result
yield current_obj


def parse_omreport(string_table: StringTable) -> Mapping[str, Mapping[str, str]]:
return {o["ID"]: o for o in _parse_single_objects(string_table)}


def status_translate_omreport(code):
def status_translate_omreport(code: str) -> int:
return {"ok": 0, "non-critical": 1, "critical": 2, "not found": 3}.get(code.lower(), 2)

0 comments on commit cd076e9

Please sign in to comment.