Module: check_mk
Branch: master
Commit: 0a1e4b1e0a58a9f41ab8fb6c2aff531170162fae
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0a1e4b1e0a58a9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 2 20:20:09 2018 +0100
Moved valuespec helper function dict_choices() to the related valuespecs
Change-Id: I7fd0ea56c0e70f65698356fc2ef45e31e0b1c2ee
---
web/htdocs/lib.py | 10 ----------
web/htdocs/valuespec.py | 10 ++++++++++
web/plugins/visuals/inventory.py | 2 +-
web/plugins/wato/check_parameters.py | 10 +++++-----
web/plugins/wato/inventory.py | 2 +-
5 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 897c962..c1861de 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -749,13 +749,3 @@ def file_size_human_readable(file_size):
as_string = as_string[:-3]
result = as_string + result
return result
-
-# For usage in Dropdown choices an the like
-#
-# TODO: Move this functionality into the related value specs. We could simply
-# make them work with choices passed as dict types and then use this logic
-# to convert the dict to choices.
-def dict_choices(types):
- return [ (str(type_id), "%d - %s" % (type_id, type_name))
- for (type_id, type_name)
- in sorted(types.items()) ]
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index b5dd0f1..c2ba6e5 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1555,6 +1555,8 @@ class DropdownChoice(ValueSpec):
result = []
if type(self._choices) == list:
result = self._choices
+ elif type(self._choices) == dict:
+ result = ListChoice.dict_choices(self._choices)
else:
result = self._choices()
@@ -1980,6 +1982,12 @@ class RadioChoice(DropdownChoice):
# A list of checkboxes representing a list of values
class ListChoice(ValueSpec):
+ @staticmethod
+ def dict_choices(types):
+ return [ ("%s" % type_id, "%d - %s" % (type_id, type_name))
+ for (type_id, type_name) in sorted(types.items()) ]
+
+
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
self._choices = kwargs.get("choices")
@@ -1999,6 +2007,8 @@ class ListChoice(ValueSpec):
if self._choices != None:
if type(self._choices) == list:
self._elements = self._choices
+ elif type(self._choices) == dict:
+ self._elements = ListChoice.dict_choices(self._choices)
else:
self._elements = self._choices()
return
diff --git a/web/plugins/visuals/inventory.py b/web/plugins/visuals/inventory.py
index 7ed958c..45ae28d 100644
--- a/web/plugins/visuals/inventory.py
+++ b/web/plugins/visuals/inventory.py
@@ -266,7 +266,7 @@ class FilterInvtableInterfaceType(Filter):
def valuespec(self):
return DualListChoice(
- choices = dict_choices(defines.interface_port_types()),
+ choices = defines.interface_port_types(),
rows = 4,
enlarge_active = True,
custom_order = True)
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index c28d0f4..ab333ed 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -965,7 +965,7 @@ register_rule(group + '/' + subgroup_inventory,
"<tt>ifAdminStatus</tt> of
<tt>down</tt> - a port administratively switched off. If you check this option
"
"then an alternate version of the check is being used that
fetches the <tt>ifAdminState</tt> in addition. "
"This will add about 5% of additional SNMP traffic."),
- choices = dict_choices(defines.interface_oper_states()),
+ choices = defines.interface_oper_states(),
toggle_all = True,
default_value = ['1'],
)),
@@ -973,7 +973,7 @@ register_rule(group + '/' + subgroup_inventory,
DualListChoice(title = _("Network interface port types to
discover"),
help = _("When doing discovery on switches or other devices with
network interfaces "
"then only ports of the specified types will be created
services for."),
- choices = dict_choices(defines.interface_port_types()),
+ choices = defines.interface_port_types(),
custom_order = True,
rows = 40,
toggle_all = True,
@@ -7882,7 +7882,7 @@ register_check_parameters(
Optional(
ListChoice(
title = _("Allowed states:"),
- choices = dict_choices(defines.interface_oper_states())),
+ choices = defines.interface_oper_states()),
title = _("Operational state"),
help = _("If you activate the monitoring of the operational
state (<tt>ifOperStatus</tt>) "
"the check will get warning or critical if the current
state "
@@ -7898,7 +7898,7 @@ register_check_parameters(
Tuple(
orientation = "horizontal",
elements = [
- DropdownChoice(choices =
dict_choices(defines.interface_oper_states())),
+ DropdownChoice(choices = defines.interface_oper_states()),
MonitoringState()
]),
title = _('Map operational states'),
@@ -11780,7 +11780,7 @@ vs_elements_if_groups_matches = [
("iftype", Transform(
DropdownChoice(
title = _("Select interface port type"),
- choices = dict_choices(defines.interface_port_types()),
+ choices = defines.interface_port_types(),
help = _("Only interfaces with the given port type are put into this
group. "
"For example 53 (propVirtual)."),
), forth = lambda x: str(x),
diff --git a/web/plugins/wato/inventory.py b/web/plugins/wato/inventory.py
index b9644f9..d171245 100644
--- a/web/plugins/wato/inventory.py
+++ b/web/plugins/wato/inventory.py
@@ -153,7 +153,7 @@ register_rule(group,
( "usage_port_types",
DualListChoice(
title = _("Port types to include in usage statistics"),
- choices = dict_choices(defines.interface_port_types()),
+ choices = defines.interface_port_types(),
autoheight = False,
rows = 40,
enlarge_active = False,