diff options
author | Sahina Bose <sabose@redhat.com> | 2014-04-10 15:48:32 +0530 |
---|---|---|
committer | Bala.FA <barumuga@redhat.com> | 2014-04-29 10:14:33 +0530 |
commit | 86a404d7ce805a25762cd66c310b1ad9e3a2a779 (patch) | |
tree | d686e65934000e6f750360b1af6917863b3c3686 | |
parent | 96122accad447a7c11ce91678465600c262492a2 (diff) |
plugins: Enhanced volume status with quota status
Added an optional parameter to query quota status
Added command to nrpe.cfg
Change-Id: I9f60ed1a98cb2ca59b799cf9c09e3621b7bd8c0c
Signed-off-by: Sahina Bose <sabose@redhat.com>
-rw-r--r-- | gluster-nagios-addons.spec.in | 5 | ||||
-rw-r--r-- | plugins/Makefile.am | 1 | ||||
-rwxr-xr-x | plugins/check_volume_status.py | 33 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/test_check_volume_status.py | 35 |
5 files changed, 56 insertions, 19 deletions
diff --git a/gluster-nagios-addons.spec.in b/gluster-nagios-addons.spec.in index c802a5f..390d6e5 100644 --- a/gluster-nagios-addons.spec.in +++ b/gluster-nagios-addons.spec.in @@ -131,7 +131,8 @@ command[check_cpu_multicore]=%{_libdir}/nagios/plugins/gluster/cpu.py -w 80 -c 9 command[check_interfaces]=%{_libdir}/nagios/plugins/gluster/network.py -e lo -e ';vdsmdummy;' command[check_brick_usage]=/usr/lib64/nagios/plugins/gluster/check_disk_and_inode.py -w 80 -c 90 -u MB -n -i \$ARG1\$ command[check_vol_utilization]=sudo /usr/lib64/nagios/plugins/gluster/check_vol_utilization.py \$ARG1\$ -w \$ARG2\$ -c \$ARG3\$ -command[check_vol_status]=sudo /usr/lib64/nagios/plugins/gluster/check_volume_status.py -v \$ARG1\$ +command[check_vol_status]=sudo /usr/lib64/nagios/plugins/gluster/check_volume_status.py -v \$ARG1\$ -t info +command[check_vol_quota_status]=sudo /usr/lib64/nagios/plugins/gluster/check_volume_status.py -v \$ARG1\$ -t quota ###Auto Discovery related command[discoverpeers]=/usr/lib64/nagios/plugins/gluster/discoverpeers.py command[discoverlogicalcomponents]=/usr/lib64/nagios/plugins/gluster/discoverlogicalcomponents.py @@ -147,6 +148,8 @@ sed -i '/check_memory/d' %{_sysconfdir}/nagios/nrpe.cfg sed -i '/check_swap_usage/d' %{_sysconfdir}/nagios/nrpe.cfg sed -i '/sadf.py/d' %{_sysconfdir}/nagios/nrpe.cfg sed -i '/check_cpu_multicore.py/d' %{_sysconfdir}/nagios/nrpe.cfg +sed -i '/check_vol_status/d' %{_sysconfdir}/nagios/nrpe.cfg +sed -i '/check_vol_quota_status/d' %{_sysconfdir}/nagios/nrpe.cfg %files %defattr(-,root,root,-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index eb88ee1..c74cc3e 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -11,6 +11,7 @@ dist_glusternagiosplugins_PYTHON = \ check_disk_and_inode.py \ check_vol_utilization.py \ check_vol_status.py \ + check_volume_status.py \ cpu.py \ discoverpeers.py \ discoverlogicalcomponents.py \ diff --git a/plugins/check_volume_status.py b/plugins/check_volume_status.py index 383ec14..df68657 100755 --- a/plugins/check_volume_status.py +++ b/plugins/check_volume_status.py @@ -39,23 +39,46 @@ def getVolumeStatus(args): exitstatus = utils.PluginStatusCode.CRITICAL message = "CRITICAL: Volume is stopped" except glustercli.GlusterCmdFailedException as e: - out = "UNKNOWN: Command execution failed" - return utils.PluginStatusCode.UNKNOWN,out + out = ("UNKNOWN: Command execution failed %s" % e.message) + return utils.PluginStatusCode.UNKNOWN, out return exitstatus, message + +def getVolumeQuotaStatus(args): + try: + status = glustercli.volumeQuotaStatus(args.volume) + except glustercli.GlusterCmdFailedException as e: + out = ("QUOTA: Quota status could not be determined %s" % e.message) + return utils.PluginStatusCode.UNKNOWN, out + + if status == glustercli.VolumeQuotaStatus.EXCEEDED: + return utils.PluginStatusCode.WARNING, "QUOTA: limit exceeded" + elif status == glustercli.VolumeQuotaStatus.DISABLED: + return utils.PluginStatusCode.OK, "QUOTA: not enabled or configured" + else: + return utils.PluginStatusCode.OK, "QUOTA: OK" + + def parse_input(): parser = argparse.ArgumentParser() parser.add_argument("-v", "--volume", action="store", required=True, - help="Name of the volume for which" - " status is to be shown") + help="Name of the volume for status") + parser.add_argument("-t", "--type", action="store", + default="info", + dest="type", + help="Type of status to be shown. Possible values:", + choices=["info", "quota"]) args = parser.parse_args() return args if __name__ == '__main__': args = parse_input() - exitstatus, message = getVolumeStatus(args) + if args.type == "info": + exitstatus, message = getVolumeStatus(args) + if args.type == "quota": + exitstatus, message = getVolumeQuotaStatus(args) print message exit(exitstatus) diff --git a/tests/Makefile.am b/tests/Makefile.am index 5f82370..e8ab026 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,6 +19,7 @@ # test_modules = \ + test_check_volume_status.py \ test_cpu.py \ test_cpu_dataFile.py \ test_memory.py \ diff --git a/tests/test_check_volume_status.py b/tests/test_check_volume_status.py index a18cc1c..6b0be67 100644 --- a/tests/test_check_volume_status.py +++ b/tests/test_check_volume_status.py @@ -17,18 +17,20 @@ # # Refer to the README and COPYING files for full details of the license # -import argparse - import mock from testrunner import PluginsTestCase as TestCaseBase from plugins import check_volume_status from glusternagios import utils +from glusternagios import glustercli + class ArgParseMock(object): - def __init__(self, cluster, volume): - self.cluster = cluster - self.volume = volume + def __init__(self, cluster, volume, type="info"): + self.cluster = cluster + self.volume = volume + self.type = type + class TestCheckVolumeStatus(TestCaseBase): @@ -50,20 +52,27 @@ class TestCheckVolumeStatus(TestCaseBase): .getVolumeStatus(args)) assert exitStatusCode == utils.PluginStatusCode.CRITICAL + @mock.patch('glusternagios.glustercli.volumeQuotaStatus') + def test_checkVolumeQuotaStatus(self, mock_volumeQuotaStatus): + mock_volumeQuotaStatus.return_value = glustercli.\ + VolumeQuotaStatus.EXCEEDED + args = ArgParseMock('test-cluster', 'test-vol', 'quota') + exitStatusCode, exitStatusMsg = (check_volume_status + .getVolumeQuotaStatus(args)) + assert exitStatusCode == utils.PluginStatusCode.WARNING def _getVolume(): vol = {'test-vol': {'brickCount': 2, - 'bricks': ['server1:/path1', 'server2:/path2'], - 'options': {'option':'val'}, - 'transportType': ['tcp'], - 'uuid': '0000-0000-0000-1111', - 'volumeName': 'test-vol', - 'volumeStatus': 'ONLINE', - 'volumeType': 'DISTRIBUTED'}} + 'bricks': ['server1:/path1', 'server2:/path2'], + 'options': {'option': 'val'}, + 'transportType': ['tcp'], + 'uuid': '0000-0000-0000-1111', + 'volumeName': 'test-vol', + 'volumeStatus': 'ONLINE', + 'volumeType': 'DISTRIBUTED'}} return vol def _getEmptyVolume(): return {} - |