Module: check_mk
Branch: master
Commit: fec8bb40437c9cd4c533ec5bc8939e8307afae0a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fec8bb40437c9c…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Apr 29 08:35:25 2012 +0200
make host_extra_conf["parents"] have precedence
---
ChangeLog | 3 +++
modules/check_mk.py | 10 +++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e4fdc4d..6cb2349 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
Core:
* FIX: fixed SNMP info declaration in checks: could be garbled
up in rare cases
+ * avoid duplicate parents definition, when using 'parents' and
+ extra_host_conf["parents"] at the same time. The later one has
+ precedence.
Multisite:
* Logwatch: Colorizing OK state blocks correctly
diff --git a/modules/check_mk.py b/modules/check_mk.py
index a1b0c66..4243f45 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1507,8 +1507,12 @@ def create_nagios_hostdefs(outfile, hostname):
outfile.write(" contact_groups\t\t%s\n" % ",".join(cgrs))
contactgroups_to_define.update(cgrs)
+ # Get parents manually defined via extra_host_conf["parents"]. Only honor
+ # variable "parents" and implicit parents if this setting is empty
+ extra_conf_parents = host_extra_conf(hostname, extra_host_conf.get("parents", []))
+
# Parents for non-clusters
- if not is_clust:
+ if not extra_conf_parents and not is_clust:
parents_list = parents_of(hostname)
if len(parents_list) > 0:
outfile.write(" parents\t\t\t%s\n" % (",".join(parents_list)))
@@ -1522,13 +1526,13 @@ def create_nagios_hostdefs(outfile, hostname):
node_ips = [ lookup_ipaddress(h) for h in nodes ]
alias = "cluster of %s" % ", ".join(nodes)
outfile.write(" _NODEIPS\t\t\t%s\n" % " ".join(node_ips))
- outfile.write(" parents\t\t\t%s\n" % ",".join(nodes))
+ if not extra_conf_parents:
+ outfile.write(" parents\t\t\t%s\n" % ",".join(nodes))
# Host check uses (service-) IP address if available
if ip:
outfile.write(" check_command\t\t\tcheck-mk-ping\n")
-
# Output alias, but only if it's not define in extra_host_conf
aliases = host_extra_conf(hostname, extra_host_conf.get("alias", []))
if len(aliases) == 0:
Module: check_mk
Branch: master
Commit: de1803410c61c7912902dc8ccc4981027e9314c5
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=de1803410c61c7…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Apr 28 18:30:52 2012 +0200
WATO: configure parents of hosts
Still some code in modules/check_mk.py is neccessary in
order to avoid duplicate parent definitions
---
ChangeLog | 2 +
web/htdocs/check_mk.css | 6 ++++-
web/htdocs/valuespec.py | 2 +-
web/htdocs/wato.css | 1 -
web/htdocs/wato.py | 4 +-
web/plugins/wato/builtin_attributes.py | 36 ++++++++++++++++++++++++++++---
6 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2797dad..e4fdc4d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,8 @@
* New button "Recursive Inventory" on folder: Allows to do
a recursive inventory over all hosts. Also allows to selectively
retry only hosts that have failed in a previous inventory.
+ * You can configure parents now (via a host attribute, no rules are
+ neccessary).
* FIX: fix page header after confirmation dialogs
* FIX: Fixed umlaut problem in host aliases and ip addresses created by WATO
* FIX: Fixed exception caused by validation problems during editing tags in WATO
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index f867b5f..21cda92 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -390,9 +390,13 @@ table.valuespec_listof option[selected] {
font-weight: bold;
}
+div.listofstrings > div {
+ margin-bottom: 2px;
+}
+
div.listofstrings.horizontal > div {
float: left;
- margin-right: 5px;
+ margin-right: 2px;
}
table.listchoice {
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index ec9953d..2bb608c 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -266,7 +266,7 @@ class TextAscii(ValueSpec):
def __init__(self, **kwargs):
ValueSpec.__init__(self, **kwargs)
self._label = kwargs.get("label")
- self._size = kwargs.get("size", 30)
+ self._size = kwargs.get("size", 25)
self._strip = kwargs.get("strip", True)
self._allow_empty = kwargs.get("allow_empty", True)
self._none_is_empty = kwargs.get("none_is_empty", False)
diff --git a/web/htdocs/wato.css b/web/htdocs/wato.css
index 826c4bf..864949c 100644
--- a/web/htdocs/wato.css
+++ b/web/htdocs/wato.css
@@ -488,7 +488,6 @@ table.validationerror img {
margin-top: 10px;
margin-bottom: 10px;
padding: 5px 8px;
- width: 834px;
-moz-border-radius: 3px;
background-image: url("images/form_background.png");
background-repeat: repeat;
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 95d3b54..fbb7fd2 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -72,7 +72,7 @@
# ".total_hosts" -> recursive number of hosts, computed on demand by
# num_hosts_in()
# ".siteid" -> This attribute is mandatory for host objects and optional for folder
-# objects. In case of hosts and single WATO setup it is always none.
+# objects. In case of hosts and single WATO setup it is always None.
#
#
# g_folder -> The folder object representing the folder the user is
@@ -3707,7 +3707,7 @@ class Attribute:
# A simple text attribute. It is stored in
# a Python unicode string
class TextAttribute(Attribute):
- def __init__(self, name, title, help = None, default_value="", mandatory=False, allow_empty=True, size=20):
+ def __init__(self, name, title, help = None, default_value="", mandatory=False, allow_empty=True, size=25):
Attribute.__init__(self, name, title, help, default_value)
self._mandatory = mandatory
self._allow_empty = allow_empty
diff --git a/web/plugins/wato/builtin_attributes.py b/web/plugins/wato/builtin_attributes.py
index 1ec9c75..3f8311f 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -46,18 +46,46 @@ declare_host_attribute(TextAttribute("ipaddress", _("IP address"),
show_in_table = True,
show_in_folder = False)
+# Attribute for configuring parents
class ParentsAttribute(ValueSpecAttribute):
def __init__(self):
ValueSpecAttribute.__init__(self, "parents",
- ListOfStrings(
- title = _("Parents"),
- help = _("Hier kommt die Hilfe."),
- orientation = "horizontal"))
+ ListOfStrings(
+ title = _("Parents"),
+ help = _("Parents are used to configure the reachability of hosts by the "
+ "monitoring server. A host is considered to be <b>unreachable</b> if all "
+ "of its parents are unreachable or down. Unreachable hosts will not be "
+ "actively monitored.<br><br><b>Clusters</b> automatically configure all "
+ "of their nodes as parents, but only if you do not configure parents "
+ "manually.<br><br>In a distributed setup make sure that the host and all "
+ "of its parents are monitored by the same site."),
+ orientation = "horizontal"))
def to_nagios(self, value):
if value:
return ",".join(value)
+ def nagios_name(self):
+ return "parents"
+
declare_host_attribute(ParentsAttribute(),
show_in_table = True,
show_in_folder = True)
+
+def validate_host_parents(effective_host):
+ for parentname in effective_host["parents"]:
+ parent_folder = find_host(parentname)
+ if not parent_folder:
+ raise MKUserError(None, _("You defined the non-existing host '%s' as a parent.") % parentname)
+ # In case of distributed wato check also if site of host and parent
+ # are the same.
+ if is_distributed():
+ parent = effective_attributes(parent_folder[".hosts"][parentname], parent_folder)
+ if effective_host["site"] != parent["site"]:
+ raise MKUserError(None, _("The parent '%s' is monitored on site '%s' while the host itself "
+ "is monitored on site '%s'. Both must be monitored on the same site. Remember: The parent/child "
+ "relation is used to describe the reachability of hosts by one monitoring daemon.") %
+ (parentname, parent["site"], effective_host["site"]))
+
+api.register_hook('validate-host', validate_host_parents)
+
vertical mode
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 6fdcba30eacee6e82b108dccc8ed91e4e9267afa
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6fdcba30eacee6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sat Apr 28 17:37:54 2012 +0200
Fix ValueSpec ListOfStrings horizontal/vertical mode
---
web/htdocs/check_mk.css | 5 +-
web/htdocs/js/checkmk.js | 67 +++++++++++++++++---------------
web/htdocs/valuespec.py | 20 +++-------
web/plugins/wato/builtin_attributes.py | 16 ++++++++
4 files changed, 61 insertions(+), 47 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index 4eed256..f867b5f 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -390,8 +390,9 @@ table.valuespec_listof option[selected] {
font-weight: bold;
}
-table.listofstrings.horizontal td {
- padding-right: 5px;
+div.listofstrings.horizontal > div {
+ float: left;
+ margin-right: 5px;
}
table.listchoice {
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 1990135..4dc5d78 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1408,52 +1408,57 @@ function valuespec_toggle_dropdownn(oDropdown, divid) {
oDiv = null;
}
-function list_of_strings_init(tableid) {
- var oTable = document.getElementById(tableid);
- var oTBody = oTable.childNodes[0];
- var oTr = oTBody.childNodes[oTBody.childNodes.length - 1];
- var oTd = oTr.childNodes[0];
- for (var j in oTd.childNodes) {
- var o = oTd.childNodes[j];
+/* This function is called after the table with of input elements
+ has been rendered. It attaches the onFocus-function to the last
+ of the input elements. The reason is, that ListOfString does not render
+ the input fields itself. This does so other ValueSpec element
+ where we have no access to */
+function list_of_strings_init(divid) {
+ var oContainer = document.getElementById(divid);
+ var numChilds = oContainer.childNodes.length;
+ var oLastChild = oContainer.childNodes[numChilds-1];
+ list_of_strings_add_focus(oLastChild);
+}
+
+function list_of_strings_add_focus(oLastChild) {
+ /* look for <input> in last child node and attach focus handler to it. */
+ for (var j in oLastChild.childNodes) {
+ var o = oLastChild.childNodes[j];
if (o.tagName == "INPUT") {
o.onfocus = function(e) { return list_of_strings_extend(this); };
}
}
}
+/* Is called when the last input field in a ListOfString gets focus.
+ In that case a new input field is being appended. */
function list_of_strings_extend(oInput, j) {
+
+ /* The input field has a unique name like "extra_emails_2" for the field with
+ the index 2. We need to convert this into "extra_emails_3". */
+
var oldName = oInput.name;
- // Transform e.g extra_emails_12 -> extra_emails_13
var splitted = oldName.split("_");
var num = 1 + parseInt(splitted[splitted.length-1]);
splitted[splitted.length-1] = "" + num;
var newName = splitted.join("_");
- var oTd = oInput.parentNode;
- var oTr = oTd.parentNode;
- var oTBody = oTr.parentNode;
- var oNewTd;
+ /* Now create a new <div> element as a copy from the current one and
+ replace this name. We do this by simply copying the HTML code. The
+ last field is always empty. Remember: ListOfStrings() always renders
+ one exceeding empty element. */
- var horiz = oTBody.parentNode.classList.contains("horizontal");
+ var oDiv = oInput.parentNode;
+ while (!oDiv.parentNode.classList.contains("listofstrings"))
+ oDiv = oDiv.parentNode;
+ var oContainer = oDiv.parentNode;
- if (!horiz) {
- var oNewTr = document.createElement("TR");
- oNewTr.innerHTML = oTr.innerHTML.replace('"' + oldName + '"', '"' + newName + '"');
- oTBody.appendChild(oNewTr);
- oNewTd = oNewTr.childNodes[0];
- }
- else {
- var oNewTd = document.createElement("TD");
- oNewTd.innerHTML = oTd.innerHTML.replace('"' + oldName + '"', '"' + newName + '"');
- oTr.appendChild(oNewTd);
- }
- for (var j in oNewTd.childNodes) {
- var o = oNewTd.childNodes[j];
- if (o.tagName == "INPUT") {
- o.onfocus = function(e) { return list_of_strings_extend(this); };
- }
- }
- // Remove handle from old last element
+ var oNewDiv = document.createElement("DIV");
+ oNewDiv.innerHTML = oDiv.innerHTML.replace('"' + oldName + '"', '"' + newName + '"');
+ oContainer.appendChild(oNewDiv);
+
+ /* Move focus function from old last to new last input field */
+ list_of_strings_add_focus(oNewDiv);
oInput.onfocus = null;
}
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 682ce62..ec9953d 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -499,23 +499,15 @@ class ListOfStrings(ValueSpec):
while html.has_var(vp + "_%d" % nr):
html.del_var(vp + "_%d" % nr)
nr += 1
- html.write('<table class="listofstrings %s" border=0 cellspacing=0 cellpadding=0 id="%s">' % (
- self._vertical and "vertical" or "horizontal", vp))
- if not self._vertical:
- html.write('<tr>')
-
+
+ html.write('<div class="listofstrings %s" id="%s">' % (self._vertical and 'vertical' or 'horizontal', vp))
+
for nr, s in enumerate(value + [""]):
- if self._vertical:
- html.write('<tr>')
- html.write('<td>')
+ html.write('<div>')
self._valuespec.render_input(vp + "_%d" % nr, s)
- html.write('</td>')
- if self._vertical:
- html.write('</tr>')
+ html.write('</div>')
+ html.write('</div>')
- if not self._vertical:
- html.write('</tr>')
- html.write('</table>')
html.javascript("list_of_strings_init('%s');" % vp);
def canonical_value(self):
diff --git a/web/plugins/wato/builtin_attributes.py b/web/plugins/wato/builtin_attributes.py
index 3e85bcd..1ec9c75 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -45,3 +45,19 @@ declare_host_attribute(TextAttribute("ipaddress", _("IP address"),
allow_empty = False),
show_in_table = True,
show_in_folder = False)
+
+class ParentsAttribute(ValueSpecAttribute):
+ def __init__(self):
+ ValueSpecAttribute.__init__(self, "parents",
+ ListOfStrings(
+ title = _("Parents"),
+ help = _("Hier kommt die Hilfe."),
+ orientation = "horizontal"))
+ def to_nagios(self, value):
+ if value:
+ return ",".join(value)
+
+
+declare_host_attribute(ParentsAttribute(),
+ show_in_table = True,
+ show_in_folder = True)