Module: check_mk
Branch: master
Commit: 63ee29d3d47029d214229ffeff5c6a8386e9b36b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=63ee29d3d47029…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Aug 12 14:15:54 2013 +0200
WATO hosts/folders: implemented snmp community config on host/folder base
---
ChangeLog | 2 ++
web/htdocs/wato.py | 38 +++++++++++++++++++++-----------
web/plugins/wato/builtin_attributes.py | 11 +++++++++
3 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 82a0963..4091581 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -122,6 +122,8 @@
requests, queue
* Custom user attributes can now be managed using WATO
* Allow GIT to be used for change tracking (enable via global option)
+ * Hosts/Folders: SNMP communities can now be configured via the host
+ and folders hierarchy. Those settings override the rule base config.
* FIX: do validation of check items in rule editor
* FIX: More consistent handling of folderpath select in rule editor
* Require unique alias names in between the following elements:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 57860c5..8433cf7 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -572,16 +572,17 @@ def load_hosts_file(folder):
filename = root_dir + folder[".path"] + "/hosts.mk"
if os.path.exists(filename):
variables = {
- "FOLDER_PATH" : "",
- "ALL_HOSTS" : ALL_HOSTS,
- "all_hosts" : [],
- "clusters" : {},
- "ipaddresses" : {},
- "extra_host_conf" : { "alias" : [] },
- "extra_service_conf" : { "_WATO" : [] },
- "host_attributes" : {},
- "host_contactgroups" : [],
- "_lock" : False,
+ "FOLDER_PATH" : "",
+ "ALL_HOSTS" : ALL_HOSTS,
+ "all_hosts" : [],
+ "clusters" : {},
+ "ipaddresses" : {},
+ "explicit_snmp_communities" : {},
+ "extra_host_conf" : { "alias" : [] },
+ "extra_service_conf" : { "_WATO" : [] },
+ "host_attributes" : {},
+ "host_contactgroups" : [],
+ "_lock" : False,
}
execfile(filename, variables, variables)
nodes_of = {}
@@ -610,8 +611,9 @@ def load_hosts_file(folder):
alias = aliases[0]
else:
alias = None
- host["alias"] = alias
- host["ipaddress"] = ipaddress
+ host["alias"] = alias
+ host["ipaddress"] = ipaddress
+ host["snmp_community"] =
variables["explicit_snmp_communities"].get(hostname)
# Retrieve setting for each individual host tag
tags = set([ tag for tag in parts[1:] if tag != 'wato' and not
tag.endswith('.mk') ])
@@ -675,6 +677,7 @@ def save_hosts(folder = None):
all_hosts = [] # list of [Python string for all_hosts]
clusters = [] # tuple list of (Python string, nodes)
ipaddresses = {}
+ explicit_snmp_communities = {}
hostnames = hosts.keys()
hostnames.sort()
custom_macros = {} # collect value for attributes that are to be present in Nagios
@@ -686,7 +689,8 @@ def save_hosts(folder = None):
host = cleaned_hosts[hostname]
effective = effective_attributes(host, folder)
- ipaddress = effective.get("ipaddress")
+ ipaddress = effective.get("ipaddress")
+ snmp_community = effective.get("snmp_community")
# Compute tags from settings of each individual tag. We've got
# the current value for each individual tag. Also other attributes
@@ -712,6 +716,8 @@ def save_hosts(folder = None):
if ipaddress:
ipaddresses[hostname] = ipaddress
+ if snmp_community:
+ explicit_snmp_communities[hostname] = snmp_community
# Create contact group rule entries for hosts with explicitely set values
# Note: since the type if this entry is a list, not a single contact group, all
other list
@@ -754,6 +760,12 @@ def save_hosts(folder = None):
out.write("\n# Explicit IP addresses\n")
out.write("ipaddresses.update(")
out.write(pprint.pformat(ipaddresses))
+ out.write(")\n")
+
+ if len(ipaddresses) > 0:
+ out.write("\n# Explicit SNMP communities\n")
+ out.write("explicit_snmp_communities.update(")
+ out.write(pprint.pformat(explicit_snmp_communities))
out.write(")")
out.write("\n")
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index cebcd2a..1d907e7 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -46,6 +46,17 @@ declare_host_attribute(TextAttribute("ipaddress", _("IP
address"),
show_in_table = True,
show_in_folder = False)
+declare_host_attribute(TextAttribute("snmp_community", _("SNMP
Community"),
+ _("Using this option you can configure the community which
should be used when "
+ "contacting this host via SNMP v1 or v2. It is possible to
configure the SNMP community by "
+ "using the <a href=\"%s\">SNMP
Communities</a> ruleset, but when you configure "
+ "some community here, this will override the community
defined by the rules.") % \
+ html.makeuri([('mode', 'edit_ruleset'),
('varname', 'snmp_communities')]),
+ allow_empty = False),
+ show_in_table = False,
+ show_in_folder = True,
+ depends_on_tags = ['snmp'])
+
# Attribute for configuring parents
class ParentsAttribute(ValueSpecAttribute):
def __init__(self):