diff options
author | Shubhendu Tripathi <shtripat@redhat.com> | 2014-05-06 14:39:42 +0530 |
---|---|---|
committer | Sahina Bose <sabose@redhat.com> | 2014-05-20 00:20:50 -0700 |
commit | 0c6651331d3a8fc867a1799b18baed4c0789ba69 (patch) | |
tree | c09a84fd2f806b1a5da4e10ac2884f39cd3ba917 /plugins/check_vol_server.py | |
parent | 25a9105f9583cf165526db0c24c67bd12c4336fe (diff) |
nagios-server-addons: NRPE command with timeout
Introduced a utility method to return a NRPE base command
with timeout set externally.
Currently if a plugin internally executes NRPE to get the
details from the node, there is no mechanism that timeout
could be set to more than 10 sec. This method provides the
NRPE command with timeout (if passed).
This is required for some of the NRPE calls where gluster commands
get executed and they might take more time.
All the plugins, which execute a NRPE within, can provide
optional command line argument for timeout, and same can be used
for forming the proper NRPE call with timeout value.
Change-Id: Id97624df743664a320a585acc4a85cfcf64d0a07
Signed-off-by: Shubhendu Tripathi <shtripat@redhat.com>
Reviewed-on: http://review.gluster.org/7682
Reviewed-by: Sahina Bose <sabose@redhat.com>
Tested-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins/check_vol_server.py')
-rwxr-xr-x | plugins/check_vol_server.py | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/plugins/check_vol_server.py b/plugins/check_vol_server.py index 1c5863a..b512317 100755 --- a/plugins/check_vol_server.py +++ b/plugins/check_vol_server.py @@ -1,6 +1,5 @@ #!/usr/bin/python import sys -import commands import json import random import argparse @@ -8,7 +7,7 @@ import livestatus import os from glusternagios import utils -from constants import NRPE_PATH +import server_utils def _getListHosts(args): @@ -50,17 +49,8 @@ def _getVolGeoRepStatusNRPECommand(args): return ("check_vol_status -a %s %s" % (args.volume, 'geo-rep')) -def _getNRPEBaseCmd(host): - return NRPE_PATH + " -H " + host + " -c " - - -def execNRPECommand(command): - status, output = commands.getstatusoutput(command) - return os.WEXITSTATUS(status), output - - def _getVolumeStatusOutput(args): - status, output = _executeRandomHost(_getVolStatusNRPECommand(args)) + status, output = _executeRandomHost(_getVolStatusNRPECommand(args), args) if status == utils.PluginStatusCode.OK: #Following query will return the output in format [[2,0]] @@ -101,16 +91,23 @@ def _getVolumeQuotaStatusOutput(args): statusoutput.find("QUOTA: OK") > -1): # if ok, don't poll return servicestatus, statusoutput - return _executeRandomHost(_getVolQuotaStatusNRPECommand(args)) + return _executeRandomHost(_getVolQuotaStatusNRPECommand(args), args) -def _executeRandomHost(command): +def execNRPECommand(command): + status, output, err = utils.execCmd(command.split(), raw=True) + return os.WEXITSTATUS(status), output + + +def _executeRandomHost(command, args): list_hosts = _getListHosts(args) host = random.choice(list_hosts) #Get the address of the host host_address = _getHostAddress(host) - status, output = execNRPECommand(_getNRPEBaseCmd(host_address) + command) + status, output = execNRPECommand(server_utils.getNRPEBaseCommand( + host_address, + timeout=args.timeout) + command) if status != utils.PluginStatusCode.UNKNOWN: return status, output @@ -119,8 +116,9 @@ def _executeRandomHost(command): #in the host group and send the command until #the command is successful for host in list_hosts: - status, output = execNRPECommand(_getNRPEBaseCmd(_getHostAddress(host)) - + command) + status, output = execNRPECommand(server_utils.getNRPEBaseCommand( + host, + timeout=args.timeout) + command) if status != utils.PluginStatusCode.UNKNOWN: return status, output return status, output @@ -139,7 +137,7 @@ def showVolumeOutput(args): elif args.option == 'geo-rep': command = _getVolGeoRepStatusNRPECommand(args) - return _executeRandomHost(command) + return _executeRandomHost(command, args) def parse_input(): @@ -174,6 +172,9 @@ def parse_input(): 'quota', 'self-heal', 'geo-rep']) + parser.add_argument('-t', '--timeout', + action='store', + help='NRPE timeout') args = parser.parse_args() if args.critical <= args.warning: print "UNKNOWN:Critical must be greater than Warning." |