[checkmk-commits] Check_MK Git: check_mk: Made mib translation configurable

Lars Michelsen lm at mathias-kettner.de
Wed Apr 29 13:48:09 CEST 2015


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

Author: Lars Michelsen <lm at mathias-kettner.de>
Date:   Wed Apr 29 13:42:43 2015 +0200

Made mib translation configurable

---

 mkeventd/bin/mkeventd                 |   57 +++++++++++++++++++++++----------
 mkeventd/web/plugins/wato/mkeventd.py |   14 ++++++--
 2 files changed, 52 insertions(+), 19 deletions(-)

diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 07975bb..635d2a0 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -1150,6 +1150,22 @@ class EventServer:
 
         return os.open(g_pipe_path, os.O_RDWR | os.O_NONBLOCK)
 
+    def load_mibs(self):
+        builder = MibBuilder() # manages python MIB modules
+
+        # load MIBs from our compiled MIB and default MIB paths
+        builder.setMibSources(*[DirMibSource(g_compiled_mibs_dir)]
+                               + list(builder.getMibSources()))
+
+        # Indicate we wish to load DESCRIPTION and other texts from MIBs
+        builder.loadTexts = True
+
+        # This loads all or specified pysnmp MIBs into memory
+        builder.loadModules()
+
+        # This object maintains various indices built from MIBs data
+        self._mib_resolver = MibViewController(builder)
+
     # Format time difference seconds into approximated
     # human readable value
     def fmt_timeticks(self, ticks):
@@ -1168,26 +1184,28 @@ class EventServer:
         days, hours = divmod(hours, 24)
         return "%d days, %d hours, %d min" % (days, hours, mins)
 
+    # Convert pysnmp datatypes to simply handable ones
+    def snmptrap_convert_var_binds(self, var_bind_list):
+        var_binds = []
+        for oid, value in var_bind_list:
+            key = str(oid)
 
-    def load_mibs(self):
-        builder = MibBuilder() # manages python MIB modules
-
-        # load MIBs from our compiled MIB and default MIB paths
-        builder.setMibSources(*[DirMibSource(g_compiled_mibs_dir)]
-                               + list(builder.getMibSources()))
-
-        # Indicate we wish to load DESCRIPTION and other texts from MIBs
-        builder.loadTexts = True
-
-        # This loads all or specified pysnmp MIBs into memory
-        builder.loadModules()
+            if value.__class__.__name__ == 'ObjectIdentifier':
+                val = str(value)
+            elif value.__class__.__name__ == 'TimeTicks':
+                val = self.fmt_timeticks(value._value)
+            else:
+                val = value._value
 
-        # This object maintains various indices built from MIBs data
-        self._mib_resolver = MibViewController(builder)
+            # Translate some standard SNMPv2 oids
+            if key == '1.3.6.1.2.1.1.3.0':
+                key = 'Uptime'
 
+            var_binds.append((key, val))
+        return var_binds
 
     # Convert pysnmp datatypes to simply handable ones
-    def snmptrap_convert_var_binds(self, var_bind_list):
+    def snmptrap_translate_varbinds(self, var_bind_list):
         var_binds = []
         for oid, value in var_bind_list:
             mib_var = MibVariable(oid).resolveWithMib(self._mib_resolver)
@@ -1240,7 +1258,11 @@ class EventServer:
             else:
                 break # Skip unhandled version
 
-            trap = self.snmptrap_convert_var_binds(proto.apiPDU.getVarBinds(pdu))
+            if g_config['translate_snmptraps']:
+                trap = self.snmptrap_translate_varbinds(proto.apiPDU.getVarBinds(pdu))
+            else:
+                trap = self.snmptrap_convert_var_binds(proto.apiPDU.getVarBinds(pdu))
+
             # Use the trap sender IP address as host name
             host = ipaddress
 
@@ -3514,6 +3536,7 @@ def load_configuration():
         "hostname_translation"  : {},
         "archive_orphans"       : False,
         "archive_mode"          : "file",
+        "translate_snmptraps"   : False,
     }
     main_file = g_config_dir + "/mkeventd.mk"
     if not os.path.exists(main_file):
@@ -3778,7 +3801,7 @@ try:
     g_event_status.load_status()
     g_status_server = StatusServer()
     g_event_server  = EventServer()
-    if opt_snmptrap:
+    if opt_snmptrap and g_config['translate_snmptraps']:
         g_event_server.load_mibs()
     g_event_server.compile_rules(g_config["rules"])
 
diff --git a/mkeventd/web/plugins/wato/mkeventd.py b/mkeventd/web/plugins/wato/mkeventd.py
index a337f81..37d1620 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -1894,8 +1894,6 @@ if mkeventd_enabled:
         domain = "mkeventd",
     )
 
-
-
     register_configvar(group,
         "retention_interval",
         Age(title = _("State Retention Interval"),
@@ -2079,6 +2077,18 @@ if mkeventd_enabled:
         domain = "mkeventd",
     )
 
+    register_configvar(group,
+        "translate_snmptraps",
+        Checkbox(title = _("Translate SNMP traps"),
+                 label = _("Use the available SNMP MIBs to translate contents of the SNMP traps"),
+                 help = _("When this option is enabled all available SNMP MIB files will be used "
+                          "to translate the incoming SNMP traps. Information which can not be "
+                          "translated, e.g. because a MIB is missing, are written untouched to "
+                          "the event message."),
+                 default_value = False),
+        domain = "mkeventd",
+    )
+
     # A few settings for Multisite and WATO
     register_configvar(_("Status GUI (Multisite)"),
         "mkeventd_connect_timeout",



More information about the checkmk-commits mailing list