Module: check_mk
Branch: master
Commit: b2210ce0c40f76a5a605e93f8c529588c23633da
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2210ce0c40f76…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Feb 2 11:39:21 2012 +0100
WATO: fixed several check parameter rules
---
checks/cpu | 2 +-
checks/if.include | 2 +-
web/htdocs/valuespec.py | 25 +++++++++++++++++++------
web/htdocs/wato.py | 13 ++++++++++---
web/plugins/wato/check_parameters.py | 27 +++++++++++++++++++--------
5 files changed, 50 insertions(+), 19 deletions(-)
diff --git a/checks/cpu b/checks/cpu
index 811b33b..e2bb254 100644
--- a/checks/cpu
+++ b/checks/cpu
@@ -29,7 +29,7 @@
cpuload_default_levels = (5, 10)
-threads_default_levels = (2000.0, 4000.0)
+threads_default_levels = (2000, 4000)
def inventory_cpu_load(info):
if len(info) == 1 and len(info[0]) >= 5:
diff --git a/checks/if.include b/checks/if.include
index a003d2a..dedc1fd 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -116,7 +116,7 @@ def inventory_if_common(info):
paramstring = "{"
if if_inventory_monitor_state:
- paramstring += '"state" : "%s",' %
ifOperStatus
+ paramstring += '"state" : ["%s"],' %
ifOperStatus
if ifSpeed != "" and if_inventory_monitor_speed:
paramstring += '"speed" : %d,' % int(ifSpeed)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 8707a3f..21e3d65 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -163,7 +163,7 @@ class Age(ValueSpec):
def validate_datatype(self, value, varprefix):
if type(value) != int:
- raise MKUserError(varprefix, _("The value has type %s, but must be of
type int") % (type(value)))
+ raise MKUserError(varprefix, _("The value %r has type %s, but must be of
type int") % (value, type(value)))
# Editor for a single integer
@@ -220,7 +220,8 @@ class Integer(ValueSpec):
def validate_datatype(self, value, varprefix):
if type(value) != int:
- raise MKUserError(varprefix, _("The value has type %s, but must be of
type int") % (type(value)))
+ raise MKUserError(varprefix, _("The value %r has the wrong type %s, but
must be of type int")
+ % (value, type(value)))
def validate_value(self, value, varprefix):
if self._minvalue != None and value < self._minvalue:
@@ -487,7 +488,7 @@ class Float(Integer):
def validate_datatype(self, value, varprefix):
if type(value) != float:
- raise MKUserError(varprefix, _("The value has type %s, but must be of
type float") % (type(value)))
+ raise MKUserError(varprefix, _("The value %r has type %s, but must be of
type float") % (value, type(value)))
class Percentage(Float):
@@ -499,10 +500,19 @@ class Percentage(Float):
self._maxvalue = 101.0
if "unit" not in kwargs:
self._unit = "%"
+ self._allow_int = kwargs.get("allow_int", False)
def value_to_text(self, value):
return "%.1f%%" % value
+ def validate_datatype(self, value, varprefix):
+ if self._allow_int:
+ if type(value) not in [ int, float ]:
+ raise MKUserError(varprefix, _("The value %r has type %s, but must
be either float or int")
+ % (value, type(value)))
+ else:
+ Float.validate_datatype(self, value, varprefix)
+
class Checkbox(ValueSpec):
def __init__(self, **kwargs):
@@ -526,7 +536,7 @@ class Checkbox(ValueSpec):
def validate_datatype(self, value, varprefix):
if type(value) != bool:
- raise MKUserError(varprefix, _("The value has type %s, but must be
either True or False") % (type(value)))
+ raise MKUserError(varprefix, _("The value %r has type %s, but must be of
type bool") % (value, type(value)))
# A type-save dropdown choice. Parameters:
# help_separator: if you set this to a character, e.g. "-", then
@@ -1256,7 +1266,10 @@ class Dictionary(ValueSpec):
for param, vs in self._elements:
if param in value:
vp = varprefix + "_" + param
- vs.validate_datatype(value[param], vp)
+ try:
+ vs.validate_datatype(value[param], vp)
+ except MKUserError, e:
+ raise MKUserError(e.varname, _("%s: %s") % (vs.title(),
e.message))
elif not self._optional_keys:
raise MKUserError(varprefix, _("The entry %s is missing") %
vp.title())
@@ -1265,7 +1278,7 @@ class Dictionary(ValueSpec):
for param in value.keys():
if param not in allowed_keys:
raise MKUserError(varprefix, _("Undefined key '%s' in the
dictionary. Allowed are %s.") %
- ", ".join(allowed_keys))
+ (param, ", ".join(allowed_keys)))
def validate_value(self, value, varprefix):
for param, vs in self._elements:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 8585138..6648131 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2027,9 +2027,16 @@ def show_service_table(host, firsttime):
("varname", varname),
("host", hostname),
("item", repr(item))])
- title = _("Edit rules for this check parameter")
- title = "Check parameters for this service: " + \
- rulespec["valuespec"].value_to_text(params)
+ try:
+ rulespec["valuespec"].validate_datatype(params,
"")
+ rulespec["valuespec"].validate_value(params,
"")
+ paramtext =
rulespec["valuespec"].value_to_text(params)
+ except Exception, e:
+ if config.debug:
+ raise
+ paramtext = _("Invalid check parameter: %s!") % e
+
+ title = "Check parameters for this service: " + paramtext
html.write('<a href="%s"><img
title="%s" class=icon
src="images/icon_rulesets.png"></a>' %
(url, title))
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 2e1b0f6..ed1ce73 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -453,8 +453,8 @@ checkgroups.append((
Tuple(
title = _("Levels for the used space"),
elements = [
- Percentage(title = _("Warning at"), label = _("%
usage")),
- Percentage(title = _("Critical at"), label = _("%
usage"))])),
+ Percentage(title = _("Warning at"), label = _("%
usage"), allow_int = True),
+ Percentage(title = _("Critical at"), label = _("%
usage"), allow_int = True)])),
( "magic",
Float(
title = _("Magic factor (automatic level adaptation for large
filesystems)"),
@@ -465,11 +465,22 @@ checkgroups.append((
title = _("Reference size for magic factor"),
minvalue = 1,
label = _("GB"))),
+ ( "levels_low",
+ Tuple(
+ title = _("Minimum levels if using magic factor"),
+ help = _("The filesystem levels will never fall below these
values, when using "
+ "the magic factor and the filesystem is very
small."),
+ elements = [
+ Percentage(title = _("Warning at"), label = _("%
usage"), allow_int = True),
+ Percentage(title = _("Critical at"), label = _("%
usage"), allow_int = True)])),
( "trend_range",
- Integer(
- title = _("Range for filesystem trend computation"),
- minvalue = 1,
- label= _("hours"))),
+ Optional(
+ Integer(
+ title = _("Range for filesystem trend computation"),
+ minvalue = 1,
+ label= _("hours")),
+ title = _("Trend computation"),
+ label = _("Enable trend computation"))),
( "trend_mb",
Tuple(
title = _("Levels on trends in MB per range"),
@@ -612,8 +623,8 @@ checkgroups.append((
Tuple(
title = _("Specify levels in percentage of total RAM"),
elements = [
- Percentage(title = _("Warning at a usage of"), label =
_("% of RAM")),
- Percentage(title = _("Critical at a usage of"), label =
_("% of RAM"))]),
+ Percentage(title = _("Warning at a usage of"), label =
_("% of RAM"), max_value = None),
+ Percentage(title = _("Critical at a usage of"), label =
_("% of RAM"), max_value = None)]),
Tuple(
title = _("Specify levels in absolute usage values"),
elements = [