Skip to content
Snippets Groups Projects
Commit f6039b69 authored by Simon Michnowicz's avatar Simon Michnowicz
Browse files

First checkin of python testing script

parent d753b2c8
No related branches found
No related tags found
1 merge request!449Glustermonitor
# detect-gluster-problems.py
# Authors simon michnowicz 13 April 2021
COMMAND="sudo gluster volume heal gv info"
#COMMAND="sudo gluster volume heal gv info split-brain"
#also gluster volume heal gv info split-brain
#myOutput=`$COMMAND`
#myOutput=" a split brain that heals"
#echo "Output is $myOutput"
#
#
#sudo gluster volume heal gv info split-brain
#Brick 172.16.227.169:/gbrick/brick
#Status: Connected
#Number of entries in split-brain:
import os
import sys
import subprocess
def error(e):
'''
we have an error. Send an email
e=error string
'''
hostname = os.uname()[1]
#print("Error is:\n{}".format(e))
HEADER="Error Message from {}".format(hostname)
MAILTO="{{ EMAIL_DEST }}"
command="echo -e \"{}\" | mail -s \"{}\" \"{}\" ".format(e,HEADER,MAILTO)
#print("Command is:\n{}".format(command))
os.system(command)
def Test1():
'''
This tests looks for the word "split brain" in a general query
'''
COMMAND="sudo gluster volume heal gv info"
try:
result = subprocess.check_output(COMMAND.split()).decode('UTF-8')
#print("Test1 Output is {}".format(result))
outList=result.splitlines()
for line in outList:
#print("Test1 line is {}".format(line))
if 'split' in line:
error(COMMAND+"\n"+outlist)
except subprocess.CalledProcessError as error:
error("Test1: \nPlease contact mcc-help@monash.edu \n error code", error.returncode, error.output)
sys.exit(1)
def Test2():
'''
This test checks for number of split brain entries
sudo gluster volume heal gv info split-brain
Brick 172.16.227.169:/gbrick/brick
Status: Connected
Number of entries in split-brain: 0
'''
COMMAND="sudo gluster volume heal gv info split-brain"
try:
result = subprocess.check_output(COMMAND.split()).decode('UTF-8')
#print("Test2 Output is {}".format(result))
outList=result.splitlines()
for line in outList:
#print("Line is {}".format(line))
if 'Number of entries in split-brain' in line:
split=line.split(':')
if len(split)!=2:
error("Logic error in Test2: split is {}".format(split))
sys.exit(1)
NoOfSplitBrains=int(split[1])
#print("Number of Split Brains is {}".format(NoOfSplitBrains))
if (NoOfSplitBrains!=0):
error("Number of Split Brains is {}".format(NoOfSplitBrains))
except subprocess.CalledProcessError as error:
error("Test1: \nPlease contact mcc-help@monash.edu \n error code", error.returncode, error.output)
sys.exit(1)
def main():
#error("Simon test")
#sys.exit(0)
Test1()
Test2()
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment