summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRamesh Nachimuthu <rnachimu@redhat.com>2014-05-05 10:05:29 +0530
committerSahina Bose <sabose@redhat.com>2014-05-04 23:53:01 -0700
commit33f927b5ff56f4b00635234de75b8ae57cb56214 (patch)
tree24d97b30546fb29b66885c3d5073482f8ee99efe /plugins
parent2d1f9f2f5e0e5c0816a4116d280254566d711699 (diff)
autoconf: handle exceptions in nrpe commands
Handling the exceptions and failure from NRPE commands. Change-Id: I36cba2d6adf8484ba134ad3f7aec77437ba07857 Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com> Reviewed-on: http://review.gluster.org/7659 Reviewed-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/discovery.py43
1 files changed, 25 insertions, 18 deletions
diff --git a/plugins/discovery.py b/plugins/discovery.py
index 69e1d86..2f1b9f6 100755
--- a/plugins/discovery.py
+++ b/plugins/discovery.py
@@ -39,22 +39,29 @@ from config_generator import CHANGE_MODE_UPDATE
nrpeCmdPath = utils.CommandPath("nrpe", NRPE_PATH, )
-def excecNRPECommand(host, command, arguments=None, jsonOutput=True):
+def execNRPECommand(host, command, arguments=None, jsonOutput=True):
nrpeCmd = [nrpeCmdPath.cmd, "-H", host, "-c", command]
if arguments:
nrpeCmd.append('-a')
nrpeCmd.extend(arguments)
- (returncode, outputStr, err) = utils.execCmd(nrpeCmd)
- #convert to dictionary
- if not jsonOutput:
- return outputStr[0]
+ (returncode, outputStr, err) = utils.execCmd(nrpeCmd, raw=True)
+ if returncode == 0:
+ if jsonOutput:
+ try:
+ #convert to dictionary
+ resultDict = json.loads(outputStr)
+ except Exception as e:
+ e.args += (outputStr,)
+ raise
+ return resultDict
+ else:
+ return outputStr
else:
- try:
- output = json.loads(outputStr[0])
- except Exception as e:
- e.args += (outputStr[0])
- raise
- return output
+ print "Failed to execute NRPE command '%s' in host '%s' " \
+ "\nError : %s" \
+ "Make sure NPRE server in host '%s' is configured to accept " \
+ "requests from Nagios server" % (command, host, outputStr, host)
+ sys.exit(utils.PluginStatusCode.CRITICAL)
#Discovers volumes info one by one.
@@ -63,10 +70,10 @@ def excecNRPECommand(host, command, arguments=None, jsonOutput=True):
#in NRPE.
def discoverVolumes(hostip):
resultDict = {'volumes': []}
- volumeList = excecNRPECommand(hostip, "discover_volume_list")
+ volumeList = execNRPECommand(hostip, "discover_volume_list")
for volumeName in volumeList.keys():
- volumeDetail = excecNRPECommand(hostip, "discover_volume_info",
- [volumeName])
+ volumeDetail = execNRPECommand(hostip, "discover_volume_info",
+ [volumeName])
resultDict['volumes'].append(volumeDetail.get(volumeName))
return resultDict
@@ -100,12 +107,12 @@ def discoverCluster(hostip, cluster):
#Discover the logical components
componentlist = discoverVolumes(hostip)
#Discover the peers
- hostlist = excecNRPECommand(hostip, "discoverpeers")
+ hostlist = execNRPECommand(hostip, "discoverpeers")
#Add the ip address of the root node given by the user to the peer list
hostlist[0]['hostip'] = hostip
for host in hostlist:
#Get host names
- hostDetails = excecNRPECommand(host['hostip'], "discoverhostparams")
+ hostDetails = execNRPECommand(host['hostip'], "discoverhostparams")
host.update(hostDetails)
#Get the list of bricks for this host and add to dictionary
host['bricks'] = []
@@ -342,7 +349,7 @@ def configureNodes(clusterDelta, nagiosServerAddress, mode):
#Only when a new node is added or whole cluster is added freshly.
if (clusterDelta.get('changeMode') == CHANGE_MODE_ADD or
host.get('changeMode') == CHANGE_MODE_ADD) \
- and (host['use'] != 'gluster_cluster'):
+ and (host['use'] == 'gluster-host'):
if not nagiosServerAddress:
#Nagios server address should be specified as arg in auto mode
if mode == "manual":
@@ -356,7 +363,7 @@ def configureNodes(clusterDelta, nagiosServerAddress, mode):
#Configure the nodes. clusterName, Nagios server address and
#host_name is passed as an argument to nrpe command
#'configure_gluster_node'
- excecNRPECommand(
+ execNRPECommand(
host['address'], 'configure_gluster_node',
[clusterDelta['hostgroup_name'], nagiosServerAddress,
host['host_name']], False)