Module: check_mk
Branch: master
Commit: 21274150b34f0cb6ca6c8ad8fcbf435c99d83694
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=21274150b34f0c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 19 16:57:55 2018 +0100
5850 Management board protocol can now be configured on folders
To make the configuration more flexible it is now possible to
configure the management board protocol on folders and inherit
this option to the hosts in a folder.
It is also possible to override the value inherited from a folder
to e.g. set it to "No management board" for specific hosts again.
Change-Id: If9a163ecdeb331768ede45c484af76cdadb8b7b8
---
.werks/5850 | 15 ++++++++++++
cmk_base/config.py | 29 +++++++++++++---------
web/htdocs/watolib.py | 1 +
web/plugins/wato/builtin_attributes.py | 44 +++++++++++++---------------------
4 files changed, 50 insertions(+), 39 deletions(-)
diff --git a/.werks/5850 b/.werks/5850
new file mode 100644
index 0000000..8200342
--- /dev/null
+++ b/.werks/5850
@@ -0,0 +1,15 @@
+Title: Management board protocol can now be configured on folders
+Level: 1
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1519055783
+Class: feature
+
+To make the configuration more flexible it is now possible to
+configure the management board protocol on folders and inherit
+this option to the hosts in a folder.
+
+It is also possible to override the value inherited from a folder
+to e.g. set it to "No management board" for specific hosts again.
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 9213114..513c09d 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -674,28 +674,35 @@ def management_protocol(hostname):
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,
+ "address" : None,
+ "protocol" : None,
+ "credentials" : None,
}
- if "management_protocol" not in attributes_of_host and not rule_settings:
+
+ # When management_protocol is set to no management board, don't do anything else
+ # -> The management board can not be enabled by the credentials rule
+ if not attributes_of_host.get("management_protocol"):
return management_board
- if rule_settings:
- protocol, credentials = rule_settings[0]
- management_board["protocol"] = protocol
- management_board["credentials"] = credentials
+ management_board["protocol"] =
attributes_of_host["management_protocol"]
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"]
+ # Set the defaults form the management board related ruleset. Use the first
+ # rule that matches the protocol configured for this host.
+ rule_settings = rulesets.host_extra_conf(hostname, management_board_config)
+ for protocol, credentials in rule_settings:
+ if protocol == management_board["protocol"]:
+ management_board["credentials"] = credentials
+ break
+
+ # Override the defaults set above with explicit host/folder settings
if attributes_of_host.get("management_snmp_community"):
management_board["credentials"] =
attributes_of_host["management_snmp_community"]
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index f6c8845..bdb21be 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -1449,6 +1449,7 @@ class CREFolder(BaseFolder):
else:
all_hosts.append(hostentry)
+ # TODO: Management board?
for attribute_name, dictionary in [
( "ipaddress", ipv4_addresses ),
( "ipv6address", ipv6_addresses ),
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index b1feafb..d4f7bf7 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -489,34 +489,12 @@ declare_host_attribute(NetworkScanResultAttribute(),
topic = _("Network Scan"))
-class ManagementTypeAttribute(Attribute):
- def __init__(self, name):
- self._choices = [
- ("snmp", "SNMP"),
- #("ipmi", "IPMI"),
- #("ping", _("Ping-only"))
- ]
-
- self._choices_dict = dict(self._choices)
-
- Attribute.__init__(self, name, _("Protocol"),
- _("Specify the protocol used to connect to the management
board."))
-
- def paint(self, value, hostname):
- return "", self._choices_dict.get(value, value)
-
- def render_input(self, varprefix, value):
- html.dropdown(varprefix + "protocol", self._choices, deflt=value)
-
- def from_html_vars(self, varprefix):
- return html.var(varprefix + "protocol")
-
declare_host_attribute(ValueSpecAttribute("management_address",
HostAddress(
title = _("Address"),
help = _("Address (IPv4 or IPv6) or dns name under which the "
"management board can be reached. If this is not set, "
- "the same address as that of the Host will be used."),
+ "the same address as that of the host will be used."),
allow_empty = False
)),
show_in_table = False,
@@ -524,11 +502,21 @@
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_protocol",
+ DropdownChoice(
+ title = _("Protocol"),
+ help = _("Specify the protocol used to connect to the management
board."),
+ choices = [
+ (None, _("No management board")),
+ ("snmp", "SNMP"),
+ #("ipmi", "IPMI"),
+ #("ping", _("Ping-only"))
+ ],
+ )),
+ show_in_table = False,
+ show_in_folder = True,
+ topic = _("Management Board")
+)
declare_host_attribute(ValueSpecAttribute("management_snmp_community",
SNMPCredentials(