summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--plugins/constants.py.in2
-rwxr-xr-xplugins/discovery.py34
-rwxr-xr-xplugins/server_utils.py2
4 files changed, 32 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index ef857f2..9bb4e73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,6 +57,8 @@ AC_SUBST([nagioslivestatussocketpath], ['/var/spool/nagios/cmd/live'])
AC_SUBST([nagioscommandfilepath], ['/var/spool/nagios/cmd/nagios.cmd'])
AC_SUBST([hostmonitoringserviceslist], ['/etc/nagios/gluster/host-monitoring-services.in'])
AC_SUBST([nrpepath], ['/usr/lib64/nagios/plugins/check_nrpe'])
+AC_SUBST([nagioscommandpath], ['/usr/sbin/nagios'])
+AC_SUBST([nagiosconfigfile], ['/etc/nagios/nagios.cfg'])
AC_SUBST([glusterautoconfdir], ['/etc/nagios/gluster'])
AC_SUBST([glusterhostconfigtemplatedir], ['/etc/nagios/gluster/default'])
AC_SUBST([snmpmanagerlist], ['/etc/nagios/gluster/snmpmanagers.conf'])
diff --git a/plugins/constants.py.in b/plugins/constants.py.in
index bf649de..e1fb442 100644
--- a/plugins/constants.py.in
+++ b/plugins/constants.py.in
@@ -4,3 +4,5 @@ HOST_TEMPLATE_DIR = "@glusterhostconfigtemplatedir@"
HOST_TEMPLATE_NAME = "gluster-host.cfg.template"
NRPE_PATH = "@nrpepath@"
NAGIOS_COMMAND_FILE_PATH = "@nagioscommandfilepath@"
+NAGIOS_CONFIG_FILE = "@nagiosconfigfile@"
+NAGIOS_PATH = "@nagioscommandpath@"
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)
diff --git a/plugins/server_utils.py b/plugins/server_utils.py
index e2271ba..ab5b4e8 100755
--- a/plugins/server_utils.py
+++ b/plugins/server_utils.py
@@ -24,10 +24,12 @@ from pynag import Model
from glusternagios import utils
import submit_external_command
from constants import NRPE_PATH
+from constants import NAGIOS_PATH
serviceCmdPath = utils.CommandPath("service", "/sbin/service", )
nrpeCmdPath = utils.CommandPath("check_nrpe", NRPE_PATH, )
+nagiosCmdPath = utils.CommandPath("nagios", NAGIOS_PATH, )
def restartNagios():