Module: check_mk
Branch: master
Commit: 8f4eeba0ee090a6a3ad8ee09cb3cd2f268465f97
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8f4eeba0ee090a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Mar 27 09:39:18 2015 +0100
#2167 SNMPv3: Added support for using SNMP contextes in requests
Some devices, which are checked via SNMPv3, offer their SNMP data
in different SNMP contextes. Check_MK can now be configured, based
on the host and check type, to use one or multiple specific SNMPv3
context names in the SNMP requests done for the host and check.
By default Check_MK does not set any context, but if you need it,
simply configure the rule <i>SNMPv3 contexts to use in requests</i>.
Please note to only use this feature when you really need it. By
configuring multiple contextes, all SNMP requests are done once for
each SNMPv3 context. This increases the amount of SNMP communication.
---
.werks/2167 | 19 +++++++
ChangeLog | 1 +
modules/check_mk.py | 3 ++
modules/config.py | 1 +
modules/snmp.py | 29 +++++++---
web/plugins/wato/check_mk_configuration.py | 79 ++++++++++++++++++----------
6 files changed, 97 insertions(+), 35 deletions(-)
diff --git a/.werks/2167 b/.werks/2167
new file mode 100644
index 0000000..c3f37a6
--- /dev/null
+++ b/.werks/2167
@@ -0,0 +1,19 @@
+Title: SNMPv3: Added support for using SNMP contextes in requests
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.2.7i1
+Date: 1427445341
+Class: feature
+
+Some devices, which are checked via SNMPv3, offer their SNMP data
+in different SNMP contextes. Check_MK can now be configured, based
+on the host and check type, to use one or multiple specific SNMPv3
+context names in the SNMP requests done for the host and check.
+
+By default Check_MK does not set any context, but if you need it,
+simply configure the rule <i>SNMPv3 contexts to use in requests</i>.
+
+Please note to only use this feature when you really need it. By
+configuring multiple contextes, all SNMP requests are done once for
+each SNMPv3 context. This increases the amount of SNMP communication.
diff --git a/ChangeLog b/ChangeLog
index f1bf387..983b3e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
Core & Setup:
* 1759 Packed RPM and DEB agent packages are now shipped with normal Check_MK
package...
* 1228 Linux Agent: Now supports systemd...
+ * 2167 SNMPv3: Added support for using SNMP contextes in requests...
* 1791 FIX: Fix problem where many bogus RRD files for Check_MK service would be
created...
* 1792 FIX: Fix path to special agents in case of manual installation
* 1797 FIX: Fix incomplete configuration during checking when using CMC...
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 40b881f..d8a4f38 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -641,6 +641,9 @@ def get_snmp_character_encoding(hostname):
if len(entries) > 0:
return entries[0]
+def is_snmpv3_host(hostname):
+ return type(snmp_credentials_of(hostname)) == tuple
+
def is_snmp_host(hostname):
return in_binary_hostlist(hostname, snmp_hosts)
diff --git a/modules/config.py b/modules/config.py
index 9718c9f..7332004 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -109,6 +109,7 @@ tcp_hosts = [ (['tcp'], ALL_HOSTS),
(NEGATE, ['snmp']
bulkwalk_hosts = []
snmpv2c_hosts = []
snmp_without_sys_descr = []
+snmpv3_contexts = []
usewalk_hosts = []
dyndns_hosts = [] # use host name as ip address for these hosts
ignored_checktypes = [] # exclude from inventory
diff --git a/modules/snmp.py b/modules/snmp.py
index cbd955f..4ff2cbb 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -90,6 +90,12 @@ def oid_to_intlist(oid):
def cmp_oids(o1, o2):
return cmp(oid_to_intlist(o1), oid_to_intlist(o2))
+def snmpv3_contexts_of(hostname, check_type):
+ for ty, rules in host_extra_conf(hostname, snmpv3_contexts):
+ if ty == check_type:
+ return rules
+ return [None]
+
def get_snmp_table(hostname, ip, check_type, oid_info):
# oid_info is either ( oid, columns ) or
# ( oid, suboids, columns )
@@ -144,10 +150,19 @@ def get_snmp_table(hostname, ip, check_type, oid_info):
if opt_use_snmp_walk or is_usewalk_host(hostname):
rowinfo = get_stored_snmpwalk(hostname, fetchoid)
- elif has_inline_snmp and use_inline_snmp:
- rowinfo = inline_snmpwalk_on_suboid(hostname, check_type, fetchoid, oid)
else:
- rowinfo = snmpwalk_on_suboid(hostname, ip, fetchoid)
+ rowinfo = []
+ if is_snmpv3_host(hostname):
+ snmp_contexts = snmpv3_contexts_of(hostname, check_type)
+ else:
+ snmp_contexts = [None]
+
+ for context_name in snmp_contexts:
+ if has_inline_snmp and use_inline_snmp:
+ rowinfo += inline_snmpwalk_on_suboid(hostname, check_type,
fetchoid, oid,
+
context_name=context_name)
+ else:
+ rowinfo += snmpwalk_on_suboid(hostname, ip, fetchoid,
context_name=context_name)
# I've seen a broken device (Mikrotik Router), that broke after an
# update to RouterOS v6.22. It would return 9 time the same OID when
@@ -418,10 +433,12 @@ def snmp_decode_string(text):
# | Non-inline SNMP handling code. Kept for compatibility. |
# '----------------------------------------------------------------------'
-def snmpwalk_on_suboid(hostname, ip, oid, hex_plain = False):
+def snmpwalk_on_suboid(hostname, ip, oid, hex_plain = False, context_name = None):
portspec = snmp_port_spec(hostname)
- command = snmp_walk_command(hostname) + \
- " -OQ -OU -On -Ot %s%s %s" % (ip, portspec, oid)
+ command = snmp_walk_command(hostname)
+ if context_name != None:
+ command += " -n %s" % quote_shell_string(context_name)
+ command += " -OQ -OU -On -Ot %s%s %s" % (ip, portspec, oid)
vverbose(' Running %s\n' % command)
snmp_process = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index e9f8f20..9dada8c 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1815,35 +1815,6 @@ 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 [ (None, _('All SNMP Checks')) ] + 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 = get_snmp_checktypes,
- ),
- Integer(
- title = _("Do check every"),
- unit = _("minutes"),
- min_value = 1,
- default_value = 1,
- ),
- ]
- )
-)
-
group = "monconf/" + _("Notifications")
register_rule(group,
"extra_host_conf:notifications_enabled",
@@ -2538,3 +2509,53 @@ register_rule(group,
"agent is running on. It is not applied to the translated
piggybacked hosts."),
),
match = "dict")
+
+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 [ (None, _('All SNMP Checks')) ] + 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 = get_snmp_checktypes,
+ ),
+ Integer(
+ title = _("Do check every"),
+ unit = _("minutes"),
+ min_value = 1,
+ default_value = 1,
+ ),
+ ]
+ )
+)
+
+register_rule(group,
+ "snmpv3_contexts",
+ Tuple(
+ title = _('SNMPv3 contexts to use in requests'),
+ help = _('By default Check_MK does not use a specific context during SNMPv3
queries, '
+ 'but some devices are offering their information in different SNMPv3
contexts. '
+ 'This rule can be used to configure, based on hosts and check type,
which SNMPv3 '
+ 'contexts Check_MK should ask for when getting information via
SNMPv3.'),
+ elements = [
+ DropdownChoice(
+ title = _("Checktype"),
+ choices = get_snmp_checktypes,
+ ),
+ ListOfStrings(
+ title = _("SNMP Context IDs"),
+ allow_empty = False,
+ ),
+ ]
+ )
+)