Module: check_mk
Branch: master
Commit: bb90da777d55cab92fa4f787fbe354a09ae8e36f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bb90da777d55ca…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 10 08:37:44 2015 +0200
#2562 SNMP trap translation can now be configured to put trap description into event text
The trap translation was only translating keys, values and units of OIDs provided with a
trap.
You can now configure the Event Console to append the description of the OIDs (if
available
via the MIB) to the event texts.
To make this work you may need to re-upload your MIB files you want to have a translation
for.
This translation option can be enabled using the global settings of the Event Console.
Please
note that if you have existing rules to machting SNMP traps and you change this option,
the
texts of incoming events will change. So you might have to adapt your events text
matching
patterns.
---
.werks/2562 | 18 ++++++++++++++++++
ChangeLog | 1 +
mkeventd/bin/mkeventd | 22 +++++++++++++++++-----
mkeventd/web/plugins/wato/mkeventd.py | 33 +++++++++++++++++++++++++--------
4 files changed, 61 insertions(+), 13 deletions(-)
diff --git a/.werks/2562 b/.werks/2562
new file mode 100644
index 0000000..f5779e5
--- /dev/null
+++ b/.werks/2562
@@ -0,0 +1,18 @@
+Title: SNMP trap translation can now be configured to put trap description into event
text
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.7i3
+Date: 1441866846
+Class: feature
+
+The trap translation was only translating keys, values and units of OIDs provided with a
trap.
+You can now configure the Event Console to append the description of the OIDs (if
available
+via the MIB) to the event texts.
+
+To make this work you may need to re-upload your MIB files you want to have a translation
for.
+
+This translation option can be enabled using the global settings of the Event Console.
Please
+note that if you have existing rules to machting SNMP traps and you change this option,
the
+texts of incoming events will change. So you might have to adapt your events text
matching
+patterns.
diff --git a/ChangeLog b/ChangeLog
index fa16bb5..61ba267 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -264,6 +264,7 @@
* 2411 Check check_mkevents: Now able to look for events matching the host alias...
* 2533 Allow inverted match in Event Console rules
* 2508 It is now possible to upload multiple zipped MIB files at once...
+ * 2562 SNMP trap translation can now be configured to put trap description into event
text...
* 2322 FIX: mkeventd: MIBs are now only loaded if SNMP Traps translation is
activated...
* 2460 FIX: Slightly more robust SNMP trap translation...
* 2534 FIX: Fixed implementation of skipping rule packs
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index c01e81b..3794562 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -1235,9 +1235,16 @@ class EventServer:
value = node.getSyntax().clone(value)
units = node.getUnits()
- var_binds.append((translated_oid, value.prettyPrint() + ' ' +
units))
+ translated_value = value.prettyPrint() + ' ' + units
else:
- var_binds.append((translated_oid, value))
+ translated_value = value
+
+ if hasattr(node, "getDescription") \
+ and type(g_config["translate_snmptraps"]) == tuple \
+ and "add_description" in
g_config["translate_snmptraps"][1]:
+ translated_value += "(%s)" % node.getDescription()
+
+ var_binds.append((translated_oid, translated_value))
return var_binds
def process_snmptrap(self, (whole_msg, (ipaddress, port))):
@@ -1265,7 +1272,7 @@ class EventServer:
else:
break # Skip unhandled version
- if g_config['translate_snmptraps']:
+ if snmptrap_translation_enabled():
trap = self.snmptrap_translate_varbinds(proto.apiPDU.getVarBinds(pdu))
else:
trap = self.snmptrap_convert_var_binds(proto.apiPDU.getVarBinds(pdu))
@@ -2639,7 +2646,7 @@ class StatusServer:
def handle_command_reload(self):
with lock_configuration:
load_configuration()
- if opt_snmptrap and g_config['translate_snmptraps']:
+ if opt_snmptrap and snmptrap_translation_enabled():
g_event_server.load_mibs()
g_event_server.compile_rules(g_config["rules"],
g_config["rule_packs"])
g_status_server.reload_configuration()
@@ -3596,6 +3603,7 @@ def load_slave_status():
# +----------------------------------------------------------------------+
# | Loading of the configuration files |
# '----------------------------------------------------------------------'
+
def load_configuration():
global g_config, g_last_config_reload
g_config = {
@@ -3653,6 +3661,10 @@ def load_configuration():
g_last_config_reload = time.time()
+def snmptrap_translation_enabled():
+ return g_config["translate_snmptraps"] != False
+
+
#.
# .--Help & Usage--------------------------------------------------------.
# | _ _ _ ___ _ _ |
@@ -3883,7 +3895,7 @@ try:
g_event_status.load_status()
g_status_server = StatusServer()
g_event_server = EventServer()
- if opt_snmptrap and g_config['translate_snmptraps']:
+ if opt_snmptrap and snmptrap_translation_enabled():
g_event_server.load_mibs()
g_event_server.compile_rules(g_config["rules"],
g_config["rule_packs"])
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index f2c0e28..22e6ab6 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -1994,7 +1994,7 @@ def validate_and_compile_mib(mibname, content):
if not content.strip():
raise Exception(_("The file is empty"))
- results = compiler.compile(mibname, ignoreErrors=True)
+ results = compiler.compile(mibname, ignoreErrors=True, genTexts=True)
errors = []
for name, state in sorted(results.items()):
@@ -2498,13 +2498,30 @@ if mkeventd_enabled:
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),
+ Transform(
+ CascadingDropdown(
+ choices = [
+ (False, _("Do not translate SNMP traps")),
+ (True, _("Translate SNMP traps using the available
MIBs"),
+ Dictionary(
+ elements = [
+ ("add_description", FixedValue(True,
+ title = _("Add OID descriptions"),
+ totext = _("Append descriptions of OIDs to
message texts"),
+ )),
+ ],
+ ),
+ ),
+ ],
+ ),
+ 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."),
+ forth = lambda v: v == True and (v, {}) or v,
+ ),
domain = "mkeventd",
)