diff options
author | Ramesh Nachimuthu <rnachimu@redhat.com> | 2014-09-11 18:42:29 +0530 |
---|---|---|
committer | Sahina Bose <sabose@redhat.com> | 2014-10-29 00:17:12 -0700 |
commit | 380306ab746c717ec21617f29d611d6bb96ac5c3 (patch) | |
tree | f390e51f0bbc5d69b0677345065c750432d31951 | |
parent | f6c4a6b4fac009f2b4ca738066b7ba9858ec9dec (diff) |
autoconfig: avoid renaming hostnames in nagios
Auto Config tries to use the output of 'hostname' command as
a host_name for node in nagios. But if the hostnames are not unique,
then it uses IP Address as node_name name in nagios.
If after removal of a node, hostnames becomes unique then
auto config renames all the host configuration in nagios to their
hostnames instead of ip address. It creates multiples issues like
removing all the nodes, loss of time series data and unnecessary
confusion to the user.
Fixing this issue by retaining the perviously configured host
names always by going through the host uuid. So if duplication
comes after a node addition then only that node will be
configured with ip address as host_name but all other existing
hosts will not be touched.
Similary, even though there is no duplication after the removal
of a node with duplicate name, auto config will retain the
previously configured hostnames (which are ip addresss
becasue there was a hostname duplication earlier) instead of
renaming.
Change-Id: I0abef47e2e495a591dd3901d2b1766a04c59a701
Bug-Url: https://bugzilla.redhat.com/1139228
Bug-Url: https://bugzilla.redhat.com/1139505
Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com>
Reviewed-on: http://review.gluster.org/8699
Reviewed-by: darshan n <dnarayan@redhat.com>
Reviewed-by: Sahina Bose <sabose@redhat.com>
-rwxr-xr-x | plugins/discovery.py | 10 | ||||
-rwxr-xr-x | plugins/server_utils.py | 9 | ||||
-rw-r--r-- | tests/test_discovery.py | 19 |
3 files changed, 38 insertions, 0 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py index b30e6ba..1ce4679 100755 --- a/plugins/discovery.py +++ b/plugins/discovery.py @@ -498,6 +498,15 @@ def _findDuplicateHost(hosts, clusterName): return host.get('hostname') +# Retain the old hostnames by searching through the host uuid +def replaceHostNamesWithCurrentName(hosts): + hostDict = server_utils.getUuidToHostConfigDict() + for host in hosts: + configuredHost = hostDict.get(host.get('uuid')) + if configuredHost is not None: + host['hostname'] = configuredHost['host_name'] + + def getRemovedHostsCount(clusterDelta): removedHostsCount = 0 for host in clusterDelta.get('_hosts', []): @@ -518,6 +527,7 @@ def _verifyNagiosConfig(): if __name__ == '__main__': args = parse_input() clusterdata = discoverCluster(args.hostip, args.cluster, args.timeout) + replaceHostNamesWithCurrentName(clusterdata.get('hosts')) duplicateHost = _findDuplicateHost(clusterdata.get('hosts'), args.cluster) if duplicateHost: print "ERROR: Host '%s' is already being monitored" % duplicateHost diff --git a/plugins/server_utils.py b/plugins/server_utils.py index ab5b4e8..83470cf 100755 --- a/plugins/server_utils.py +++ b/plugins/server_utils.py @@ -84,6 +84,15 @@ def getHostGroup(name): return None +def getUuidToHostConfigDict(): + hostConfigs = Model.Host.objects.all + resultDict = {} + for hostConfig in hostConfigs: + if hostConfig.get("_HOST_UUID", None) is not None: + resultDict[hostConfig.get("_HOST_UUID")] = hostConfig + return resultDict + + def getNRPEBaseCommand(host, timeout=None): command = NRPE_PATH + " -H " + host if timeout is not None: diff --git a/tests/test_discovery.py b/tests/test_discovery.py index c3a1329..7869a2e 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -194,3 +194,22 @@ class TestDiscovery(TestCaseBase): 'gluster_auto_discovery!10.70.43.57!10.70.43.57'}) hostConfig = {HOST_SERVICES: hostServices} return hostConfig + + def mockGetUuidToHostConfigDict(self): + hostDict = {} + hostDict['0001'] = {'host_name': 'old-host1'} + hostDict['0002'] = {'host_name': 'old-host2'} + hostDict['0003'] = {'host_name': 'old-host3'} + return hostDict + + def testReplaceHostNamesWithCurrentName(self): + server_utils.getUuidToHostConfigDict = self.mockGetUuidToHostConfigDict + clusterData = [{'uuid': '0001', 'hostname': 'new-host1'}, + {'uuid': '0002', 'hostname': 'new-host2'}, + {'uuid': '0004', 'hostname': 'new-host4'}, + {'uuid': '0005', 'hostname': 'new-host5'}] + discovery.replaceHostNamesWithCurrentName(clusterData) + self.assertEqual(clusterData[0]['hostname'], 'old-host1') + self.assertEqual(clusterData[1]['hostname'], 'old-host2') + self.assertEqual(clusterData[2]['hostname'], 'new-host4') + self.assertEqual(clusterData[3]['hostname'], 'new-host5') |