Module: check_mk
Branch: master
Commit: 8dc7baadde11d0d8d07dc641a5f6366e58621359
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8dc7baadde11d0…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jul 27 11:56:22 2017 +0200
Use iterators for, well, iterating...
Going via lists is needlessly slow.
Change-Id: Ic50d797d184318681b9a1e9e3855d4cf57d5d999
---
bin/mkeventd | 45 ++++++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 23 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index 3798793..6fd3052 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -345,7 +345,7 @@ def match_ipv4_network(pattern, ipaddress_text):
# first network_bits of network and ipaddress must be
# identical. Create a bitmask.
bitmask = 0
- for n in range(32):
+ for n in xrange(32):
bitmask = bitmask << 1
if n < network_bits:
bit = 1
@@ -1179,7 +1179,7 @@ class Perfcounters(object):
duration = now - self._last_statistics
else:
duration = 0
- for name, value in self._counters.items():
+ for name, value in self._counters.iteritems():
if duration:
delta = value - self._old_counters[name]
rate = delta / duration
@@ -1212,7 +1212,7 @@ class Perfcounters(object):
with self._lock:
headers = []
row = []
- for name, value in self._counters.items():
+ for name, value in self._counters.iteritems():
rate_name = name.rstrip("s") + "_rate"
average_rate_name = "average_" + name.rstrip("s") + "_rate"
headers.append("status_" + name)
@@ -1222,7 +1222,7 @@ class Perfcounters(object):
row.append(self._rates.get(name, 0.0))
row.append(self._average_rates.get(name, 0.0))
- for name in self._weights.keys():
+ for name in self._weights.iterkeys():
headers.append("status_average_%s_time" % name)
row.append(self._times.get(name, 0.0))
@@ -1261,7 +1261,7 @@ class EventServer(object):
self._rules = []
self._hash_stats = []
- for _unused_facility in range(32):
+ for _unused_facility in xrange(32):
self._hash_stats.append([ 0 ] * 8 )
self.host_config = HostConfig()
@@ -1695,7 +1695,7 @@ class EventServer(object):
client_sockets[client_socket.fileno()] = (client_socket, address, "")
# Read data from existing event unix socket connections
- for fd, (cs, address, previous_data) in client_sockets.items():
+ for fd, (cs, address, previous_data) in client_sockets.iteritems():
if fd in readable:
# Receive next part of data
try:
@@ -2179,10 +2179,10 @@ class EventServer(object):
if g_config["rule_optimizer"]:
self.logger.info("Rule hash: %d rules - %d hashed, %d unspecific" %
(len(self._rules), len(self._rules) - count_unspecific, count_unspecific))
- for facility in range(32):
+ for facility in xrange(32):
if facility in self._rule_hash:
stats = []
- for prio, entries in self._rule_hash[facility].items():
+ for prio, entries in self._rule_hash[facility].iteritems():
stats.append("%s(%d)" % (syslog_priorities[prio], len(entries)))
if syslog_facilities[facility]:
self.logger.info(" %-12s: %s" % (syslog_facilities[facility], " ".join(stats)))
@@ -2194,7 +2194,7 @@ class EventServer(object):
if facility and not rule.get("invert_matching"):
self.hash_rule_facility(rule, facility)
else:
- for facility in range(32): # all syslog facilities
+ for facility in xrange(32): # all syslog facilities
self.hash_rule_facility(rule, facility)
@@ -2204,7 +2204,7 @@ class EventServer(object):
if key in rule:
prio_from, prio_to = rule[key]
# Beware: from > to!
- for p in range(prio_to, prio_from + 1):
+ for p in xrange(prio_to, prio_from + 1):
needed_prios[p] = True
elif key == "match_priority": # all priorities match
needed_prios = [True] * 8 # needed to check this rule for all event priorities
@@ -2223,8 +2223,8 @@ class EventServer(object):
self.logger.info("Top 20 of facility/priority:")
entries = []
total_count = 0
- for facility in range(32):
- for priority in range(8):
+ for facility in xrange(32):
+ for priority in xrange(8):
count = self._hash_stats[facility][priority]
if count:
total_count += count
@@ -2877,7 +2877,7 @@ class EventServer(object):
if g_config["debug_rules"]:
self.logger.info('Parsed message:\n' +
("".join([ " %-15s %s\n" % (k+":", v) for (k, v) in
- sorted(event.items())])).rstrip())
+ sorted(event.iteritems())])).rstrip())
return event
@@ -2899,7 +2899,7 @@ class EventServer(object):
def get_hosts_with_active_event_limit(self):
hosts = []
- for hostname, num_existing_events in g_event_status.num_existing_events_by_host.items():
+ for hostname, num_existing_events in g_event_status.num_existing_events_by_host.iteritems():
if num_existing_events >= g_config["event_limit"]["by_host"]["limit"]:
hosts.append(hostname)
return hosts
@@ -2907,7 +2907,7 @@ class EventServer(object):
def get_rules_with_active_event_limit(self):
rule_ids = []
- for rule_id, num_existing_events in g_event_status.num_existing_events_by_rule.items():
+ for rule_id, num_existing_events in g_event_status.num_existing_events_by_rule.iteritems():
if rule_id == None:
continue # Ignore rule unrelated overflow events. They have no rule id associated.
if num_existing_events >= g_config["event_limit"]["by_rule"]["limit"]:
@@ -4046,7 +4046,7 @@ class EventStatus(object):
def get_rule_stats(self):
- return [ e[0] for e in rule_columns ], sorted(self._rule_stats.items(), key=lambda x: x[0])
+ return [ e[0] for e in rule_columns ], sorted(self._rule_stats.iteritems(), key=lambda x: x[0])
#.
# .--Actions-------------------------------------------------------------.
@@ -4100,7 +4100,7 @@ def do_event_actions(actions, event, is_cancelling):
def get_quoted_event(event):
new_event = {}
fields_to_quote = [ "application", "match_groups", "text", "comment", "contact" ]
- for key, value in event.items():
+ for key, value in event.iteritems():
if key not in fields_to_quote:
new_event[key] = value
else:
@@ -4175,7 +4175,7 @@ def get_event_tags(event):
def substitute_event_tags(text, event):
- for key, value in get_event_tags(event).items():
+ for key, value in get_event_tags(event).iteritems():
text = text.replace('$%s$' % key.upper(), value)
return text
@@ -4213,7 +4213,7 @@ def send_email(to, subject, body):
def execute_script(body, event):
script_env = os.environ.copy()
- for key, value in get_event_tags(event).items():
+ for key, value in get_event_tags(event).iteritems():
if type(key) == unicode:
key = key.encode("utf-8")
if type(value) == unicode:
@@ -4264,7 +4264,7 @@ def do_notify(event, username=None, is_cancelling=False):
if logger.is_verbose():
logger.verbose("Sending notification via Check_MK with the following context:")
- for varname, value in sorted(context.items()):
+ for varname, value in sorted(context.iteritems()):
logger.verbose(" %-25s: %s" % (varname, value))
if context["HOSTDOWNTIME"] != "0":
@@ -4277,8 +4277,7 @@ def do_notify(event, username=None, is_cancelling=False):
# Send notification context via stdin.
context_string = to_utf8("".join([
"%s=%s\n" % (varname, value.replace("\n", "\\n"))
- for (varname, value)
- in context.items() ]))
+ for (varname, value) in context.iteritems() ]))
p = subprocess.Popen(["cmk", "--notify", "stdin"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
@@ -4345,7 +4344,7 @@ def add_infos_from_monitoring_host(context, event):
})
# Add custom variables to the notification context
- for key, val in host_config["custom_variables"].items():
+ for key, val in host_config["custom_variables"].iteritems():
context["HOST_%s" % key] = val
context["HOSTDOWNTIME"] = "1" if event["host_in_downtime"] else "0"
Module: check_mk
Branch: master
Commit: a436adc5f54eb42c9286ee834ee1f13847b8c01d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a436adc5f54eb4…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jul 27 10:39:50 2017 +0200
2to3 (except fix): Use modern exception target separator.
Syntax history:
* Only ",": Up to and including Python 2.6 (Oct 2008)
* Both "," and "as": From 2.6.1 (Dec 2008) up to current 2.7.13
* Only "as": From 3.0 (Dec 2008) onwards
We choose "as", it works on everything from Dec 2008 onwards.
Change-Id: I5e71cb8874c14b34fd738a3f2f0a52a6328db062
---
bin/mkeventd | 58 +++++++++++++++++++++++++++++-----------------------------
1 file changed, 29 insertions(+), 29 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=a436adc5f5…
Module: check_mk
Branch: master
Commit: 6b39629ee405c1b23529b53aa57239d2e4adb9d0
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6b39629ee405c1…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jul 27 13:17:40 2017 +0200
Added a TODO.
Change-Id: I69fab477abeefab6c5832834502f51cfa63bfd99
---
bin/mkeventd | 3 +++
1 file changed, 3 insertions(+)
diff --git a/bin/mkeventd b/bin/mkeventd
index 6fd3052..ba03ada 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -3508,6 +3508,9 @@ class StatusServer(object):
return rows
def filter_row(self, headers, filters, list_row):
+ # TODO(sp) This is a real performance killer: We should just calculate
+ # the column indices for column names *once*, not doing some dict/list
+ # Kung Fu for every row...
row = dict(zip(headers, list_row))
for column, opfunc, argument in filters:
if not opfunc(row[column], argument):
Module: check_mk
Branch: master
Commit: 30b44903f06cb4cd9e26c537362bc43650c10d1a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=30b44903f06cb4…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jul 27 15:06:00 2017 +0200
2to3 (idioms fix): Directly use 'sorted'.
Change-Id: I59dcf94a8b66ee1054e11a728883912b56457a4b
---
bin/mkeventd | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index b7f28a9..2467f42 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -940,9 +940,9 @@ def get_logfile(basename):
if active_history_period == None or timestamp > active_history_period:
# Look if newer files exist
- timestamps = [ int(f[:-4]) for f in os.listdir(log_dir) \
- if f.endswith(".log") ]
- timestamps.sort()
+ timestamps = sorted(int(f[:-4])
+ for f in os.listdir(log_dir)
+ if f.endswith(".log"))
if len(timestamps) > 0:
timestamp = max(timestamps[-1], timestamp)
@@ -1032,9 +1032,6 @@ def get_event_history_from_file(filters, limit):
# the first entry and modification time of the file. Only
# if at least one of both timestamps is accepted then we
# take that file into account.
- timestamps = [ int(fn[:-4]) for fn in os.listdir(log_dir)
- if fn.endswith(".log") ]
- timestamps.sort()
# Use the later logfiles first, to get the newer log entries
# first. When a limit is reached, the newer entries should
# be processed in most cases. We assume that now.
@@ -1043,7 +1040,10 @@ def get_event_history_from_file(filters, limit):
# already be done by the GUI, so we don't do that twice. Skipping
# this # will lead into some lines of a single file to be limited in
# wrong order. But this should be better than before.
- timestamps.reverse()
+ timestamps = sorted((int(fn[:-4])
+ for fn in os.listdir(log_dir)
+ if fn.endswith(".log")),
+ reverse=True)
for ts in timestamps:
if limit != None and limit <= 0:
break
Module: check_mk
Branch: master
Commit: 31ab4037f24274599aa91399a627daff3ec8ccf1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=31ab4037f24274…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jul 27 13:49:53 2017 +0200
make dist also builds livestatus tgz
Change-Id: Ic9b143a8c30e7b442130f3862a1639f3eb5aca0a
---
Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 44d12d6..002ec10 100644
--- a/Makefile
+++ b/Makefile
@@ -144,7 +144,7 @@ PNG_FILES := $(wildcard $(addsuffix /*.png,web/htdocs/images web/htdocs
help:
@echo "setup --> Prepare system for development and building"
- @echo "make dist --> Create source tgz for later building of rpm/deb"
+ @echo "make dist --> Create source tgz for later building of rpm/deb and livestatus tgz"
@echo "make rpm --> Create rpm package"
@echo "make deb --> Create deb package"
@echo "make cma --> Create cma package"
@@ -188,7 +188,7 @@ check-version:
# Would use --exclude-vcs-ignores but that's available from tar 1.29 which
# is currently not used by most distros
-dist:
+dist: mk-livestatus-$(VERSION).tar.gz
@EXCLUDES= ; \
if [ -d .git ]; then \
git rev-parse --short HEAD > COMMIT ; \