summaryrefslogtreecommitdiffstats
path: root/plugins/discovery.py
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-06-20 17:14:41 +0530
committerSahina Bose <sabose@redhat.com>2014-09-15 03:20:55 -0700
commiteab2ca4f26adb9b661fbad855a9b46f308fc5911 (patch)
tree149da091f9bb60023e3701295b11a617711269b4 /plugins/discovery.py
parent5f1536a1ae99a15cdb4505ad94278423bf72cf27 (diff)
autoconf: verify the configurations before restarting nagios
Verify the Nagios configuration before restarting the nagios server. It helps in accidently stoping the nagios server because of config error. Change-Id: I8c7cb5663bf42d73812577e9b162434cb2ecfdfe Bug-Url: https://bugzilla.redhat.com/1138943 Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com> Reviewed-on: http://review.gluster.org/8131 Reviewed-by: Shubhendu Tripathi <shtripat@redhat.com> Reviewed-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins/discovery.py')
-rwxr-xr-xplugins/discovery.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py
index 698873e..b30e6ba 100755
--- a/plugins/discovery.py
+++ b/plugins/discovery.py
@@ -28,7 +28,7 @@ from config_generator import GlusterNagiosConfManager
import server_utils
import submit_external_command
from constants import DEFAULT_AUTO_CONFIG_DIR
-
+from constants import NAGIOS_CONFIG_FILE
from config_generator import CHANGE_MODE
from config_generator import CHANGE_MODE_ADD
@@ -505,6 +505,16 @@ def getRemovedHostsCount(clusterDelta):
removedHostsCount += 1
return removedHostsCount
+
+def _verifyNagiosConfig():
+ (rc, out, err) = utils.execCmd([server_utils.nagiosCmdPath.cmd, '-v',
+ NAGIOS_CONFIG_FILE])
+ if rc == 0:
+ return True
+ else:
+ return False
+
+
if __name__ == '__main__':
args = parse_input()
clusterdata = discoverCluster(args.hostip, args.cluster, args.timeout)
@@ -552,12 +562,16 @@ if __name__ == '__main__':
# If Nagios is running then try to restart. Otherwise don't do
# anything.
if server_utils.isNagiosRunning():
- confirmation = getConfirmation(
- "Do you want to restart Nagios to start monitoring newly "
- "discovered entities?", "Yes")
- if confirmation:
- server_utils.restartNagios()
- print "Nagios re-started successfully"
+ if _verifyNagiosConfig():
+ confirmation = getConfirmation(
+ "Do you want to restart Nagios to start monitoring "
+ "newly discovered entities?", "Yes")
+ if confirmation:
+ server_utils.restartNagios()
+ print "Nagios re-started successfully"
+ else:
+ print " CONFIG ERROR! Check your Nagios configuration."
+ sys.exit(utils.PluginStatusCode.CRITICAL)
else:
print "Start the Nagios service to monitor"
# auto mode means write the configurations without asking confirmation
@@ -578,5 +592,9 @@ if __name__ == '__main__':
msg += formatTextForMail(getSummary(clusterDelta))
sendCustomNotification(args.cluster, msg)
if server_utils.isNagiosRunning():
- server_utils.restartNagios()
+ if _verifyNagiosConfig():
+ server_utils.restartNagios()
+ else:
+ print " CONFIG ERROR! Check your Nagios configuration."
+ sys.exit(utils.PluginStatusCode.CRITICAL)
sys.exit(utils.PluginStatusCode.OK)