From c30f0e1ee1193d7585ad7378da4c360421b545b0 Mon Sep 17 00:00:00 2001 From: Ramesh Nachimuthu Date: Fri, 14 Nov 2014 10:19:47 +0530 Subject: autoconf: unregister the temp_node1 instead of deleting it. Unregistering the temp_node1 instead of deleting it while configuring nagios . new field 'register' will be added to temp_node1 and its services with value 0, so that it won't be considered by nagios. If both files, temp_node1.cfg and temp_node1.cfg.sample are present during upgrade then we will remove the file temp_node1.cfg.sample and add the 'register 0' flag to definitions in temp_node1.cfg file. Bug-Url: https://bugzilla.redhat.com/1162446 Bug-Url: https://bugzilla.redhat.com/1162443 Bug-Url: https://bugzilla.redhat.com/1115387 Change-Id: I3c76d6c6a9a9e411315859e07238a7902ddd2380 Signed-off-by: Ramesh Nachimuthu Reviewed-on: http://review.gluster.org/9123 Reviewed-by: Kanagaraj M Reviewed-by: Sahina Bose --- nagios-server-addons.spec.in | 7 +++++++ plugins/discovery.py | 27 ++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/nagios-server-addons.spec.in b/nagios-server-addons.spec.in index 23149d3..0fe4fea 100644 --- a/nagios-server-addons.spec.in +++ b/nagios-server-addons.spec.in @@ -126,6 +126,13 @@ rm -rf %{buildroot} NagiosCFGFile="/etc/nagios/nagios.cfg" sed -i '/etc\/nagios\/objects\/localhost.cfg/d' $NagiosCFGFile +LocalhostCfgFile="%{_sysconfdir}/nagios/gluster/default/temp_node1.cfg" +LocalhostCfgFileEdited="%{_sysconfdir}/nagios/gluster/default/temp_node1.cfg.sample" +if [ -f $LocalhostCfgFileEdited ]; then + sed -i '/host_name * temp_node1/a \ register 0' $LocalhostCfgFile + rm $LocalhostCfgFileEdited +fi + if grep -q "#process_performance_data=0" $NagiosCFGFile; then sed -i -e 's/#process_performance_data=0/process_performance_data=1/g' $NagiosCFGFile elif grep -q "process_performance_data=0" $NagiosCFGFile ; then diff --git a/plugins/discovery.py b/plugins/discovery.py index eb77313..46fee95 100755 --- a/plugins/discovery.py +++ b/plugins/discovery.py @@ -515,6 +515,18 @@ def getRemovedHostsCount(clusterDelta): return removedHostsCount +def unRegisterHost(hostName): + hostConfig = server_utils.getHostConfigByName(hostName) + if hostConfig: + if hostConfig.get('register') != '0': + hostConfig['register'] = 0 + hostConfig.save() + serviceConfigs = server_utils.getServiceConfigByHost(hostName) + for serviceConfig in serviceConfigs: + serviceConfig['register'] = 0 + serviceConfig.save() + + def _verifyNagiosConfig(): (rc, out, err) = utils.execCmd([server_utils.nagiosCmdPath.cmd, '-v', NAGIOS_CONFIG_FILE]) @@ -556,19 +568,8 @@ if __name__ == '__main__': args.nagiosServerIP, args.mode, args.timeout) print "Cluster configurations synced successfully from host %s" % \ (args.hostip) - # Rename the configuration file for dummy host from temp_node1.cfg - # to temp_node1.cfg.sample as this host is not needed after other - # hosts are configured through auto-discovery. - dummy_host_config_file = DEFAULT_AUTO_CONFIG_DIR \ - + '/default/temp_node1.cfg' - try: - if os.path.exists(dummy_host_config_file): - os.rename( - dummy_host_config_file, - dummy_host_config_file + '.sample' - ) - except Exception as e: - pass + #Unregister the temp_node1 + unRegisterHost("temp_node1") # If Nagios is running then try to restart. Otherwise don't do # anything. if server_utils.isNagiosRunning(): -- cgit