[checkmk-commits] Check_MK Git: check_mk: New check sap.value_groups

Bastian Kuhn bk at mathias-kettner.de
Mon Aug 11 16:05:33 CEST 2014


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

Author: Bastian Kuhn <bk at mathias-kettner.de>
Date:   Mon Aug 11 16:04:43 2014 +0200

New check sap.value_groups

---

 checkman/sap.value_groups            |   20 +++++++++
 checks/sap                           |   78 +++++++++++++++++++++++++++++++++-
 web/plugins/wato/check_parameters.py |   31 ++++++++++++++
 3 files changed, 128 insertions(+), 1 deletion(-)

diff --git a/checkman/sap.value_groups b/checkman/sap.value_groups
new file mode 100644
index 0000000..f7d39ca
--- /dev/null
+++ b/checkman/sap.value_groups
@@ -0,0 +1,20 @@
+title: SAP Single Value Monitoring Groups
+agents: linux
+catalog: app/sap
+license: GPL
+distribution: check_mk
+description:
+ Please refer to  {sap.value} for details.
+ This check is only a subchecks who enables you to create Groups of values.
+ 
+ The rule "SAP R/3 Single Value Inventory" is not necessary for that, you
+ only need the rule "SAP Value Grouping Patterns" to define a name and an include 
+ nor and exclusion list. 
+ After the service detection, the check will display the total number of OK and Critical values,
+ in case of Critical values also these.
+
+item:
+  The Name of the Group
+
+inventory:
+ The check does not inventory all available values by default. 
diff --git a/checks/sap b/checks/sap
index 5af2b49..8ee8f3b 100644
--- a/checks/sap
+++ b/checks/sap
@@ -78,7 +78,7 @@ check_info['sap.dialog'] = {
 # at the moment the following parameters are supported:
 # 1. match: the sap-path matching definition
 inventory_sap_values = []
-
+sap_value_groups = []
 def inventory_sap_value(info):
     inv = []
 
@@ -157,3 +157,79 @@ check_info['sap.value'] = {
     "service_description" : "%s",
     "has_perfdata"        : True,
 }
+
+def sap_value_groups_precompile(hostname, item, _unused):
+    return host_extra_conf(hostname, sap_value_groups)
+
+def sap_groups_of_value( value_name, patterns=False ):
+    groups = []
+    if not patterns:
+        patterns = host_extra_conf(g_hostname, sap_value_groups)
+
+    for line in patterns:
+        for group_name, pattern in line:
+            no_match = False
+            inclusion, exclusion = pattern
+            # Exclude:
+            if exclusion:
+                reg = compiled_regexes.get(exclusion)
+                if not reg:
+                    reg = re.compile(exclusion)
+                    compiled_regexes[exclusion] = reg
+                if reg.match(value_name):
+                    no_match = True
+                    break
+            #no match for this group, go on with the next group
+            if no_match:
+                break
+
+            # Include
+            reg = compiled_regexes.get(inclusion)
+            if not reg:
+                reg = re.compile(inclusion)
+                compiled_regexes[inclusion] = reg
+            if reg.match(value_name):
+                groups.append(group_name)
+    return groups
+
+def inventory_sap_value_groups( info ):
+    inventory = []
+    found_groups = []
+    for line in info:
+        path = line[3]
+        for group in sap_groups_of_value( path ):
+            if group not in found_groups:
+                inventory.append(( group, None ))
+                found_groups.append(group)
+    return inventory
+
+def check_sap_value_groups( item, params, info ):
+    frontend = []
+    backend = []
+    count_ok = 0
+    count_crit = 0
+    state = 0
+    for line in info:
+        path = line[3]
+        if item in sap_groups_of_value( path, params ):
+            status = sap_nagios_state_map[int(line[1])]
+            output = ''
+            if line[4] == '-':
+                output  = ' '.join(line[6:])
+            backend.append( path + output + " "  + nagios_state_names[status] )
+            state = max(state, status)
+            if status > 0:
+                count_crit += 1
+                frontend.append( path + output + " "  + nagios_state_names[status] )
+            else:
+                count_ok += 1
+
+    return state, "%s OK, %s Crit %s\n%s" % ( count_ok, count_crit, ", ".join(frontend), "\n".join(backend) )
+
+
+check_info['sap.value-groups'] = {
+    'check_function':      check_sap_value_groups,
+    'inventory_function':  inventory_sap_value_groups,
+    'service_description': "%s",
+}
+precompile_params['sap.value-groups'] = sap_value_groups_precompile
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 6036366..82c660a 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -476,6 +476,37 @@ register_rule(group + '/' + subgroup_inventory,
 )
 
 register_rule(group + '/' + subgroup_inventory,
+    varname   = "sap_value_groups",
+    title     = _('SAP Value Grouping Patterns'),
+    help      = _('The check <tt>sap.value</tt> normaly creates one service for each sap value '
+                  'By defining grouping patterns you can switch to the check <tt>sap.value-groups</tt>. '
+                  'That check monitors a list of SAP values at once. This is usefull if you have '
+                  'a very big list of values which do you want to monitor'),
+    valuespec = ListOf(
+        Tuple(
+            help = _("This defines one value grouping pattern"),
+            show_titles = True,
+            orientation = "horizontal",
+            elements = [
+                TextAscii(
+                     title = _("Name of group"),
+                ),
+                Tuple(
+                    show_titles = True,
+                    orientation = "vertical",
+                    elements = [
+                        RegExpUnicode(title = _("Include Pattern")),
+                        RegExpUnicode(title = _("Exclude Pattern"))
+                    ],
+                ),
+            ],
+        ),
+        add_label = _("Add pattern group"),
+    ),
+    match = 'all',
+)
+
+register_rule(group + '/' + subgroup_inventory,
     varname   = "inventory_heartbeat_crm_rules",
     title     = _("Heartbeat CRM Inventory"),
     valuespec = Dictionary(



More information about the checkmk-commits mailing list