Module: check_mk
Branch: master
Commit: 05c534dc85d53ebd207aa4a6b4c660049c0cbb83
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=05c534dc85d53e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 9 14:35:20 2013 +0200
Implemented snmp_check_interval variable to customize intervals of snmp based checks
---
ChangeLog | 2 +
modules/automation.py | 1 +
modules/check_mk.py | 30 +++++++++++++++++++++++++--
modules/check_mk_base.py | 14 +++++++++++++
web/plugins/wato/check_mk_configuration.py | 30 ++++++++++++++++++++++++++-
5 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a7deb2c..375c7de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@
used by the vSphere and SAP plugins
* New variable host_check_commands, that allows the definition of
an alternative host check command (without manually defining one)
+ * New variable snmp_check_interval which can be used to customize
+ the check intervals of SNMP based checks
Multisite:
* New availability view for arbitrary host/service collections
diff --git a/modules/automation.py b/modules/automation.py
index 1994de8..3a2ce91 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -540,6 +540,7 @@ def automation_get_check_information():
checks[check_type] = { "title" : title }
if check["group"]:
checks[check_type]["group"] = check["group"]
+ checks[check_type]["snmp"] = check_uses_snmp(check_type)
return checks
def automation_scan_parents(args):
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 403001f..e07ad46 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -323,7 +323,7 @@ host_attributes = {} # needed by WATO, ignored by
Check_MK
ping_levels = [] # special parameters for host/PING
check_command
host_check_commands = [] # alternative host check instead of check_icmp
check_periods = []
-
+snmp_check_interval = []
# global variables used to cache temporary values (not needed in check_mk_base)
@@ -697,6 +697,13 @@ def check_period_of(hostname, service):
else:
return None
+def check_interval_of(hostname, checkname):
+ if not check_uses_snmp(checkname):
+ return # no values at all for non snmp checks
+ for match, minutes in host_extra_conf(hostname, snmp_check_interval):
+ if match is None or match == checkname:
+ return minutes * 60 # use first match
+
def get_single_oid(hostname, ipaddress, oid):
# New in Check_MK 1.1.11: oid can end with ".*". In that case
# we do a snmpgetnext and try to find an OID with the prefix
@@ -1524,7 +1531,6 @@ def in_extraconf_servicelist(list, item):
# no match in list -> negative answer
return False
-
# NEW IMPLEMENTATION
def create_nagios_config(outfile = sys.stdout, hostnames = None):
global hostgroups_to_define
@@ -1774,14 +1780,26 @@ def create_nagios_servicedefs(outfile, hostname):
if asn != "":
aggregated_services_conf.add(asn)
+ # Add the check interval of either the Check_MK service or
+ # (if configured) the snmp_check_interval for snmp based checks
+ check_interval = 60 # default hardcoded interval
+ # Customized interval of Check_MK service
+ values = service_extra_conf(hostname, "Check_MK",
extra_service_conf.get('check_interval'))
+ if values:
+ check_interval = values[0] * 60
+ value = check_interval_of(hostname, checkname)
+ if value is not None:
+ check_interval = value
+
outfile.write("""define service {
use\t\t\t\t%s
host_name\t\t\t%s
service_description\t\t%s
+ check_interval\t\t%d
%s%s check_command\t\t\tcheck_mk-%s
}
-""" % ( template, hostname, description, logwatch,
+""" % ( template, hostname, description, check_interval, logwatch,
extra_service_conf_of(hostname, description), checkname ))
checknames_to_define.add(checkname)
@@ -2742,6 +2760,7 @@ no_inventory_possible = None
needed_check_types = set([])
needed_sections = set([])
service_timeperiods = {}
+ check_intervals = {}
for check_type, item, param, descr, aggr in check_table:
if check_type not in check_info:
sys.stderr.write('Warning: Ignoring missing check %s.\n' %
check_type)
@@ -2749,12 +2768,17 @@ no_inventory_possible = None
period = check_period_of(hostname, descr)
if period:
service_timeperiods[descr] = period
+ interval = check_interval_of(hostname, check_type)
+ if interval is not None:
+ check_intervals[check_type] = interval
needed_sections.add(check_type.split(".")[0])
needed_check_types.add(check_type)
if check_uses_snmp(check_type):
need_snmp_module = True
+ output.write("precompiled_check_intervals = %r\n" % check_intervals)
+ output.write("def check_interval_of(hostname, checktype):\n return
precompiled_check_intervals.get(checktype)\n\n")
output.write("precompiled_service_timeperiods = %r\n" %
service_timeperiods)
output.write("def check_period_of(hostname, service):\n return
precompiled_service_timeperiods.get(service)\n\n")
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 46a7b57..4ec4fa2 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -135,6 +135,9 @@ class MKSNMPError(Exception):
def __str__(self):
return self.reason
+class MKSkipCheck(Exception):
+ pass
+
# +----------------------------------------------------------------------+
# | _ _ _ |
# | / \ __ _ __ _ _ __ ___ __ _ __ _| |_(_) ___ _ __ |
@@ -278,6 +281,8 @@ def get_host_info(hostname, ipaddress, checkname):
new_info = [ [node] + line for line in new_info ]
info += new_info
at_least_one_without_exception = True
+ except MKSkipCheck:
+ at_least_one_without_exception = True
except MKAgentError, e:
if str(e) != "": # only first error contains text
exception_texts.append(str(e))
@@ -328,6 +333,13 @@ def get_realhost_info(hostname, ipaddress, check_type,
max_cache_age):
# snmp info for "foo", not for "foo.bar".
oid_info = snmp_info.get(check_type.split(".")[0])
if oid_info:
+ cache_path = tcp_cache_dir + "/" + cache_relpath
+ check_interval = check_interval_of(hostname, check_type)
+ if check_interval is not None and os.path.exists(cache_path) \
+ and cachefile_age(cache_path) < check_interval:
+ # cache file is newer than check_interval, skip this check
+ raise MKSkipCheck()
+
content = read_cache_file(cache_relpath, max_cache_age)
if content:
return eval(content)
@@ -1012,6 +1024,8 @@ def do_all_checks_on_host(hostname, ipaddress, only_check_types =
None):
infotype = checkname.split('.')[0]
try:
info = get_host_info(hostname, ipaddress, infotype)
+ except MKSkipCheck, e:
+ continue
except MKSNMPError, e:
if str(e):
problems.append(str(e))
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 66c1e46..30c0f9c 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -37,8 +37,6 @@
group = _("Configuration of Checks")
-# ignored_checktypes --> Hier brauchen wir noch einen neuen Value-Typ
-
group = _("Multisite & WATO")
register_configvar(group,
@@ -1209,6 +1207,34 @@ register_rule(group,
),
)
+def get_snmp_checktypes():
+ checks = check_mk_local_automation("get-check-information")
+ types = [ (cn, (c['title'] != cn and '%s: ' % cn or '') +
c['title'])
+ for (cn, c) in checks.items() if c['snmp'] ]
+ types.sort()
+ return types
+
+register_rule(group,
+ "snmp_check_interval",
+ Tuple(
+ title = _('Check intervals for SNMP checks'),
+ help = _('This rule can be used to customize the check interval of each SNMP
based check. '
+ 'With this option it is possible to configure a longer check
interval for specific '
+ 'checks, than then normal check interval.'),
+ elements = [
+ DropdownChoice(
+ title = _("Checktype"),
+ choices = [ (None, _('All SNMP Checks')) ] +
get_snmp_checktypes(),
+ ),
+ Integer(
+ title = _("Do check every"),
+ unit = _("minutes"),
+ min_value = 1,
+ ),
+ ]
+ )
+)
+
group = "monconf/" + _("Notifications")
register_rule(group,
"extra_host_conf:notifications_enabled",