Module: check_mk
Branch: master
Commit: 35c5f258abbffb3fd686ca356aa1d8fd4a5f89e2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=35c5f258abbffb…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Mar 29 20:11:32 2019 +0100
Moved help texts to valuespecs
Change-Id: Ic722c095405d3256e14aab77181976c09676f09b
---
cmk/gui/wato/pages/rulesets.py | 57 ++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 24 deletions(-)
diff --git a/cmk/gui/wato/pages/rulesets.py b/cmk/gui/wato/pages/rulesets.py
index d7b8a14..562fc9f 100644
--- a/cmk/gui/wato/pages/rulesets.py
+++ b/cmk/gui/wato/pages/rulesets.py
@@ -1359,7 +1359,7 @@ class EditRuleMode(WatoMode):
(self._ruleset.title(), self._folder.alias_path())
def _get_explicit_rule_conditions(self):
- vs_tag_conditions = HostTagCondition()
+ vs_tag_conditions = self._vs_host_tag_condition()
tag_list = vs_tag_conditions.from_html_vars("")
vs_tag_conditions.validate_value(tag_list, "")
@@ -1524,15 +1524,10 @@ class EditRuleMode(WatoMode):
# Rule folder
forms.section(_("Folder"), css="condition explicit")
self._vs_folder().render_input("new_rule_folder", self._folder.path())
- html.help(_("The rule is only applied to hosts directly in or below this folder."))
# Host tags
forms.section(_("Host tags"), css="condition explicit")
- HostTagCondition().render_input(varprefix="", value=self._rule.tag_specs)
- html.help(
- _("The rule will only be applied to hosts fulfilling all "
- "of the host tag conditions listed here, even if they appear "
- "in the list of explicit host names."))
+ self._vs_host_tag_condition().render_input(varprefix="", value=self._rule.tag_specs)
# Explicit hosts / watolib.ALL_HOSTS
forms.section(_("Explicit hosts"), css="condition explicit")
@@ -1545,27 +1540,10 @@ class EditRuleMode(WatoMode):
if itemtype:
if itemtype == "service":
forms.section(_("Services"), css="condition explicit")
- html.help(
- _("Specify a list of service patterns this rule shall apply to. "
- "The patterns must match the <b>beginning</b> of the service "
- "in question. Adding a <tt>$</tt> to the end forces an excact "
- "match. Pattern use <b>regular expressions</b>. A <tt>.*</tt> will "
- "match an arbitrary text."))
elif itemtype == "checktype":
forms.section(_("Check types"), css="condition explicit")
elif itemtype == "item":
forms.section(self._ruleset.item_name().title(), css="condition explicit")
- if self._ruleset.item_help():
- html.help(self._ruleset.item_help())
- else:
- html.help(
- _("You can make the rule apply only to certain services of the "
- "specified hosts. Do this by specifying explicit <b>items</b> to "
- "match here. <b>Hint:</b> make sure to enter the item only, "
- "not the full Service description. "
- "<b>Note:</b> the match is done on the <u>beginning</u> "
- "of the item in question. Regular expressions are interpreted, "
- "so appending a <tt>$</tt> will force an exact match."))
else:
raise MKUserError(None, "Invalid item type '%s'" % itemtype)
@@ -1608,10 +1586,17 @@ class EditRuleMode(WatoMode):
def _vs_folder(self):
return DropdownChoice(
title=_("Folder"),
+ help=_("The rule is only applied to hosts directly in or below this folder."),
choices=watolib.Folder.folder_choices(),
encode_value=False,
)
+ def _vs_host_tag_condition(self):
+ return HostTagCondition(
+ help=_("The rule will only be applied to hosts fulfilling all "
+ "of the host tag conditions listed here, even if they appear "
+ "in the list of explicit host names."),)
+
def _vs_explicit_hosts(self):
return Alternative(
style="dropdown",
@@ -1664,6 +1649,29 @@ class EditRuleMode(WatoMode):
],
)
+ def _explicit_service_help_text(self):
+ itemtype = self._ruleset.item_type()
+ if itemtype == "service":
+ return _("Specify a list of service patterns this rule shall apply to. "
+ "The patterns must match the <b>beginning</b> of the service "
+ "in question. Adding a <tt>$</tt> to the end forces an excact "
+ "match. Pattern use <b>regular expressions</b>. A <tt>.*</tt> will "
+ "match an arbitrary text.")
+
+ if itemtype == "item":
+ if self._ruleset.item_help():
+ return self._ruleset.item_help()
+
+ return _("You can make the rule apply only to certain services of the "
+ "specified hosts. Do this by specifying explicit <b>items</b> to "
+ "match here. <b>Hint:</b> make sure to enter the item only, "
+ "not the full Service description. "
+ "<b>Note:</b> the match is done on the <u>beginning</u> "
+ "of the item in question. Regular expressions are interpreted, "
+ "so appending a <tt>$</tt> will force an exact match.")
+
+ return None
+
def _vs_service_conditions(self):
itemenum = self._ruleset.item_enum()
if itemenum:
@@ -1679,6 +1687,7 @@ class EditRuleMode(WatoMode):
return ListOfStrings(
orientation="horizontal",
valuespec=RegExpUnicode(size=30, mode=RegExpUnicode.prefix),
+ help=self._explicit_service_help_text(),
)
def _vs_rule_options(self, disabling=True):
Module: check_mk
Branch: master
Commit: 6aa4eeb7d68b4b43e362b35cd8e728593459ae0a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6aa4eeb7d68b4b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Mar 29 22:52:55 2019 +0100
Rule editor: Refactored whole rule conditions to valuespec
* Encapsulated the single valuespec parts into a single
explicit rule condition valuespec
* Moved conversion of values to the valuespec processing logic
* The valuespec expectes a RuleCondition object and produces
one with from_html_vars()
Sorry for the huge commit :-/. Wasn't able to use a more
incremental way.
Change-Id: I3e7b1651418db803586259e0d978062e20f3fe67
---
cmk/gui/valuespec.py | 22 +--
cmk/gui/wato/pages/rulesets.py | 311 +++++++++++++++++++++++------------------
2 files changed, 186 insertions(+), 147 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=6aa4eeb7d6…
Module: check_mk
Branch: master
Commit: 7c89a410396036946d03c11bb00037e0688a4210
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7c89a410396036…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sat Mar 30 00:12:06 2019 +0100
Show condition text in predefined condition list
* Moved the textual rendering of rule conditions to the valuespec
VSExplicitConditions.
* Added a new column "conditions" which displays a description of
the conditions just like the regular rule list tables.
Change-Id: I5284af67e9e4a18590fd9a00146810e068e869c5
---
cmk/gui/wato/pages/predefined_conditions.py | 40 ++--
cmk/gui/wato/pages/rulesets.py | 321 ++++++++++++++--------------
2 files changed, 190 insertions(+), 171 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=7c89a41039…
Module: check_mk
Branch: master
Commit: 86df4cbc83cbde4e2acce791bb2bf46be12fb997
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=86df4cbc83cbde…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Mar 29 16:23:18 2019 +0100
Rule editor: Refactored explicit host condition to valuespec
Change-Id: I29476958df524b0fcc4a5ffcd717130ab071eebc
---
cmk/gui/wato/pages/rulesets.py | 89 +++++++++++++++++++++++++-----------------
1 file changed, 53 insertions(+), 36 deletions(-)
diff --git a/cmk/gui/wato/pages/rulesets.py b/cmk/gui/wato/pages/rulesets.py
index aac811c..45cbc47 100644
--- a/cmk/gui/wato/pages/rulesets.py
+++ b/cmk/gui/wato/pages/rulesets.py
@@ -42,12 +42,15 @@ from cmk.gui.exceptions import MKUserError, MKAuthException
from cmk.gui.i18n import _
from cmk.gui.globals import html
from cmk.gui.valuespec import (
+ FixedValue,
+ Checkbox,
ListChoice,
Tuple,
ListOfStrings,
Dictionary,
RegExpUnicode,
DropdownChoice,
+ Alternative,
)
from cmk.gui.watolib.predefined_conditions import PredefinedConditionStore
from cmk.gui.watolib.rulespecs import (
@@ -1360,19 +1363,21 @@ class EditRuleMode(WatoMode):
vs_tag_conditions.validate_value(tag_list, "")
# Host list
- if not html.get_checkbox("explicit_hosts"):
+ explicit_hosts = self._vs_explicit_hosts().from_html_vars("explicit_hosts")
+ self._vs_explicit_hosts().validate_value(explicit_hosts, "explicit_hosts")
+
+ if explicit_hosts is None:
host_list = watolib.ALL_HOSTS
else:
- negate = html.get_checkbox("negate_hosts")
- vs = ListOfStrings()
- host_list = vs.from_html_vars("hostlist")
- vs.validate_value(host_list, "hostlist")
+ host_list, negate = explicit_hosts
+
if negate:
host_list = [watolib.ENTRY_NEGATE_CHAR + h for h in host_list]
+
# append watolib.ALL_HOSTS to negated host lists
- if len(host_list) > 0 and host_list[0][0] == watolib.ENTRY_NEGATE_CHAR:
+ if host_list and host_list[0][0] == watolib.ENTRY_NEGATE_CHAR:
host_list += watolib.ALL_HOSTS
- elif len(host_list) == 0 and negate:
+ elif not host_list and negate:
host_list = watolib.ALL_HOSTS # equivalent
# Item list
@@ -1537,35 +1542,17 @@ class EditRuleMode(WatoMode):
# Explicit hosts / watolib.ALL_HOSTS
forms.section(_("Explicit hosts"), css="condition explicit")
- div_id = "div_all_hosts"
-
- checked = self._rule.host_list != watolib.ALL_HOSTS
- html.checkbox(
- "explicit_hosts",
- checked,
- onclick="cmk.valuespecs.toggle_option(this, %r)" % div_id,
- label=_("Specify explicit host names"))
- html.open_div(style="display:none;" if not checked else None, id_=div_id)
- negate_hosts = len(self._rule.host_list) > 0 and self._rule.host_list[0].startswith("!")
-
- explicit_hosts = [h.strip("!") for h in self._rule.host_list if h != watolib.ALL_HOSTS[0]]
- ListOfStrings(
- orientation="horizontal", valuespec=ConfigHostname(size=30)).render_input(
- "hostlist", explicit_hosts)
-
- html.checkbox(
- "negate_hosts",
- negate_hosts,
- label=_("<b>Negate:</b> make rule apply for <b>all but</b> the above hosts"))
- html.close_div()
- html.help(
- _("Here you can enter a list of explicit host names that the rule should or should "
- "not apply to. Leave this option disabled if you want the rule to "
- "apply for all hosts specified by the given tags. The names that you "
- "enter here are compared with case sensitive exact matching. Alternatively "
- "you can use regular expressions if you enter a tilde (<tt>~</tt>) as the first "
- "character. That regular expression must match the <i>beginning</i> of "
- "the host names in question."))
+
+ if self._rule.host_list == watolib.ALL_HOSTS:
+ explicit_hosts = None
+ else:
+ explicit_hosts = [
+ h.strip("!") for h in self._rule.host_list if h != watolib.ALL_HOSTS[0]
+ ]
+ negate_hosts = len(self._rule.host_list) > 0 and self._rule.host_list[0].startswith("!")
+ explicit_hosts = (explicit_hosts, negate_hosts)
+
+ self._vs_explicit_hosts().render_input("explicit_hosts", explicit_hosts)
# Itemlist
itemtype = self._ruleset.item_type()
@@ -1660,6 +1647,36 @@ class EditRuleMode(WatoMode):
encode_value=False,
)
+ def _vs_explicit_hosts(self):
+ return Alternative(
+ style="dropdown",
+ elements=[
+ FixedValue(
+ None,
+ title=_("No explicit host filtering"),
+ totext="",
+ ),
+ Tuple(
+ title=_("Specify explicit host names"),
+ elements=[
+ ListOfStrings(orientation="horizontal", valuespec=ConfigHostname(size=30,)),
+ Checkbox(
+ label=_(
+ "<b>Negate:</b> make rule apply for <b>all but</b> the above hosts"
+ ),),
+ ],
+ ),
+ ],
+ help=_(
+ "Here you can enter a list of explicit host names that the rule should or should "
+ "not apply to. Leave this option disabled if you want the rule to "
+ "apply for all hosts specified by the given tags. The names that you "
+ "enter here are compared with case sensitive exact matching. Alternatively "
+ "you can use regular expressions if you enter a tilde (<tt>~</tt>) as the first "
+ "character. That regular expression must match the <i>beginning</i> of "
+ "the host names in question."),
+ )
+
def _vs_service_conditions(self):
return ListOfStrings(
orientation="horizontal",