Module: check_mk
Branch: master
Commit: 1cab789fdae27956647d6f78f602151c7e01aa73
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1cab789fdae279…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun May 6 12:02:46 2012 +0200
ps and ps.perf configurable via WATO now (without inventory)
---
ChangeLog | 2 +
web/htdocs/valuespec.py | 61 +++++++++++++++++++++++++++++-
web/htdocs/wato.py | 2 +-
web/plugins/wato/check_parameters.py | 68 +++++++++++++++++++++++++++++++++-
4 files changed, 129 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5ef3d9f..32c7546 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
1.2.0b4:
+ WATO:
+ * ps and ps.perf configurable via WATO now (without inventory)
1.2.0b3:
Core:
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index a1ecff0..6dde3a7 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -1343,6 +1343,7 @@ class Optional(ValueSpec):
self._none_label = kwargs.get("none_label", _("(unset)"))
self._none_value = kwargs.get("none_value", None)
self._sameline = kwargs.get("sameline", False)
+ self._indent = kwargs.get("indent", True)
def canonical_value(self):
return self._none_value
@@ -1375,14 +1376,18 @@ class Optional(ValueSpec):
if self._sameline:
html.write(" ")
else:
- html.write("<br><br>")
+ html.write("<br>")
html.write("</span>")
if checked == self._negate:
display = "none"
else:
display = ""
+ if self._indent:
+ indent = 40
+ else:
+ indent = 0
- html.write('<span id="%s" style="display: %s">'
% (div_id, display))
+ html.write('<span id="%s" style="margin-left: %dpx;
display: %s">' % (div_id, indent, display))
if value == self._none_value:
value = self._valuespec.default_value()
if self._valuespec.title():
@@ -1418,11 +1423,15 @@ class Alternative(ValueSpec):
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
self._elements = kwargs["elements"]
+ self._match = kwargs.get("match") # custom match function
# Return the alternative (i.e. valuespec)
# that matches the datatype of a given value. We assume
# that always one matches. No error handling here.
def matching_alternative(self, value):
+ if self._match:
+ return self._elements[self._match(value)]
+
for vs in self._elements:
try:
vs.validate_datatype(value, "")
@@ -1762,4 +1771,52 @@ class Foldable(ValueSpec):
self._valuespec.validate_value(value, varprefix)
+# Transforms the value from one representation to
+# another while being completely transparent to the user.
+# forth: function that converts a value into the representation
+# needed by the encapsulated vs
+# back: function that converts a value created by the encapsulated
+# vs back to the outer representation
+
+class Transform(ValueSpec):
+ def __init__(self, valuespec, **kwargs):
+ ValueSpec.__init__(self, **kwargs)
+ self._valuespec = valuespec
+ self._back = kwargs.get("back")
+ self._forth = kwargs.get("forth")
+
+ def forth(self, value):
+ if self._forth:
+ return self._forth(value)
+ else:
+ return value
+
+ def back(self, value):
+ if self._back:
+ return self._back(value)
+ else:
+ return value
+
+ def render_input(self, varprefix, value):
+ self._valuespec.render_input( varprefix, self.forth(value))
+
+ def set_focus(*args):
+ self._valuespec.set_focus(*args)
+
+ def canonical_value(self):
+ return self._valuespec.canonical_value()
+
+ def default_value(self):
+ return self._valuespec.default_value()
+
+ def value_to_text(self, value):
+ return self._valuespec.value_to_text(self.forth(value))
+
+ def from_html_vars(self, varprefix):
+ return self.back(self._valuespec.from_html_vars(varprefix))
+ def validate_datatype(self, value, varprefix):
+ self._valuespec.validate_datatype(self.forth(value), varprefix)
+
+ def validate_value(self, value, varprefix):
+ self._valuespec.validate_value(self.forth(value), varprefix)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 4eed7ca..1f3892c 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -9559,7 +9559,7 @@ def create_rule(rulespec, hostname=None, item=NO_ITEM):
new_rule = []
valuespec = rulespec["valuespec"]
if valuespec:
- new_rule.append(valuespec.canonical_value())
+ new_rule.append(valuespec.default_value())
if hostname:
new_rule.append([hostname])
else:
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 385ecc0..3c947f2 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -1151,7 +1151,7 @@ checkgroups.append((
None,
TextAscii(
title = _("Name of the service"),
- help = _("Pleae Please note, that the agent replaces spaces in "
+ help = _("Pleae Please note, that the agent replaces spaces in "
"the service names with underscores. If you are unsure about the "
"correct spelling of the name then please look at the output of "
"the agent (cmk -d HOSTNAME). The service names are in the first "
@@ -1305,6 +1305,72 @@ register_rulegroup("static", _("Manual
Checks"),
"on your hosts."))
group = "static"
+# Add checks that have parameters but are only configured as manual checks
+checkgroups.append((
+ subgroup_ps,
+ "ps",
+ _("State and count of processes"),
+ Tuple(
+ elements = [
+ Alternative(
+ title = _("Name of the process"),
+ elements = [
+ TextAscii(
+ title = _("Exact name of the process without
argments"),
+ size = 50,
+ ),
+ Transform(
+ RegExp(size = 50),
+ title = _("Regular expression matching command line"),
+ help = _("This regex must match the
<i>beginning</i> of the complete "
+ "command line of the process including
arguments"),
+ forth = lambda x: x[1:], # remove ~
+ back = lambda x: "~" + x, # prefix ~
+ ),
+ FixedValue(
+ None,
+ totext = "",
+ title = _("Match all processes"),
+ )
+ ],
+ match = lambda x: (not x and 2) or (x[0] == '~' and 1 or 0)
+ ),
+ TextAscii(
+ title = _("Name of operating system user"),
+ help = _("Leave this empty, if the user does not matter"),
+ none_is_empty = True,
+ ),
+ Integer(
+ title = _("Minimum number of matched process for WARNING
state"),
+ default_value = 1,
+ ),
+ Integer(
+ title = _("Minimum number of matched process for OK state"),
+ default_value = 1,
+ ),
+ Integer(
+ title = _("Maximum number of matched process for OK state"),
+ default_value = 1,
+ ),
+ Integer(
+ title = _("Maximum number of matched process for WARNING
state"),
+ default_value = 1,
+ ),
+ ]),
+ TextAscii(
+ title = _("Name of service"),
+ help = _("This name will be used in the description of the service"),
+ allow_empty = False,
+ regex = "^[a-zA-Z_0-9 _.-]*$",
+ regex_error = _("Please use only a-z, A-Z, 0-9, space, underscore, "
+ "dot and hyphon for your service description"),
+ ),
+ "first"))
+
+
+
+
+
for subgroup, checkgroup, title, valuespec, itemspec, matchtype in checkgroups:
elements = [
CheckTypeGroupSelection(