Module: check_mk
Branch: master
Commit: 951c829fedc608a5a94efe3dfe713e1e4c99856c
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=951c829fedc608…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 2 13:12:44 2013 +0200
small system call improvement when processing stored walks; removed old stored walk processing code
---
modules/snmp.py | 174 +++++++++++++++++++++++--------------------------------
1 file changed, 74 insertions(+), 100 deletions(-)
diff --git a/modules/snmp.py b/modules/snmp.py
index bbc75c7..f938add 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -335,119 +335,93 @@ def get_stored_snmpwalk(hostname, oid):
if opt_debug:
sys.stderr.write("Getting %s from %s\n" % (oid, path))
- if not os.path.exists(path):
- raise MKGeneralException("No snmpwalk file %s\n" % path)
rowinfo = []
- use_new = True
- if use_new:
- # New implementation: use binary search
- def to_bin_string(oid):
- try:
- return tuple(map(int, oid.strip(".").split(".")))
- except:
- raise MKGeneralException("Invalid OID %s" % oid)
-
- def compare_oids(a, b):
- aa = to_bin_string(a)
- bb = to_bin_string(b)
- if len(aa) <= len(bb) and bb[:len(aa)] == aa:
- result = 0
- else:
- result = cmp(aa, bb)
- return result
-
- if hostname in g_walk_cache:
- lines = g_walk_cache[hostname]
+ # New implementation: use binary search
+ def to_bin_string(oid):
+ try:
+ return tuple(map(int, oid.strip(".").split(".")))
+ except:
+ raise MKGeneralException("Invalid OID %s" % oid)
+
+ def compare_oids(a, b):
+ aa = to_bin_string(a)
+ bb = to_bin_string(b)
+ if len(aa) <= len(bb) and bb[:len(aa)] == aa:
+ result = 0
else:
+ result = cmp(aa, bb)
+ return result
+
+ if hostname in g_walk_cache:
+ lines = g_walk_cache[hostname]
+ else:
+ try:
lines = file(path).readlines()
- g_walk_cache[hostname] = lines
-
- begin = 0
- end = len(lines)
- hit = None
- while end - begin > 0:
- current = (begin + end) / 2
- parts = lines[current].split(None, 1)
- comp = parts[0]
- hit = compare_oids(oid_prefix, comp)
- if hit == 0:
- break
- elif hit == 1: # we are too low
- begin = current + 1
- else:
- end = current
+ except IOError:
+ raise MKGeneralException("No snmpwalk file %s\n" % path)
+ g_walk_cache[hostname] = lines
+
+ begin = 0
+ end = len(lines)
+ hit = None
+ while end - begin > 0:
+ current = (begin + end) / 2
+ parts = lines[current].split(None, 1)
+ comp = parts[0]
+ hit = compare_oids(oid_prefix, comp)
+ if hit == 0:
+ break
+ elif hit == 1: # we are too low
+ begin = current + 1
+ else:
+ end = current
- if hit != 0:
- return [] # not found
+ if hit != 0:
+ return [] # not found
- def collect_until(index, direction):
- rows = []
- # Handle case, where we run after the end of the lines list
- if index >= len(lines):
- if direction > 0:
- return []
- else:
- index -= 1
- while True:
- line = lines[index]
- parts = line.split(None, 1)
- o = parts[0]
- if o.startswith('.'):
- o = o[1:]
- if o == oid or o.startswith(oid_prefix + "."):
- if len(parts) > 1:
- value = parts[1]
- if agent_simulator:
- value = agent_simulator_process(value)
- else:
- value = ""
- # Fix for missing starting oids
- rows.append(('.'+o, strip_snmp_value(value)))
- index += direction
- if index < 0 or index >= len(lines):
- break
+ def collect_until(index, direction):
+ rows = []
+ # Handle case, where we run after the end of the lines list
+ if index >= len(lines):
+ if direction > 0:
+ return []
+ else:
+ index -= 1
+ while True:
+ line = lines[index]
+ parts = line.split(None, 1)
+ o = parts[0]
+ if o.startswith('.'):
+ o = o[1:]
+ if o == oid or o.startswith(oid_prefix + "."):
+ if len(parts) > 1:
+ value = parts[1]
+ if agent_simulator:
+ value = agent_simulator_process(value)
else:
+ value = ""
+ # Fix for missing starting oids
+ rows.append(('.'+o, strip_snmp_value(value)))
+ index += direction
+ if index < 0 or index >= len(lines):
break
- return rows
-
-
- rowinfo = collect_until(current, -1)
- rowinfo.reverse()
- rowinfo += collect_until(current + 1, 1)
- # import pprint ; pprint.pprint(rowinfo)
-
- if dot_star:
- return [ rowinfo[0] ]
- else:
- return rowinfo
-
-
-
- # Old implementation
- hot = False
- for line in file(path):
- parts = line.split(None, 1)
- o = parts[0]
- if o.startswith('.'):
- o = o[1:]
- if o == oid or o.startswith(oid_prefix + "."):
- hot = True
- if len(parts) > 1:
- value = parts[1]
- if agent_simulator:
- value = agent_simulator_process(value)
else:
- value = ""
- rowinfo.append((o, strip_snmp_value(value))) # return pair of OID and value
- if dot_star:
break
- elif hot: # end of interesting part, no point in further search
- break
+ return rows
+
+
+ rowinfo = collect_until(current, -1)
+ rowinfo.reverse()
+ rowinfo += collect_until(current + 1, 1)
# import pprint ; pprint.pprint(rowinfo)
- return rowinfo
+
+ if dot_star:
+ return [ rowinfo[0] ]
+ else:
+ return rowinfo
# Helper function to be used in checks. It applies a user-specified
# character encoding in order to tranlate e.g. latin1 to utf8
Module: check_mk
Branch: master
Commit: 5177eb0cd6192fe6d365f7b96f9ba75705de8096
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5177eb0cd6192f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 2 14:57:17 2013 +0200
localize: Using .po from regular hierarchy if no file exists in local-hierarchy
---
modules/localize.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/modules/localize.py b/modules/localize.py
index f32130f..9ec0691 100644
--- a/modules/localize.py
+++ b/modules/localize.py
@@ -245,6 +245,14 @@ def localize_update(lang):
except:
pass
+ # Maybe initialize the file in the local hierarchy with the file in
+ # the default hierarchy
+ if local_locale_dir and not os.path.exists(po_file) \
+ and os.path.exists(locale_dir + '/%s/LC_MESSAGES/%s.po' % (lang, domain)):
+ file(po_file, 'w').write(file(locale_dir + '/%s/LC_MESSAGES/%s.po' % (lang, domain)).read())
+
+ sys.exit(1)
+
localize_sniff()
if not os.path.exists(po_file):
@@ -263,6 +271,12 @@ def localize_compile(lang):
init_files(lang)
+ # Maybe initialize the file in the local hierarchy with the file in
+ # the default hierarchy
+ if local_locale_dir and not os.path.exists(po_file) \
+ and os.path.exists(locale_dir + '/%s/LC_MESSAGES/%s.po' % (lang, domain)):
+ file(po_file, 'w').write(file(locale_dir + '/%s/LC_MESSAGES/%s.po' % (lang, domain)).read())
+
if not os.path.exists(po_file):
raise LocalizeException('The .po file %s does not exist.' % po_file)
hostname also when cancelling events
Message-ID: <51fa6993.4G0e07dt7brUrh/r%mk(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: b38d65cff909b0deea5daaae311fe83b885c35fa
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b38d65cff909b0…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Aug 1 15:57:08 2013 +0200
FIX: apply rewriting of application/hostname also when cancelling events
Conflicts:
mkeventd/bin/mkeventd
---
ChangeLog | 3 +++
mkeventd/bin/mkeventd | 30 +++++++++++++++++++++---------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f9497af..58a1c7f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -295,6 +295,9 @@
* FIX: fix logwatch pattern analyzer message "The host xyz is not
managed by WATO." after direct access via snapin
+ Event Console:
+ * FIX: apply rewriting of application/hostname also when cancelling events
+
1.2.2p2:
Core:
* FIX: livecheck: fixed handling of one-line plugin outputs and missing \n
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index aedf770..6887e21 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -1487,7 +1487,7 @@ class EventServer:
return
if cancelling:
- g_event_status.cancel_events(event, groups, rule["id"])
+ g_event_status.cancel_events(event, groups, rule)
return
else:
@@ -2467,29 +2467,41 @@ class EventStatus():
# Cancel all events the belong to a certain rule id and are
# of the same "breed" as a new event.
- def cancel_events(self, new_event, match_groups, rule_id):
+ def cancel_events(self, new_event, match_groups, rule):
with lock_eventstatus:
to_delete = []
for nr, event in enumerate(self._events):
- if event["rule_id"] == rule_id:
- if self.cancelling_match(match_groups, new_event, event):
+ if event["rule_id"] == rule["id"]:
+ if self.cancelling_match(match_groups, new_event, event, rule):
log_event_history(event, "CANCELLED")
to_delete.append(nr)
for nr in to_delete[::-1]:
del self._events[nr]
- def cancelling_match(self, match_groups, new_event, event):
+ def cancelling_match(self, match_groups, new_event, event, rule):
debug = g_config["debug_rules"]
- if event["host"] != new_event["host"]:
+
+ # Note: before we compare host and application we need to
+ # apply the rewrite rules to the event. Because if in the previous
+ # the hostname was rewritten, it wouldn't match anymore here.
+ host = new_event["host"]
+ if "set_host" in rule:
+ host = replace_groups(rule["set_host"], host, match_groups)
+
+ if event["host"] != host:
if debug:
log("Do not cancel event %d: host is not the same (%s != %s)" %
- (event["id"], event["host"], new_event["host"]))
+ (event["id"], event["host"], host))
return False
- if event["application"] != new_event["application"]:
+ # The same for the application
+ application = new_event["application"]
+ if "set_application" in rule:
+ application = replace_groups(rule["set_application"], application, match_groups)
+ if event["application"] != application:
if debug:
log("Do not cancel event %d: application is not the same (%s != %s)" %
- (event["id"], event["application"], new_event["application"]))
+ (event["id"], event["application"], application))
return False
if event["facility"] != new_event["facility"]: