#! /bin/bash cd "$(dirname "$0")" . opts.sh if [ -f "../security/$host.kubeconfig" ]; then gpod=$(get_gluster_pod) function gluster { oc -n glusterfs rsh po/$gpod gluster "$@" } # check if gluster pods are running if [ -n "$gpod" ]; then online=1 else oc -n glusterfs get pods -l 'glusterfs=storage-pod' | sed 's/^/* /' online=0 fi else echo "0 0 Not supported" exit fi function check { vol=$1 vol_bricks=$(gluster volume info "$vol" | grep -P 'Number of Bricks' | awk '{ print $NF }' | tr -d '\r\n') vol_online=$(gluster volume status "$vol" detail | grep Online | grep Y | wc -l) if [ -z "$vol_bricks" -o -z "$vol_online" -o "$vol_bricks" -ne "$vol_online" ]; then vol_status=$(gluster volume info "$vol" | grep -P 'Status' | awk '{ print $2 }' | tr -d '\r\n') vol_avail=$(gluster volume status "$vol" detail | grep Brick | wc -l) echo "* Volume $vol: $vol_status (Bricks: $vol_bricks, Available: $vol_avail, Online: $vol_online)" if [ "$vol_status" == "Started" -a "$vol_online" -ge 0 ]; then return 2 else return 0 fi else return 1 fi } version=$(gluster --version | head -n 1 | awk '{ print $2 }' | tr -d '\r') if [ -z "$version" ]; then online=0 else version="GlusterFS $version" fi volumes=0 partial=0 failed=0 healthy=$online if [ $online -eq 1 ]; then vols=$(gluster volume info | grep -P '^Volume Name' | awk '{ print $NF }' | tr '\r\n' ' ') for vol in $vols; do [[ "$vol" =~ [0-9] ]] && continue [[ "$vol" =~ ^vol_ ]] && continue [[ "$vol" =~ ^heketi ]] && continue check ${vol} ret=$? volumes=$((volumes + 1)) if [ $ret -eq 0 ]; then healthy=0 failed=$((failed + 1)) elif [ $ret -ne 1 ]; then [ $healthy -gt 0 ] && healthy=$ret partial=$((partial + 1)) fi done fi if [ $healthy -eq 1 ]; then msg="\${color gray}/ $volumes volumes" else msg="\${color gray}/ $volumes volumes, $failed failed, $partial bricks missing" fi echo "$online $healthy $version $msg"