From 3ce8475c3e3ace39696d83e45c249f22554d4602 Mon Sep 17 00:00:00 2001 From: Sahina Bose Date: Mon, 9 Jun 2014 15:11:49 +0530 Subject: plugins: nrpe plugin to check volumes with server quorum Added a plugin to check if any volume in the cluster has the server side quorum turned on Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1106421 Change-Id: I897aedd737a622832548e7470e8f3cf9fb7dbc2c Signed-off-by: Sahina Bose Reviewed-on: http://review.gluster.org/8016 Reviewed-by: darshan n Reviewed-by: Ramesh N --- config/nrpe.in | 1 + gluster-nagios-addons.spec.in | 2 + plugins/Makefile.am | 1 + plugins/check_quorum_status.py | 54 ++++++++++++++++++++++++++ tests/Makefile.am | 1 + tests/test_check_quorum_status.py | 80 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 139 insertions(+) create mode 100755 plugins/check_quorum_status.py create mode 100644 tests/test_check_quorum_status.py diff --git a/config/nrpe.in b/config/nrpe.in index f2cf3b0..a1b68d3 100644 --- a/config/nrpe.in +++ b/config/nrpe.in @@ -3,6 +3,7 @@ Cmnd_Alias NRPE_PATHS = @sbindir@/send_nsca, \ @libdir@/nagios/plugins/gluster/check_vol_utilization.py, \ @libdir@/nagios/plugins/gluster/check_volume_status.py, \ @libdir@/nagios/plugins/gluster/check_gluster_proc_status.py, \ + @libdir@/nagios/plugins/gluster/check_quorum_status.py, \ @libdir@/nagios/plugins/gluster/discoverpeers.py, \ @libdir@/nagios/plugins/gluster/discover_volumes.py, \ @libdir@/nagios/plugins/gluster/discoverhostparams.py, \ diff --git a/gluster-nagios-addons.spec.in b/gluster-nagios-addons.spec.in index cc28003..27b13fa 100644 --- a/gluster-nagios-addons.spec.in +++ b/gluster-nagios-addons.spec.in @@ -147,6 +147,7 @@ command[discover_volume_list]=sudo %{_libdir}/nagios/plugins/gluster/discover_vo command[discover_volume_info]=sudo %{_libdir}/nagios/plugins/gluster/discover_volumes.py -v \$ARG1\$ command[discoverhostparams]=sudo %{_libdir}/nagios/plugins/gluster/discoverhostparams.py command[configure_gluster_node]=sudo %{_libdir}/nagios/plugins/gluster/configure_gluster_node.py -c \$ARG1\$ -n \$ARG2\$ -H \$ARG3\$ +command[check_quorum_status]=sudo %{_libdir}/nagios/plugins/gluster/check_quorum_status.py %{_end_conf_section} EOF @@ -155,6 +156,7 @@ EOF %_init_try_restart crond %_init_try_restart rsyslog %_init_try_restart glusterpmd +%_init_try_restart nrpe %preun if [ "$1" -eq 0 ]; then diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ffc121f..b5e522e 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -11,6 +11,7 @@ crond_DATA = \ dist_glusternagiosplugins_PYTHON = \ check_gluster_syslog.py \ check_mounts.py \ + check_quorum_status.py \ check_vol_utilization.py \ check_volume_status.py \ check_proc_status.py \ diff --git a/plugins/check_quorum_status.py b/plugins/check_quorum_status.py new file mode 100755 index 0000000..b3994c9 --- /dev/null +++ b/plugins/check_quorum_status.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# Copyright (C) 2014 Red Hat Inc +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +# +from glusternagios import utils +from glusternagios import glustercli + + +def getClusterQuorumStatus(): + exitstatus = 0 + message = "" + try: + volumes = glustercli.volumeInfo() + except glustercli.GlusterLockedException as e: + out = ("UNKNOWN: temporary error. %s" % '.'.join(e.err)) + return utils.PluginStatusCode.UNKNOWN, out + except glustercli.GlusterCmdFailedException as e: + out = ("Quorum status could not be determined. %s" + % '.'.join(e.err)) + return utils.PluginStatusCode.WARNING, out + + quorumVolumes = [] + for volumename, volume in volumes.iteritems(): + if (volume.get('options') and + volume.get('options').get('cluster.server-quorum-type') + == "server"): + quorumVolumes.append(volumename) + if not quorumVolumes: + exitstatus = utils.PluginStatusCode.UNKNOWN + message = "Server quorum not turned on for any volume" + else: + exitstatus = utils.PluginStatusCode.OK + message = ("Server quorum turned on for %s" + % (','.join(quorumVolumes))) + return exitstatus, message + + +if __name__ == '__main__': + exitstatus, message = getClusterQuorumStatus() + print message + exit(exitstatus) diff --git a/tests/Makefile.am b/tests/Makefile.am index 1994d43..22ec654 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,7 @@ test_modules = \ test_check_gluster_syslog.py \ test_check_volume_status.py \ + test_check_quorum_status.py \ check_proc_test_data.py \ test_cpu.py \ test_cpu_dataFile.py \ diff --git a/tests/test_check_quorum_status.py b/tests/test_check_quorum_status.py new file mode 100644 index 0000000..1cdc5ab --- /dev/null +++ b/tests/test_check_quorum_status.py @@ -0,0 +1,80 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +import mock + +from testrunner import PluginsTestCase as TestCaseBase +from plugins import check_quorum_status +from glusternagios import utils + + +class TestCheckQuorumStatus(TestCaseBase): + + # Method to test quorum status when quorum not set + @mock.patch('glusternagios.glustercli.volumeInfo') + def test_checkStatusNoQuorum(self, mock_volumeInfo): + mock_volumeInfo.return_value = _getVolumes('none') + exitStatusCode, exitStatusMsg = (check_quorum_status + .getClusterQuorumStatus()) + print exitStatusMsg + assert exitStatusMsg == "Server quorum not turned on for any volume" + assert exitStatusCode == utils.PluginStatusCode.UNKNOWN + mock_volumeInfo.return_value = _getEmptyVolume() + exitStatusCode, exitStatusMsg = (check_quorum_status + .getClusterQuorumStatus()) + assert exitStatusMsg == "Server quorum not turned on for any volume" + assert exitStatusCode == utils.PluginStatusCode.UNKNOWN + + # Method to test quorum status when options are turned on + @mock.patch('glusternagios.glustercli.volumeInfo') + def test_checkStatusWithQuorum(self, mock_volumeInfo): + mock_volumeInfo.return_value = _getVolumes('server') + exitStatusCode, exitStatusMsg = (check_quorum_status + .getClusterQuorumStatus()) + assert exitStatusCode == utils.PluginStatusCode.OK + assert exitStatusMsg == "Server quorum turned on " \ + "for test-vol,test-vol2" + + +def _getVolumes(quorumVal): + vol = {'test-vol': {'brickCount': 2, + 'bricks': ['server1:/path1', 'server2:/path2'], + 'options': {'cluster.quorum-type': 'none', + 'cluster.server-quorum-type': quorumVal, + 'changelog.changelog': 'on'}, + 'transportType': ['tcp'], + 'uuid': '0000-0000-0000-1111', + 'volumeName': 'test-vol', + 'volumeStatus': 'ONLINE', + 'volumeType': 'DISTRIBUTED'}, + 'test-vol2': {'brickCount': 2, + 'bricks': ['server1:/path1', 'server2:/path2'], + 'options': {'cluster.quorum-type': 'none', + 'cluster.server-quorum-type': quorumVal, + 'changelog.changelog': 'on'}, + 'transportType': ['tcp'], + 'uuid': '0000-0000-0000-1111', + 'volumeName': 'test-vol', + 'volumeStatus': 'ONLINE', + 'volumeType': 'DISTRIBUTED'}} + return vol + + +def _getEmptyVolume(): + return {} -- cgit