[checkmk-commits] Check_MK Git: check_mk: New API for declaring WATO rules for own checks

git version control git at mathias-kettner.de
Fri Nov 9 14:48:36 CET 2012


Module: check_mk
Branch: master
Commit: 27017d2b506b52a656fe7abbd8c3f5d2d1bce454
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=27017d2b506b52a656fe7abbd8c3f5d2d1bce454

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Fri Nov  9 14:48:32 2012 +0100

New API for declaring WATO rules for own checks

---

 web/htdocs/wato.py                   |   59 ++++++++++++++++++++++++++++++++++
 web/plugins/wato/check_parameters.py |   58 +++------------------------------
 2 files changed, 65 insertions(+), 52 deletions(-)

diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index cd017b5..946ab41 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -10965,6 +10965,65 @@ def register_rule(group, varname, valuespec = None, title = None,
 
     g_rulespecs[varname] = ruleset
 
+# Special version of register_rule, dedicated to checks. This is not really
+# modular here, but we cannot put this function into the plugins file because
+# the order is not defined there.
+def register_check_parameters(subgroup, checkgroup, title, valuespec, itemspec, matchtype, has_inventory=True):
+    # Register rule for inventorized checks
+    if valuespec and has_inventory: # would be useless rule if check has no parameters
+        itemenum = None
+        if itemspec:
+            itemtype = "item"
+            itemname = itemspec.title()
+            itemhelp = itemspec.help()
+            if isinstance(itemspec, DropdownChoice):
+                itemenum = itemspec._choices
+        else:
+            itemtype = None
+            itemname = None
+            itemhelp = None
+
+        register_rule(
+            "checkparams/" + subgroup,
+            varname = "checkgroup_parameters:%s" % checkgroup,
+            title = title,
+            valuespec = valuespec,
+            itemtype = itemtype, itemname = itemname,
+            itemhelp = itemhelp,
+            itemenum = itemenum,
+            match = matchtype)
+
+    # Register rule for static checks
+    elements = [
+        CheckTypeGroupSelection(
+            checkgroup,
+            title = _("Checktype"),
+            help = _("Please choose the check plugin")) ]
+    if itemspec:
+        elements.append(itemspec)
+    if not valuespec:
+        valuespec =\
+            FixedValue(None,
+                help = _("This check has no parameters."),
+                totext = "")
+    if not valuespec.title():
+        valuespec._title = _("Parameters")
+    elements.append(valuespec)
+
+    register_rule(
+        "static/" + subgroup, 
+        "static_checks:%s" % checkgroup,
+        title = title,
+        valuespec = Tuple(
+            title = valuespec.title(),
+            elements = elements,
+        ),
+        match = "all")
+
+    
+
+
+
 #
 # User profile edit page
 # The user can edit the own profile
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 5bbb432..08cbe12 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -144,7 +144,7 @@ register_rule(group + '/' + subgroup_applications,
 
 register_rule(group + '/' + subgroup_inventory,
     varname   = "inventory_services_rules",
-    title     = _('Windows Services'),
+    title     = _("Windows Service Inventory"),
     valuespec = Dictionary(
         elements = [
             ('services', ListOfStrings(
@@ -178,7 +178,7 @@ register_rule(group + '/' + subgroup_inventory,
 
 register_rule(group + '/' + subgroup_inventory,
     varname   = "inventory_processes_rules",
-    title     = _('Processes'),
+    title     = _('Process Inventory'),
     valuespec = Dictionary(
         elements = [
             ('descr', TextAscii(
@@ -2065,30 +2065,9 @@ checkgroups.append((
 
 # Create rules for check parameters of inventorized checks
 for subgroup, checkgroup, title, valuespec, itemspec, matchtype in checkgroups:
-    if not valuespec:
-        continue # would be useles rule if check has no parameters
-    itemenum = None
-    if itemspec:
-        itemtype = "item"
-        itemname = itemspec.title()
-        itemhelp = itemspec.help()
-        if isinstance(itemspec, DropdownChoice):
-            itemenum = itemspec._choices
-    else:
-        itemtype = None
-        itemname = None
-        itemhelp = None
-
-    register_rule(
-        group + "/" + subgroup,
-        varname = "checkgroup_parameters:%s" % checkgroup,
-        title = title,
-        valuespec = valuespec,
-        itemtype = itemtype, itemname = itemname,
-        itemhelp = itemhelp,
-        itemenum = itemenum,
-        match = matchtype)
+    register_check_parameters(subgroup, checkgroup, title, valuespec, itemspec, matchtype)
 
+checkgroups = []
 
 register_rule(
     group + "/" + subgroup_networking,
@@ -2103,7 +2082,7 @@ register_rule(
 # Create Rules for static checks
 register_rulegroup("static", _("Manual Checks"),
     _("Statically configured Check_MK checks that do not rely on the inventory"))
-group = "static"
+
 
 # wmic_process does not support inventory at the moment
 checkgroups.append((
@@ -2192,31 +2171,6 @@ checkgroups.append((
     "first"))
 
 
-
 for subgroup, checkgroup, title, valuespec, itemspec, matchtype in checkgroups:
-    elements = [
-        CheckTypeGroupSelection(
-            checkgroup,
-            title = _("Checktype"),
-            help = _("Please choose the check plugin")) ]
-    if itemspec:
-        elements.append(itemspec)
-    if not valuespec:
-        valuespec =\
-            FixedValue(None,
-                help = _("This check has no parameters."),
-                totext = "")
-    if not valuespec.title():
-        valuespec._title = _("Parameters")
-    elements.append(valuespec)
-
-    register_rule(
-        group + "/" + subgroup, 
-        "static_checks:%s" % checkgroup,
-        title = title,
-        valuespec = Tuple(
-            title = valuespec.title(),
-            elements = elements,
-        ),
-        match = "all")
+    register_check_parameters(subgroup, checkgroup, title, valuespec, itemspec, matchtype, False)
 



More information about the checkmk-commits mailing list