Module: check_mk
Branch: master
Commit: 107c316f76368e05ff3c6925d257c2dc43e55eb2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=107c316f76368e…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Nov 30 15:52:57 2017 +0100
5449 Credentials of SNMP management boards are now configurable via WATO host rule
Change-Id: I8e214c90385e3804461a5286c347f87abace05a2
---
.werks/5449 | 13 +++++++++
cmk_base/config.py | 47 +++++++++++++++++++++++-------
cmk_base/default_config/base.py | 1 +
web/plugins/wato/builtin_attributes.py | 16 +++++-----
web/plugins/wato/check_mk_configuration.py | 11 +++++++
5 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/.werks/5449 b/.werks/5449
new file mode 100644
index 0000000..313293e
--- /dev/null
+++ b/.werks/5449
@@ -0,0 +1,13 @@
+Title: Credentials of SNMP management boards are now configurable via WATO host rule
+Level: 1
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1512053208
+Class: feature
+
+Previously SNMP management board credentials could only be
+stated wihtin the host object itself. Now this can be done
+with the host rule {Management board config} below
+{Host & Service parameters}, {Access to Agents}, {SNMP}.
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 8e417d9..7e4138b 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -652,25 +652,49 @@ def is_ipv4_host(hostname):
# Either explicit IPv4 or implicit (when host is not an IPv6 host)
return "ip-v4" in tags_of_host(hostname) or "ip-v6" not in
tags_of_host(hostname)
-
#
# Management board
#
def has_management_board(hostname):
- return "management_protocol" in host_attributes.get(hostname, {})
+ return _management_board_settings_of(hostname)["protocol"] is not None
def management_address(hostname):
- if 'management_address' in host_attributes.get(hostname, {}):
- return host_attributes[hostname]['management_address']
- else:
- return ipaddresses.get(hostname)
+ return _management_board_settings_of(hostname)["address"]
def management_protocol(hostname):
- return host_attributes[hostname]['management_protocol']
+ return _management_board_settings_of(hostname)["protocol"]
+
+
+def _management_board_settings_of(hostname):
+ rule_settings = rulesets.host_extra_conf(hostname, management_board_config)
+ attributes_of_host = host_attributes.get(hostname, {})
+ management_board = {
+ "address": None,
+ "protocol": None,
+ "credentials": None,
+ }
+ if "management_protocol" not in attributes_of_host and not rule_settings:
+ return management_board
+ if rule_settings:
+ protocol, credentials = rule_settings[0]
+ management_board["protocol"] = protocol
+ management_board["credentials"] = credentials
+
+ if attributes_of_host.get("management_address"):
+ management_board["address"] =
attributes_of_host["management_address"]
+ else:
+ management_board["address"] = ipaddresses.get(hostname)
+
+ if attributes_of_host.get("management_protocol"):
+ management_board["protocol"] =
attributes_of_host["management_protocol"]
+ if attributes_of_host.get("management_snmp_community"):
+ management_board["credentials"] =
attributes_of_host["management_snmp_community"]
+
+ return management_board
#
# Agent communication
@@ -731,9 +755,12 @@ def snmp_credentials_of(hostname):
# board and the host itself queried through snmp.
# The alternative is a lengthy and errorprone refactoring of the whole check-
# call hierarchy to get the credentials passed around.
- if has_management_board(hostname)\
- and management_protocol(hostname) == "snmp":
- return host_attributes.get(hostname,
{}).get("management_snmp_community", "public")
+ management_board = _management_board_settings_of(hostname)
+ if management_board["protocol"] == "snmp":
+ if management_board["credentials"]:
+ return management_board["credentials"]
+ else:
+ return "public"
try:
return explicit_snmp_communities[hostname]
diff --git a/cmk_base/default_config/base.py b/cmk_base/default_config/base.py
index a4db784..af766b7 100644
--- a/cmk_base/default_config/base.py
+++ b/cmk_base/default_config/base.py
@@ -75,6 +75,7 @@ record_inline_snmp_stats = False
snmp_default_community = 'public'
snmp_communities = []
explicit_snmp_communities = {} # override the rule based configuration
+management_board_config = []
snmp_timing = []
snmp_character_encodings = []
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index 93bd567..118e2df 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -178,6 +178,7 @@ class SNMPCredentials(Alternative):
kwargs["orientation"] = "vertical"
Alternative.__init__(self, **kwargs)
+
declare_host_attribute(
ValueSpecAttribute(
"snmp_community",
@@ -196,6 +197,7 @@ declare_host_attribute(
depends_on_tags = ['snmp'],
)
+
# Attribute for configuring parents
class ParentsAttribute(ValueSpecAttribute):
def __init__(self):
@@ -477,12 +479,6 @@ class ManagementTypeAttribute(Attribute):
def from_html_vars(self, varprefix):
return html.var(varprefix + "protocol")
-declare_host_attribute(ManagementTypeAttribute("management_protocol"),
- show_in_table = False,
- show_in_folder = False,
- topic = _("Management Board")
- )
-
declare_host_attribute(ValueSpecAttribute("management_address",
HostAddress(
title = _("Address"),
@@ -496,12 +492,18 @@
declare_host_attribute(ValueSpecAttribute("management_address",
topic = _("Management Board")
)
+declare_host_attribute(ManagementTypeAttribute("management_protocol"),
+ show_in_table = False,
+ show_in_folder = False,
+ topic = _("Management Board")
+ )
+
declare_host_attribute(ValueSpecAttribute("management_snmp_community",
SNMPCredentials(
default_value = None,
)),
show_in_table = False,
- show_in_folder = False,
+ show_in_folder = True,
topic = _("Management Board")
)
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 551eba5..2c849e2 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -2328,6 +2328,17 @@ register_rule(group,
)
register_rule(group,
+ "management_board_config",
+ CascadingDropdown(
+ title=_("Management board config"),
+ choices=[
+ (None, _("No protocol specified"), FixedValue(None,
totext="")),
+ ("snmp", _("SNMP"), SNMPCredentials()),
+ ],
+ ),
+)
+
+register_rule(group,
"snmp_character_encodings",
DropdownChoice(
title = _("Output text encoding settings for SNMP devices"),