From d0327fab7fbaf2c6f30e807fb8c90dfe5fa9db5c Mon Sep 17 00:00:00 2001 From: Ramesh Nachimuthu Date: Thu, 1 May 2014 12:37:54 +0530 Subject: autoconf: discover volume list and info separately NRPE doesn't support transfering large junk of data as a result. Hence we have to discover the volume details one by one. Added two NRPE commands 'discover_volume_list' and 'discover_volume_info'. 'discover_volume_list' returns the list of volume names with volume type. 'discover_volume_info' returns the bricks details of a given volume. Change-Id: I753be5e407fe14988f23ca77007b3a585537b360 Signed-off-by: Ramesh Nachimuthu Reviewed-on: http://review.gluster.org/7630 Reviewed-by: Kanagaraj M Reviewed-by: Sahina Bose --- plugins/discover_volumes.py | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 plugins/discover_volumes.py (limited to 'plugins/discover_volumes.py') diff --git a/plugins/discover_volumes.py b/plugins/discover_volumes.py new file mode 100755 index 0000000..f917d40 --- /dev/null +++ b/plugins/discover_volumes.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# discover_volumes.py -- nagios plugin for discovering +#logical gluster components +# 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 +# +import json +import sys +import argparse + +from glusternagios import utils +from glusternagios import glustercli + + +def discoverVolumes(volumeName, list): + """ + This method helps to discover volumes list and volume info + Parameters + ---------- + list: Flag used for getting volume info. If the flag is 'True' then the + method will return only list of volume names with volume Type and doesn't + include the brick details. . If list is 'False' then returns the volume + details with brick information. + + volumeName: Fetch information only for the given volume. + Note: glustercli.volumeInfo(volName) command accept a volumeName. But if + the volume name is not passed then it returns details about all the volumes + in the cluster. + Returns + --------- + Returns volume details in the following dictionary format + { + 'vol-name' : {vol-details} + 'vol-name' : {vol-details} + 'vol-name' : {vol-details} + ... + } + """ + resultlist = {} + volumes = glustercli.volumeInfo(volumeName) + for key, volume in volumes.iteritems(): + volDict = {} + volDict['name'] = key + volDict['type'] = volume['volumeType'] + if not list: + volDict['bricks'] = [] + for brick in volume['bricksInfo']: + brickproplist = brick['name'].split(':') + volDict['bricks'].append({'brickpath': brickproplist[1], + 'hostUuid': brick['hostUuid']}) + resultlist[key] = volDict + resultString = json.dumps(resultlist) + return resultString + + +def get_arg_parser(): + parser = argparse.ArgumentParser(description="Discovery tool for " + "Gluster volumes") + parser.add_argument('-l', '--list', action='store_true', dest='list', + help="Fetch only list of volumes names") + parser.add_argument('-v', '--volume', action='store', dest='volume', + type=str, help='Volume name') + return parser + + +if __name__ == '__main__': + args = get_arg_parser().parse_args() + resultString = discoverVolumes(args.volume, args.list) + print resultString + sys.exit(utils.PluginStatusCode.OK) -- cgit