summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorndarshan <dnarayan@redhat.com>2014-04-10 11:15:53 +0530
committerBala.FA <barumuga@redhat.com>2014-04-29 10:21:37 +0530
commit10c414706c2c77225c014673f03b8e3166b82ff2 (patch)
tree644efffb0f4e1bb9e5eb8930c7ab515098409205
parent3374e943a17516e1e28339dc3df55c80b0ecf5ad (diff)
Server-addons: Server-side plugin for volume status.
Modified the existing volume utilization server plugin to include status information as well. Refactored the plugin with an argument -o|--option to get the specific volume status. Change-Id: I2b6f8612e32390fb20917098a255de1ee6b3a170 Signed-off-by: ndarshan <dnarayan@redhat.com> Signed-off-by: Sahina Bose <sabose@redhat.com>
-rw-r--r--config/gluster-commands.cfg6
-rw-r--r--config/glustercluster.cfg.sample16
-rw-r--r--plugins/Makefile.am2
-rwxr-xr-xplugins/check_vol_server.py127
-rwxr-xr-xplugins/check_vol_utilization_server.py83
-rw-r--r--plugins/config_generator.py4
6 files changed, 151 insertions, 87 deletions
diff --git a/config/gluster-commands.cfg b/config/gluster-commands.cfg
index 377887c..ec72417 100644
--- a/config/gluster-commands.cfg
+++ b/config/gluster-commands.cfg
@@ -52,7 +52,7 @@ define command {
define command {
command_name check_vol_utilization
- command_line $USER1$/gluster/check_vol_utilization_server.py $ARG1$ $ARG2$ -w $ARG3$ -c $ARG4$
+ command_line $USER1$/gluster/check_vol_server.py $ARG1$ $ARG2$ -w $ARG3$ -c $ARG4$ -o utilization
}
@@ -71,3 +71,7 @@ define command{
command_line $USER1$/check_dummy 0
}
+define command {
+ command_name check_vol_status
+ command_line $USER1$/gluster/check_vol_server.py $ARG1$ $ARG2$ -o status
+}
diff --git a/config/glustercluster.cfg.sample b/config/glustercluster.cfg.sample
index 81124d7..3afb95a 100644
--- a/config/glustercluster.cfg.sample
+++ b/config/glustercluster.cfg.sample
@@ -92,6 +92,22 @@ define service{
}
################################################################################
+# This defines a Volume status service
+# Edit this sample
+# host_name = the cluster host previously defined for cluster
+# service_description = Volume-status - <volname>
+# check_command = check_vol_status!<cluster-hostgroup-name>!<volume-name>
+# _VOL_NAME = Volume name
+################################################################################
+define service{
+ use gluster-service-without-graph
+ host_name test-cluster
+ service_description Volume Status - data-vol
+ _VOL_NAME data-vol ; MUST DECLARE the custom var _VOL_NAME
+ check_command check_vol_status!test-cluster!data-vol
+}
+
+################################################################################
# This defines a Cluster utilization service
# Edit this sample
# host_name = cluster host previously defined. (The service is under a cluster)
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 5606fb3..78d0d8a 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -2,7 +2,7 @@ dist_glusternagiosplugins_PYTHON = \
constants.py \
check_cluster_vol_usage.py \
check_remote_host.py \
- check_vol_utilization_server.py \
+ check_vol_server.py \
gluster_host_service_handler.py \
livestatus.py \
notify_ovirt_engine_handler.py \
diff --git a/plugins/check_vol_server.py b/plugins/check_vol_server.py
new file mode 100755
index 0000000..87ca269
--- /dev/null
+++ b/plugins/check_vol_server.py
@@ -0,0 +1,127 @@
+#!/usr/bin/python
+import sys
+import commands
+import random
+import argparse
+import livestatus
+import os
+from glusternagios import utils
+
+_NRPEPath = "/usr/lib64/nagios/plugins/check_nrpe"
+
+
+def _getListHosts(args):
+ table = livestatus.readLiveStatus("GET hostgroups\nColumns: members\n"
+ "Filter: name = "
+ + args.hostgroup + "\n")
+ tab1 = table[0]
+ list_hosts = tab1[0].split(",")
+ #First take a random host from the group and send the request
+ return list_hosts
+
+
+def _getHostAddress(host):
+ # Get the address of the host
+ host_address = livestatus.checkLiveStatus("GET hosts\nColumns: address\n"
+ "Filter: display_name = "
+ + host + "\n")
+ return host_address.rstrip()
+
+
+def _getVolUtilizationNRPECommand(args):
+ return ("check_vol_utilization -a " + args.volume + " " +
+ str(args.warning) + " " + str(args.critical))
+
+
+def _getVolStatusNRPECommand(args):
+ return ("check_vol_status -a " + args.volume)
+
+
+def _getNRPEBaseCmd(host):
+ return _NRPEPath + " -H " + host + " -c ";
+
+
+def execNRPECommand(command):
+ status, output = commands.getstatusoutput(command)
+ return os.WEXITSTATUS(status), output
+
+
+def showVolumeOutput(args):
+ list_hosts = _getListHosts(args)
+ host = random.choice(list_hosts)
+ #Get the address of the host
+ host_address = _getHostAddress(host)
+
+ if args.option == 'status':
+ command = _getVolStatusNRPECommand(args)
+ elif args.option == 'utilization':
+ command = _getVolUtilizationNRPECommand(args)
+
+ status, output = execNRPECommand(_getNRPEBaseCmd(host_address) + command)
+
+ if status != utils.PluginStatusCode.UNKNOWN:
+ return status, output
+ for host in list_hosts:
+ status, output = execNRPECommand(_getNRPEBaseCmd(_getHostAddress(host))
+ + command)
+ if status != utils.PluginStatusCode.UNKNOWN:
+ return status, output
+ break
+ return status, output
+
+ #if success return from here
+ if "Volume Utilization" in output:
+ return status, output
+ #radom host is not able to execute the command
+ #Now try to iterate through the list of hosts
+ #in the host group and send the command until
+ #the command is successful
+ for host in list_hosts:
+ status, output = execNRPECommand(host, args)
+ #if success return from here
+ if "Volume Utilization" in output:
+ return status, output
+ break
+ return status, output
+
+
+def parse_input():
+ parser = argparse.ArgumentParser(
+ usage='%(prog)s [-h] <hostgroup> <volume> -w <Warning>'
+ ' -c <Critical> [-o|--option]')
+ parser.add_argument(
+ "hostgroup",
+ help="Name of the hostgroup to which the volume belongs")
+ parser.add_argument(
+ "volume",
+ help="Name of the volume being queried")
+ parser.add_argument(
+ "-w",
+ "--warning",
+ action="store",
+ type=int,
+ default=70,
+ help="Warning Threshold in percentage")
+ parser.add_argument(
+ "-c",
+ "--critical",
+ action="store",
+ type=int,
+ default=90,
+ help="Critical Threshold in percentage")
+ parser.add_argument('-o', '--option',
+ action='store',
+ help='the volume option to check',
+ choices=['utilization',
+ 'status'])
+ args = parser.parse_args()
+ if args.critical <= args.warning:
+ print "UNKNOWN:Critical must be greater than Warning."
+ sys.exit(utils.PluginStatusCode.UNKNOWN)
+ return args
+
+if __name__ == '__main__':
+ args = parse_input()
+ status, output = showVolumeOutput(args)
+ print output
+ exit(status)
diff --git a/plugins/check_vol_utilization_server.py b/plugins/check_vol_utilization_server.py
deleted file mode 100755
index cdc36ff..0000000
--- a/plugins/check_vol_utilization_server.py
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/usr/bin/python
-import sys
-import commands
-import random
-import argparse
-import livestatus
-import os
-
-_NRPEPath = "/usr/lib64/nagios/plugins/check_nrpe"
-
-
-def excecNRPECommand(host):
- #Get the address of the host
- answer = livestatus.checkLiveStatus("GET hosts\nColumns: address\n"
- "Filter: display_name = "
- + host + "\n")
- command = (_NRPEPath + " -H " + answer.rstrip() + " -c " +
- "check_vol_utilization -a " + args.volume + " " +
- str(args.warning) + " " + str(args.critical))
- status, output = commands.getstatusoutput(command)
- return status, output
-
-
-def showVolumeUtilization(args):
- table = livestatus.readLiveStatus("GET hostgroups\nColumns: members\n"
- "Filter: name = "
- + args.hostgroup + "\n")
- tab1 = table[0]
- list_hosts = tab1[0].split(",")
- #First take a random host from the group and send the request
- host = random.choice(list_hosts)
- status, output = excecNRPECommand(host)
- #if success return from here
- if "Volume Utilization" in output:
- return status, output
- #radom host is not able to execute the command
- #Now try to iterate through the list of hosts
- #in the host group and send the command until
- #the command is successful
- for host in list_hosts:
- status, output = excecNRPECommand(host)
- #if success return from here
- if "Volume Utilization" in output:
- return status, output
- break
- return status, output
-
-
-def parse_input():
- parser = argparse.ArgumentParser(
- usage='%(prog)s [-h] <hostgroup> <volume> -w <Warning> -c <Critical>')
- parser.add_argument(
- "hostgroup",
- help="Name of the hostgroup in which the volume belongs to")
- parser.add_argument(
- "volume",
- help="Name of the volume to get the Utilization")
- parser.add_argument(
- "-w",
- "--warning",
- action="store",
- type=int,
- help="Warning Threshold in percentage")
- parser.add_argument(
- "-c",
- "--critical",
- action="store",
- type=int,
- help="Critical Threshold in percentage")
- args = parser.parse_args()
- if not args.critical or not args.warning:
- print "UNKNOWN:Missing critical/warning threshold value."
- sys.exit(3)
- if args.critical <= args.warning:
- print "UNKNOWN:Critical must be greater than Warning."
- sys.exit(3)
- return args
-
-if __name__ == '__main__':
- args = parse_input()
- status, output = showVolumeUtilization(args)
- print output
- exit(os.WEXITSTATUS(status))
diff --git a/plugins/config_generator.py b/plugins/config_generator.py
index a6757df..9941028 100644
--- a/plugins/config_generator.py
+++ b/plugins/config_generator.py
@@ -73,11 +73,11 @@ class GlusterNagiosConfManager:
def __createVolumeStatusService(self, volume, clusterName):
volumeService = {}
volumeService['host_name'] = clusterName
- volumeService['use'] = 'gluster-service-with-graph'
+ volumeService['use'] = 'gluster-service-withoout-graph'
serviceDesc = 'Volume Status - %s' % (volume['name'])
volumeService['service_description'] = serviceDesc
volumeService['_VOL_NAME'] = volume['name']
- checkCommand = 'check_vol_utilization!%s!%s!70!90' % \
+ checkCommand = 'check_vol_status!%s!%s' % \
(clusterName, volume['name'])
volumeService['check_command'] = checkCommand
volumeService['notes'] = "Volume type : %s" % (volume['typeStr'])