Edit file File name : check_a2_ipastatus.sh Content :#!/bin/bash # # Script to check cipa status on ipa replica servers # Critical if more than one replica is seen in a non 0 status in cipa output # Warning if one replica is seen in a non 0 status in cipa output # Ref BFENG-2058 # # Get the replica status part from cipa output cipa_replication_status=$(sudo -u admin /home/admin/.local/bin/cipa -H localhost --no-header --no-border 2>/dev/null|grep -A10 " Replication Status") # If the replica status part is missing from the output, it could mean replication is broken if [ -z "${cipa_replication_status}" ]; then echo "ipastatus - Replication info missing from cipa output" exit 2 fi # Get the first replica name mentioned in the cipa_replication_status first_replica_string=$(echo "${cipa_replication_status}"| head -1 | awk '{print $3}') # If the first replica string is "None", then alert critical if [ "${first_replica_string}" == "None" ]; then echo "ipastatus - Replication info missing from cipa outout" exit 2 fi # Find the total number of replica status's reported cipa_replica_count=$(echo "${cipa_replication_status}"|wc -l) # For replicas which are only linked to one other replica, # we still need them to be critical if the one replica has a non zero status if [ "${cipa_replica_count}" -gt 1 ]; then cipa_nonzero_threshold=1 elif [ "${cipa_replica_count}" -eq 1 ] ;then cipa_nonzero_threshold=0 fi # Get the name of replicas in a non zero state, one each line cipa_nonzero_status=$(echo "${cipa_replication_status}"|sed 's/ Replication Status//'|awk '$2!="0"'|awk '{print $1}') # Get the count of non zero replica status in cipa output cipa_nonzero_count=$(echo "${cipa_nonzero_status}"|wc -l) if [ -z "${cipa_nonzero_status}" ]; then echo "ipastatus - OK" exit 0 elif [ "${cipa_nonzero_count}" -gt "${cipa_nonzero_threshold}" ]; then # Format the non zero status replicas, separated by a comma character cipa_nonzero_replicas=$(echo "${cipa_nonzero_status}"|tr '\n' ','|sed 's/.$/\n/') echo "ipastatus - More than ${cipa_nonzero_threshold} hosts have a non-zero replication status : ${cipa_nonzero_replicas}" exit 2 else echo "ipastatus - ${cipa_nonzero_status} has a non-zero replication status" exit 1 fi Save