Module: check_mk
Branch: master
Commit: 2676ae5fa08bfe3f5971e2e9d73131f4d1f61fde
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2676ae5fa08bfe…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Dec 19 19:08:36 2011 +0100
cmk -I: accept host tags and cluster names
Unknown hostnames are considered to be tags and will be replaced
by all hosts with that tag. Prefixing @ forces interpretation as
tag. Cluster names are also allowed now and will be replaced by
the list of nodes.
---
ChangeLog | 4 ++++
modules/check_mk.py | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 87bcaf1..ac58691 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
1.1.13i2
+ Core, Setup, etc.:
+ * cmk -I: accept host tags and cluster names
+
Checks & Agents:
* linux agent - ipmi: Creating directory of cache file if not exists
* dell_powerconnect_cpu: renamed service from CPU to "CPU utilization", in
@@ -65,6 +68,7 @@
to set number of processes. Nagios will not fork() anymore for check exection.
* New columns num_hosts and num_services in status table
* New aggregation functions suminv and avginv (see Documentation)
+
Core, Setup, etc.:
* New configuration variable static_checks[] (used by WATO)
* New configuration variable checkgroup_parameters (mainly for WATO)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 1b8e426..1b3d591 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1103,6 +1103,25 @@ def host_is_member_of_site(hostname, site):
# hosts without a site: tag belong to all sites
return True
+def parse_hostname_list(args):
+ valid_hosts = all_active_hosts() + all_active_clusters()
+ hostlist = []
+ for arg in args:
+ if arg[0] != '@' and arg in valid_hosts:
+ hostlist.append(arg)
+ else:
+ if arg[0] == '@':
+ arg = arg[1:]
+ num_found = 0
+ for host in valid_hosts:
+ if arg in hosttags[host]:
+ hostlist.append(host)
+ num_found += 1
+ if num_found == 0:
+ sys.stderr.write("No host or tag with the name '%s' is
defined in "
+ "all_hosts or clusters.\n" % (arg))
+ sys.exit(1)
+ return hostlist
def hostgroups_of(hostname):
@@ -4419,7 +4438,18 @@ if __name__ == "__main__":
if not done and seen_I > 0:
- hostnames = args
+ hostnames = parse_hostname_list(args)
+ # For clusters add their nodes to the list
+ nodes = []
+ for h in hostnames:
+ nodes = nodes_of(h)
+ if nodes:
+ hostnames += nodes
+
+ # Then remove clusters and make list unique
+ hostnames = list(set([ h for h in hostnames if not is_cluster(h) ]))
+ hostnames.sort()
+
if inventory_checks:
checknames = inventory_checks.split(",")
@@ -4428,6 +4458,8 @@ if __name__ == "__main__":
if inventory_checks == None:
checknames = inventorable_checktypes("all")
if len(hostnames) > 0:
+ # Entries in hostnames that are either prefixed with @
+ # or are no valid hostnames are considered to be tags.
for host in hostnames:
remove_autochecks_of(host, checknames)
clust = cluster_of(host)