diff options
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/discovery.py | 10 | ||||
-rwxr-xr-x | plugins/server_utils.py | 9 |
2 files changed, 19 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: |