summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-05-13 18:18:52 +0530
committerSahina Bose <sabose@redhat.com>2014-05-22 04:06:15 -0700
commit2a33c90c72959a8ed0889effb6ef99190c4d2e0d (patch)
treee40bb630ba49235e4a0b64f0c9424d38e8462d80 /plugins
parenta103d0c54966059bdcf4c1cd20eaf7ef741938ab (diff)
autoconf:check if host is already being monitored
User may have a host configuration defined already for the host being discovered by auto config. So checking if the host already exist as part of another cluster before auto configuring. Same issue may happen when user gives a differnt cluster name in autoconfig after running for the first time. Change-Id: Ia3dbf8e4895cfe4d24e99eda49313b44dbd25aef Bug-Url: https://bugzilla.redhat.com/1085320 Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com> Reviewed-on: http://review.gluster.org/7755 Reviewed-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/discovery.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py
index 87892e9..78f666e 100755
--- a/plugins/discovery.py
+++ b/plugins/discovery.py
@@ -453,9 +453,29 @@ def getAllNonConnectedHosts(hostList):
return nonConnectedHosts
+def _getHostGroupNames(hostConfig):
+ hostgroups = []
+ for hostgroup in hostConfig.get_effective_hostgroups():
+ hostgroups.append(hostgroup.get('hostgroup_name'))
+ return hostgroups
+
+
+def _findDuplicateHost(hosts, clusterName):
+ for host in hosts:
+ hostConfig = server_utils.getHostConfigByName(host.get('hostname'))
+ if hostConfig:
+ if clusterName not in _getHostGroupNames(hostConfig):
+ return host.get('hostname')
+
+
if __name__ == '__main__':
args = parse_input()
clusterdata = discoverCluster(args.hostip, args.cluster, args.timeout)
+ duplicateHost = _findDuplicateHost(clusterdata.get('hosts'), args.cluster)
+ if duplicateHost:
+ print "ERROR: Host '%s' is already being monitored" % duplicateHost
+ sys.exit(utils.PluginStatusCode.CRITICAL)
+
configManager = getConfigManager(args)
clusterDelta = configManager.generateNagiosConfig(clusterdata)
if args.force: