Module: check_mk
Branch: master
Commit: b9811fd1b46da123b8749aa878e2566333fd8735
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b9811fd1b46da1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 24 12:15:45 2015 +0100
#2156 Interface-Checks: Can now be configured to use predictive traffic levels
---
.werks/2156 | 9 +++++++++
ChangeLog | 1 +
checks/if.include | 46 ++++++++++++++++++++++++++--------------------
modules/check_mk_base.py | 11 ++++++++---
4 files changed, 44 insertions(+), 23 deletions(-)
diff --git a/.werks/2156 b/.werks/2156
new file mode 100644
index 0000000..0627f8f
--- /dev/null
+++ b/.werks/2156
@@ -0,0 +1,9 @@
+Title: Interface-Checks: Can now be configured to use predictive traffic levels
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i1
+Date: 1427195721
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 0716df1..2b2592d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -140,6 +140,7 @@
* 2154 Interface-Checks: Separate traffic thresholds for in and out are now
possible...
* 2155 siemens_plc_counter: added new check for monitoring increasing counter values
* 2106 aix_sap_processlist: new check and agent plugin to monitor the process list of
SAP Application Server Instances on AIX systems
+ * 2156 Interface-Checks: Can now be configured to use predictive traffic levels
* 1457 FIX: logins: new check renamed from "users" check...
NOTE: Please refer to the migration notes!
* 1762 FIX: lnx_thermal: Now ignoring trip points with level 0...
diff --git a/checks/if.include b/checks/if.include
index 3aefbca..d2e81bd 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -165,7 +165,13 @@ def if_get_traffic_levels(params):
def get_specific_traffic_levels(general_traffic_levels, unit, ref_speed,
assumed_speed_in, assumed_speed_out):
traffic_levels = {}
- for (traffic_dir, up_or_low), (level_type, (warn, crit)) in
general_traffic_levels.items():
+ for (traffic_dir, up_or_low), (level_type, levels) in
general_traffic_levels.items():
+ if type(levels) != tuple:
+ traffic_levels[(traffic_dir, 'predictive')] = levels
+ continue # don't convert predictive levels config
+ else:
+ warn, crit = levels
+
for what, level_value in [('warn', warn), ('crit', crit)]:
# If the measurement unit is set to bit and the bw levels
# are of type absolute, convert these 'bit' entries to byte
@@ -656,7 +662,7 @@ def check_if_common_single(item, params, info, force_counter_wrap =
False, has_n
if wrapped:
# If there is a threshold on the bandwidth, we cannot proceed
# further (the check would be flapping to green on a wrap)
- if bw_crit != None:
+ if any(traffic_levels.values()):
raise MKCounterWrapped("Counter wrap, skipping checks this
time")
perfdata = []
else:
@@ -674,10 +680,15 @@ def check_if_common_single(item, params, info, force_counter_wrap =
False, has_n
infotext += ", %s: %s" % (what, format_value(traffic))
- bw_warn = traffic_levels[(what, 'upper',
'warn')]
- bw_crit = traffic_levels[(what, 'upper',
'crit')]
- bw_warn_min = traffic_levels[(what, 'lower',
'warn')]
- bw_crit_min = traffic_levels[(what, 'lower',
'crit')]
+ if (what, 'predictive') in traffic_levels:
+ params = traffic_levels[(what, 'predictive')]
+ bw_warn, bw_crit = None, None
+ else:
+ bw_warn = traffic_levels[(what, 'upper',
'warn')]
+ bw_crit = traffic_levels[(what, 'upper',
'crit')]
+ bw_warn_min = traffic_levels[(what, 'lower',
'warn')]
+ bw_crit_min = traffic_levels[(what, 'lower',
'crit')]
+ params = (bw_warn, bw_crit, bw_warn_min, bw_crit_min)
if speed:
perc_used = 100.0 * traffic / speed
@@ -691,22 +702,17 @@ def check_if_common_single(item, params, info, force_counter_wrap =
False, has_n
if average:
traffic_avg = get_average("if.%s.%s.avg" % (what,
item), this_time, traffic, average)
infotext += ", %dmin avg: %s" % (average,
format_value(traffic_avg))
- perfdata.append( ("%s_avg_%d" % (what, average),
traffic_avg, bw_warn, bw_crit, 0, speed) )
+ dsname = "%s_avg_%d" % (what, average)
+ perfdata.append((dsname, traffic_avg, bw_warn, bw_crit, 0,
speed))
traffic = traffic_avg # apply levels to average traffic
+ else:
+ dsname = what
- # Check bandwidth thresholds
- if bw_crit != None and traffic >= bw_crit:
- state = 2
- infotext += ' (!!) >= ' + format_value(bw_crit)
- elif bw_warn != None and traffic >= bw_warn:
- state = max(state, 1)
- infotext += ' (!) >= ' + format_value(bw_warn)
- if bw_crit_min != None and traffic < bw_crit_min:
- state = 2
- infotext += ' (!!) < ' + format_value(bw_crit_min)
- elif bw_warn_min != None and traffic < bw_warn_min:
- state = max(state, 1)
- infotext += ' (!) >= ' + format_value(bw_warn_min)
+ # Check bandwidth thresholds incl. prediction
+ result = check_levels(traffic, dsname, params, statemarkers=True)
+ state = max(state, result[0])
+ infotext += result[1]
+ perfdata += result[2]
# check percentage of error packets
pacrate = urate + nurate + errorrate
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 4b0c130..7ac6737 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1793,18 +1793,23 @@ def regex(pattern):
def check_levels(value, dsname, params, unit="", factor=1.0, scale=1.0,
statemarkers=False):
if unit:
unit = " " + unit # Insert space before MB, GB, etc.
-
perfdata = []
infotexts = []
+ scale_value = lambda v: v != None and v * factor * scale or None
+
# None or (None, None) -> do not check any levels
if params == None or params == (None, None):
return 0, "", []
# Pair of numbers -> static levels
elif type(params) == tuple:
- warn_upper, crit_upper = params[0] * factor * scale, params[1] * factor * scale,
- warn_lower, crit_lower = None, None
+ if len(params) == 2: # upper warn and crit
+ warn_upper, crit_upper = scale_value(params[0]), scale_value(params[1])
+ warn_lower, crit_lower = None, None
+ else: # uppwer and lower warn and crit
+ warn_upper, crit_upper = scale_value(params[0]), scale_value(params[1])
+ warn_lower, crit_lower = scale_value(params[2]), scale_value(params[3])
ref_value = None
# Dictionary -> predictive levels