diff options
author | Ramesh Nachimuthu <rnachimu@redhat.com> | 2014-04-16 10:09:31 +0530 |
---|---|---|
committer | Bala.FA <barumuga@redhat.com> | 2014-04-29 10:14:33 +0530 |
commit | 666983202013dd3c1e236eb458b75b3a95d74782 (patch) | |
tree | 44d96fa3016fed48edfba3aa23de8c97a9f0e8ea | |
parent | e5c38e4d2411d453a769fd5acda2bee97d9237d9 (diff) |
autoconf: use glustercli to run volume info command
Using the glustercli.volumeInfo() from common to get the volume
info. It makes the discovery logic very simple
Change-Id: Iacf319eb3b3b39805a483cbe43b02496802316a7
Signed-off-by: Ramesh Nachimuthu <rnachimu@redhat.com>
-rw-r--r-- | gluster-nagios-addons.spec.in | 4 | ||||
-rwxr-xr-x | plugins/discoverlogicalcomponents.py | 52 |
2 files changed, 17 insertions, 39 deletions
diff --git a/gluster-nagios-addons.spec.in b/gluster-nagios-addons.spec.in index 190d2e7..8278bb4 100644 --- a/gluster-nagios-addons.spec.in +++ b/gluster-nagios-addons.spec.in @@ -135,8 +135,8 @@ command[check_vol_utilization]=sudo /usr/lib64/nagios/plugins/gluster/check_vol_ 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 +command[discoverpeers]=%{_libdir}/nagios/plugins/gluster/discoverpeers.py +command[discoverlogicalcomponents]=sudo %{_libdir}/nagios/plugins/gluster/discoverlogicalcomponents.py EOF %_init_enable nrpe %_init_restart crond diff --git a/plugins/discoverlogicalcomponents.py b/plugins/discoverlogicalcomponents.py index 50a259f..9211f42 100755 --- a/plugins/discoverlogicalcomponents.py +++ b/plugins/discoverlogicalcomponents.py @@ -17,51 +17,29 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # -import commands import json import sys from glusternagios import utils - - -def discoverbricks(vol_info_out): - bricklist = [] - xmlElemList = utils.parseXml(vol_info_out, - "./volInfo/volumes/volume/bricks/brick") - for brick in xmlElemList: - brickdict = {} - brickstr = brick.text - brickproplist = brickstr.split(':') - brickdict['hostip'] = brickproplist[0] - brickdict['brickpath'] = brickproplist[1] - bricklist.append(brickdict) - - return bricklist - - -def discovervolumes(vol_info_out): - vollist = [] - - #Get the volume info - xmlElemList = utils.parseXml(vol_info_out, "./volInfo/volumes/volume") - for volume in xmlElemList: - voldict = {} - voldict['name'] = volume.find('name').text - voldict['typeStr'] = volume.find('typeStr').text - vollist.append(voldict) - - return vollist +from glusternagios import glustercli def discoverlogicalelements(): resultlist = {} - resultstring = "" - command_vol_info = utils.sudoCmdPath.cmd + " " + \ - utils.glusterCmdPath.cmd + " volume info --xml" - vol_info_out = commands.getoutput(command_vol_info) - resultlist['volumes'] = discovervolumes(vol_info_out) - resultlist['bricks'] = discoverbricks(vol_info_out) - #convert to string + resultlist['volumes'] = [] + + volumes = glustercli.volumeInfo() + for volume in volumes.values(): + volDict = {} + volDict['name'] = volume['volumeName'] + volDict['type'] = volume['volumeType'] + volDict['bricks'] = [] + for brickstr in volume['bricks']: + brickproplist = brickstr.split(':') + volDict['bricks'].append({'hostip': brickproplist[0], + 'brickpath': brickproplist[1]}) + resultlist['volumes'].append(volDict) + resultstring = json.dumps(resultlist) print resultstring sys.exit(utils.PluginStatusCode.OK) |