Module: check_mk
Branch: master
Commit: 1727cef7039a1472d48094a241d0606e8311190a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1727cef7039a14…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Jan 10 09:39:55 2018 +0100
5487 FIX isc_dhcpd: Resolve performance issues
Resolves performance issues which could lead to a timeout when a large amount
of pools and leases were present.
Change-Id: Iddcc108b4282baabcd6c42b6f3845e87127a3688
---
.werks/5487 | 11 +++++++++++
checks/isc_dhcpd | 40 +++++++++++++++++++---------------------
2 files changed, 30 insertions(+), 21 deletions(-)
diff --git a/.werks/5487 b/.werks/5487
new file mode 100644
index 0000000..93ac1fb
--- /dev/null
+++ b/.werks/5487
@@ -0,0 +1,11 @@
+Title: isc_dhcpd: Resolve performance issues
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i3
+Date: 1515573287
+Class: fix
+
+Resolves performance issues which could lead to a timeout when a large amount
+of pools and leases were present.
diff --git a/checks/isc_dhcpd b/checks/isc_dhcpd
index 2ebfe16..e20119a 100644
--- a/checks/isc_dhcpd
+++ b/checks/isc_dhcpd
@@ -46,10 +46,18 @@ isc_dhcpd_default_levels = (15.0, 5.0)
# 10.0.1.57
def parse_isc_dhcpd(info):
+ def ip_to_number(ip):
+ number = 0
+ factor = 1
+ for part in ip.split('.')[::-1]:
+ number += factor * int(part)
+ factor *= 256
+ return number
+
parsed = {
- "pids" : [],
- "pools" : [],
- "leases" : [],
+ "pids": [],
+ "pools": {},
+ "leases": [],
}
mode = None
@@ -66,10 +74,12 @@ def parse_isc_dhcpd(info):
parsed["pids"] = map(int, line[1:])
elif mode == "pools":
- parsed["pools"].append((line[0], line[1]))
+ start, end = line[0], line[1]
+ item = "%s-%s" % (start, end)
+ parsed["pools"][item] = (ip_to_number(start), ip_to_number(end))
elif mode == "leases":
- parsed["leases"].append(line[0])
+ parsed["leases"].append(ip_to_number(line[0]))
return parsed
@@ -89,8 +99,7 @@ def parse_isc_dhcpd(info):
def inventory_isc_dhcpd(parsed):
- return [ ("%s-%s" % pool, "isc_dhcpd_default_levels")
- for pool in parsed["pools"] ]
+ return [(item, "isc_dhcpd_default_levels") for item in
parsed["pools"]]
def check_isc_dhcpd(item, params, parsed):
@@ -100,24 +109,13 @@ def check_isc_dhcpd(item, params, parsed):
yield 1, "DHCP Daemon running %d times (PIDs: %s)" % (
len(parsed["pids"]), ", ".join(map(str,
parsed["pids"])))
- def ip_to_number(ip):
- number = 0
- factor = 1
- for part in ip.split('.')[::-1]:
- number += factor * int(part)
- factor *= 256
- return number
-
- pool = tuple(item.split("-"))
- if pool not in parsed["pools"]:
+ if item not in parsed["pools"]:
return
- range_from = ip_to_number(pool[0])
- range_to = ip_to_number(pool[1])
+ range_from, range_to = parsed["pools"][item]
num_leases = range_to - range_from + 1
num_used = 0
- for lease in parsed["leases"]:
- lease_dec = ip_to_number(lease)
+ for lease_dec in parsed["leases"]:
if lease_dec >= range_from and lease_dec <= range_to:
num_used += 1