Skip to content

Commit

Permalink
Implement internal form spec MonitoredHostExtended
Browse files Browse the repository at this point in the history
`MonitoredHostExtended` is effectively an extension of `MonitoredHost` with the
option to specify a default value.

CMK-19497

Change-Id: I78e8db6fa64e5db8261ea092aeea7140743e8c26
  • Loading branch information
jherbel committed Oct 9, 2024
1 parent c640b16 commit be038df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmk/gui/form_specs/private/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .dictionary_extended import DictionaryExtended
from .list_extended import ListExtended
from .list_of_strings import ListOfStrings
from .monitored_host_extended import MonitoredHostExtended
from .multiple_choice import AdaptiveMultipleChoice, AdaptiveMultipleChoiceLayout
from .optional_choice import OptionalChoice
from .string_autocompleter import StringAutocompleter
Expand All @@ -35,4 +36,5 @@
"not_empty",
"AdaptiveMultipleChoice",
"AdaptiveMultipleChoiceLayout",
"MonitoredHostExtended",
]
13 changes: 13 additions & 0 deletions cmk/gui/form_specs/private/monitored_host_extended.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3
# Copyright (C) 2024 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 dataclasses import dataclass

from cmk.rulesets.v1.form_specs import DefaultValue, FormSpec


@dataclass(frozen=True, kw_only=True)
class MonitoredHostExtended(FormSpec[str]):
prefill: DefaultValue[str]
7 changes: 5 additions & 2 deletions cmk/gui/utils/rule_specs/legacy_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DictionaryExtended,
ListExtended,
ListOfStrings,
MonitoredHostExtended,
)
from cmk.gui.form_specs.vue.shared_type_defs import ListOfStringsLayout
from cmk.gui.form_specs.vue.visitors import DefaultValue as VueDefaultValue
Expand Down Expand Up @@ -747,7 +748,7 @@ def _convert_to_inner_legacy_valuespec(
case ruleset_api_v1.form_specs.Metric():
return _convert_to_legacy_metric_name(to_convert, localizer)

case ruleset_api_v1.form_specs.MonitoredHost():
case ruleset_api_v1.form_specs.MonitoredHost() | MonitoredHostExtended():
return _convert_to_legacy_monitored_host_name(to_convert, localizer)

case ruleset_api_v1.form_specs.MonitoredService():
Expand Down Expand Up @@ -2205,7 +2206,7 @@ def _convert_to_legacy_metric_name(


def _convert_to_legacy_monitored_host_name(
to_convert: ruleset_api_v1.form_specs.MonitoredHost,
to_convert: ruleset_api_v1.form_specs.MonitoredHost | MonitoredHostExtended,
localizer: Callable[[str], str],
) -> legacy_valuespecs.MonitoredHostname:
converted_kwargs: dict[str, Any] = {
Expand All @@ -2223,6 +2224,8 @@ def _convert_to_legacy_monitored_host_name(
if (title := _localize_optional(to_convert.title, localizer)) is None:
title = ruleset_api_v1.Title("Host name").localize(localizer)
converted_kwargs["title"] = title
if isinstance(to_convert, MonitoredHostExtended):
converted_kwargs["default_value"] = to_convert.prefill.value

return legacy_valuespecs.MonitoredHostname(**converted_kwargs)

Expand Down

0 comments on commit be038df

Please sign in to comment.